From bfc5cbd6431cee166e564abd0a0c6cf773208145 Mon Sep 17 00:00:00 2001 From: Martin Howarth Date: Fri, 5 Nov 2021 23:23:22 +0000 Subject: [PATCH] Add ability to request merged_yaml from the Gitlab Lint API (#2185) --- packages/core/src/resources/Lint.ts | 5 ++- .../node/test/integration/resources/Lint.ts | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 packages/node/test/integration/resources/Lint.ts diff --git a/packages/core/src/resources/Lint.ts b/packages/core/src/resources/Lint.ts index 34976521..562bfa6b 100644 --- a/packages/core/src/resources/Lint.ts +++ b/packages/core/src/resources/Lint.ts @@ -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 { status: string; errors?: string[]; warnings?: string[]; + merged_yaml?: string; } export class Lint extends BaseResource { - lint(content: string, options?: Sudo) { + lint(content: string, options?: BaseRequestOptions) { return RequestHelper.post()(this, 'ci/lint', { content, ...options }); } } diff --git a/packages/node/test/integration/resources/Lint.ts b/packages/node/test/integration/resources/Lint.ts new file mode 100644 index 00000000..11651ba7 --- /dev/null +++ b/packages/node/test/integration/resources/Lint.ts @@ -0,0 +1,41 @@ +import 'jest-extended'; +import { Lint } from '../../../src'; + +let lintAPI: InstanceType; + +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']); + }); +});