Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Jan 13, 2025
1 parent b5278c1 commit d8d8427
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import { Octokit } from '@octokit/rest';
import { Endpoints } from '@octokit/types';
import { StatusEvent } from '@octokit/webhooks-definitions/schema';
import type { components } from '@octokit/openapi-types';
import { findModulePath, moduleStability } from './module';
import { breakingModules } from './parser';

Expand All @@ -21,6 +22,8 @@ export const CODECOV_CHECKS = [
'project/packages/aws-cdk-lib/core'
];

type CheckRunConclusion = components['schemas']['check-run']['conclusion']

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.';

/**
Expand Down Expand Up @@ -363,22 +366,22 @@ export class PullRequestLinter {
}
}

private async checkRunSucceeded(sha: string, checkName: string) {
private async checkRunConclusion(sha: string, checkName: string): Promise<CheckRunConclusion> {
const response = await this.client.paginate(this.client.checks.listForRef, {
owner: this.prParams.owner,
repo: this.prParams.repo,
ref: sha,
});

// grab the last check run that was started
const status = response
.filter(c => c.started_at !== undefined)
.sort((c1, c2) => c2.started_at!.localeCompare(c1.started_at!))
const conclusion = response
.filter(c => c.name === checkName)
.filter(c => c.started_at != null)
.sort((c1, c2) => c2.started_at!.localeCompare(c1.started_at!))
.map(s => s.conclusion)[0];

console.log(`${checkName} status: ${status}`)
return status === 'success';
console.log(`${checkName} conclusion: ${conclusion}`)
return conclusion;
}

/**
Expand Down Expand Up @@ -607,11 +610,12 @@ export class PullRequestLinter {
const codecovTests: Test[] = [];
for (const c of CODECOV_CHECKS) {
const checkName = `${CODECOV_PREFIX}${c}`;
const succeeded = await this.checkRunSucceeded(sha, checkName);
const status = await this.checkRunConclusion(sha, checkName);
codecovTests.push({
test: () => {
const result = new TestResult();
result.assessFailure(!succeeded, `${checkName} job is not succeeding`);
const message = status == null ? `${checkName} has not started yet` : `${checkName} job is in status: ${status}`;
result.assessFailure(status !== 'success', message);
return result;
}
})
Expand Down
1 change: 1 addition & 0 deletions tools/@aws-cdk/prlint/test/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ function configureMock(pr: Subset<linter.GitHubPr>, prFiles?: linter.GitHubFile[
issues: issuesClient as any,
search: searchClient as any,
repos: reposClient as any,
checks: checksClient as any,
paginate: (method: any, args: any) => { return method(args).data; },
} as any,
});
Expand Down

0 comments on commit d8d8427

Please sign in to comment.