Add ability to request merged_yaml from the Gitlab Lint API (#2185)

This commit is contained in:
Martin Howarth 2021-11-05 23:23:22 +00:00 committed by GitHub
parent 193348484f
commit bfc5cbd643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -1,14 +1,15 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, Sudo } from '../infrastructure';
import { BaseRequestOptions, RequestHelper } from '../infrastructure';
export interface LintSchema extends Record<string, unknown> {
status: string;
errors?: string[];
warnings?: string[];
merged_yaml?: string;
}
export class Lint<C extends boolean = false> extends BaseResource<C> {
lint(content: string, options?: Sudo) {
lint(content: string, options?: BaseRequestOptions) {
return RequestHelper.post<LintSchema>()(this, 'ci/lint', { content, ...options });
}
}

View File

@ -0,0 +1,41 @@
import 'jest-extended';
import { Lint } from '../../../src';
let lintAPI: InstanceType<typeof Lint>;
beforeEach(() => {
lintAPI = new Lint({
host: process.env.GITLAB_URL,
token: process.env.GITLAB_PERSONAL_ACCESS_TOKEN,
});
});
describe('Lint.lint', () => {
it('should return validate a lint without returning the merged_yaml', async () => {
// Call the lint API, passing in a basic CI yaml, asking for the merged_yaml back.
const input_ci_yaml = `
test:
stage: test
script:
- echo 1
`;
const result = await lintAPI.lint(input_ci_yaml);
expect(result).toBeInstanceOf(Object);
expect(result).toContainKeys(['status']);
});
it('should return the merged yaml in a lint request when requested', async () => {
// Call the lint API, passing in a basic CI yaml, asking for the merged_yaml back.
const input_ci_yaml = `
test:
stage: test
script:
- echo 1
`;
const result = await lintAPI.lint(input_ci_yaml, { includeMergedYaml: true });
expect(result).toBeInstanceOf(Object);
expect(result).toContainKeys(['status', 'merged_yaml']);
});
});