From 928d3bb05da1be25159c58cb4f8b13c44a258ba1 Mon Sep 17 00:00:00 2001 From: Eli Polonsky Date: Sun, 12 Jan 2025 22:17:27 +0200 Subject: [PATCH] revert(prlint): fail prlinter on codecov failures, with exemption label (#32867) Reverts aws/aws-cdk#32674 --- tools/@aws-cdk/prlint/lint.ts | 51 +++---------------------- tools/@aws-cdk/prlint/test/lint.test.ts | 11 ++---- 2 files changed, 9 insertions(+), 53 deletions(-) diff --git a/tools/@aws-cdk/prlint/lint.ts b/tools/@aws-cdk/prlint/lint.ts index b2bbee0399ea5..48c5a23819459 100644 --- a/tools/@aws-cdk/prlint/lint.ts +++ b/tools/@aws-cdk/prlint/lint.ts @@ -10,16 +10,7 @@ export type GitHubPr = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response']['data']; export const CODE_BUILD_CONTEXT = 'AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)'; -export const CODECOV_PREFIX = 'codecov/'; - -export const CODECOV_CHECKS = [ - 'patch', - 'patch/packages/aws-cdk', - 'patch/packages/aws-cdk-lib/core', - 'project', - 'project/packages/aws-cdk', - 'project/packages/aws-cdk-lib/core' -]; + const PR_FROM_MAIN_ERROR = 'Pull requests from `main` branch of a fork cannot be accepted. Please reopen this contribution from another branch on your fork. For more information, see https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md#step-4-pull-request.'; /** @@ -33,7 +24,6 @@ enum Exemption { CLI_INTEG_TESTED = 'pr-linter/cli-integ-tested', REQUEST_CLARIFICATION = 'pr/reviewer-clarification-requested', REQUEST_EXEMPTION = 'pr-linter/exemption-requested', - CODECOV = "pr-linter/exempt-codecov", } export interface GithubStatusEvent { @@ -346,23 +336,14 @@ export class PullRequestLinter { * @param sha the commit sha to evaluate */ private async codeBuildJobSucceeded(sha: string): Promise { - return this.checkStatusSucceeded(sha, CODE_BUILD_CONTEXT); - } - - /** - * Check a specific status check to see if it is successful for the given commit - * - * @param sha the commit sha to evaluate - */ - private async checkStatusSucceeded(sha: string, context: string): Promise { - const statuses = await this.client.paginate(this.client.repos.listCommitStatusesForRef, { + const statuses = await this.client.repos.listCommitStatusesForRef({ owner: this.prParams.owner, repo: this.prParams.repo, ref: sha, }); - let status = statuses.filter(status => status.context === context).map(status => status.state); - console.log(`${context} statuses: ${status}`); - return statuses.some(status => status.context === context && status.state === 'success'); + let status = statuses.data.filter(status => status.context === CODE_BUILD_CONTEXT).map(status => status.state); + console.log("CodeBuild Commit Statuses: ", status); + return statuses.data.some(status => status.context === CODE_BUILD_CONTEXT && status.state === 'success'); } public async validateStatusEvent(pr: GitHubPr, status: StatusEvent): Promise { @@ -594,24 +575,6 @@ export class PullRequestLinter { ], }); - const codecovTests: Test[] = []; - for (const c of CODECOV_CHECKS) { - const checkName = `${CODECOV_PREFIX}${c}`; - const succeeded = await this.checkStatusSucceeded(sha, checkName); - codecovTests.push({ - test: () => { - const result = new TestResult(); - result.assessFailure(!succeeded, `${checkName} job is not succeeding`); - return result; - } - }) - } - - validationCollector.validateRuleSet({ - exemption: shouldExemptCodecov, - testRuleSet: codecovTests, - }); - console.log("Deleting PR Linter Comment now"); await this.deletePRLinterComment(); try { @@ -693,10 +656,6 @@ function fixContainsIntegTest(pr: GitHubPr, files: GitHubFile[]): TestResult { return result; } -function shouldExemptCodecov(pr: GitHubPr): boolean { - return hasLabel(pr, Exemption.CODECOV); -} - function shouldExemptReadme(pr: GitHubPr): boolean { return hasLabel(pr, Exemption.README); } diff --git a/tools/@aws-cdk/prlint/test/lint.test.ts b/tools/@aws-cdk/prlint/test/lint.test.ts index c1aa7d6dc85b7..1de1f3c334ee0 100644 --- a/tools/@aws-cdk/prlint/test/lint.test.ts +++ b/tools/@aws-cdk/prlint/test/lint.test.ts @@ -1182,13 +1182,10 @@ function configureMock(pr: Subset, prFiles?: linter.GitHubFile[ const reposClient = { listCommitStatusesForRef() { return { - data: [ - { - context: linter.CODE_BUILD_CONTEXT, - state: 'success', - }, - ...(linter.CODECOV_CHECKS.map(c => ({ context: `${linter.CODECOV_PREFIX}${c}`, state: 'success'}))) - ], + data: [{ + context: linter.CODE_BUILD_CONTEXT, + state: 'success', + }], }; }, };