From c5da0d3aedcb7e8a5cd361ed021f2a3684961b50 Mon Sep 17 00:00:00 2001 From: epolon Date: Wed, 15 Jan 2025 10:37:51 +0200 Subject: [PATCH] mid work --- tools/@aws-cdk/prlint/lint.ts | 47 +++++++++++++------------ tools/@aws-cdk/prlint/test/lint.test.ts | 8 ++--- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/tools/@aws-cdk/prlint/lint.ts b/tools/@aws-cdk/prlint/lint.ts index 39cd4db00919c..547184e722fb2 100644 --- a/tools/@aws-cdk/prlint/lint.ts +++ b/tools/@aws-cdk/prlint/lint.ts @@ -373,11 +373,10 @@ export class PullRequestLinter { ref: sha, }); - // grab the last check run that was started - const conclusion = response.check_runs - .filter(c => c.name === checkName) - .filter(c => c.started_at != null) - .sort((c1, c2) => c2.started_at!.localeCompare(c1.started_at!)) + // grab the last check run that was completed + const conclusion = response + .filter(c => c.name === checkName && c.completed_at != null) + .sort((c1, c2) => c2.completed_at!.localeCompare(c1.completed_at!)) .map(s => s.conclusion)[0]; console.log(`${checkName} conclusion: ${conclusion}`) @@ -555,6 +554,7 @@ export class PullRequestLinter { console.log(`⌛ Fetching PR number ${number}`); const pr = (await this.client.pulls.get(this.prParams)).data as GitHubPr; + console.log(`PR base ref is: ${pr.base.ref}`) console.log(`⌛ Fetching files for PR number ${number}`); const files = await this.client.paginate(this.client.pulls.listFiles, this.prParams); @@ -607,25 +607,28 @@ export class PullRequestLinter { ], }); - const codecovTests: Test[] = []; - for (const c of CODECOV_CHECKS) { - const checkName = `${CODECOV_PREFIX}${c}`; - const status = await this.checkRunConclusion(sha, checkName); - codecovTests.push({ - test: () => { - const result = new TestResult(); - const message = status == null ? `${checkName} has not started yet` : `${checkName} job is in status: ${status}`; - result.assessFailure(status !== 'success', message); - return result; - } - }) + if (pr.base.ref === 'main') { + // we don't enforce codecov on release branches + const codecovTests: Test[] = []; + for (const c of CODECOV_CHECKS) { + const checkName = `${CODECOV_PREFIX}${c}`; + const conclusion = await this.checkRunConclusion(sha, checkName); + codecovTests.push({ + test: () => { + const result = new TestResult(); + const message = conclusion == null ? `${checkName} has not reported a status yet` : `${checkName} job is in status: ${conclusion}`; + result.assessFailure(conclusion !== 'success', message); + return result; + } + }) + } + + validationCollector.validateRuleSet({ + exemption: shouldExemptCodecov, + testRuleSet: codecovTests, + }); } - validationCollector.validateRuleSet({ - exemption: shouldExemptCodecov, - testRuleSet: codecovTests, - }); - console.log("Deleting PR Linter Comment now"); await this.deletePRLinterComment(); try { diff --git a/tools/@aws-cdk/prlint/test/lint.test.ts b/tools/@aws-cdk/prlint/test/lint.test.ts index fe64c74d026f6..d287f27186c74 100644 --- a/tools/@aws-cdk/prlint/test/lint.test.ts +++ b/tools/@aws-cdk/prlint/test/lint.test.ts @@ -1142,7 +1142,7 @@ describe('integration tests required on features', () => { function configureMock(pr: Subset, prFiles?: linter.GitHubFile[], existingComments?: string[]): linter.PullRequestLinter { const pullsClient = { get(_props: { _owner: string, _repo: string, _pull_number: number, _user: { _login: string} }) { - return { data: pr }; + return { data: { ...pr, base: { ref: 'main'}} }; }, listFiles(_props: { _owner: string, _repo: string, _pull_number: number }) { @@ -1193,11 +1193,11 @@ function configureMock(pr: Subset, prFiles?: linter.GitHubFile[ const checksClient = { listForRef() { return { - data: { check_runs: linter.CODECOV_CHECKS.map(c => ({ + data: linter.CODECOV_CHECKS.map(c => ({ name: `${linter.CODECOV_PREFIX}${c}`, conclusion: 'success', - started_at: '1' - }))}, + completed_at: '1' + })), } } }