Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Jan 16, 2025
1 parent 98c3ec1 commit c5da0d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
47 changes: 25 additions & 22 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions tools/@aws-cdk/prlint/test/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ describe('integration tests required on features', () => {
function configureMock(pr: Subset<linter.GitHubPr>, 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 }) {
Expand Down Expand Up @@ -1193,11 +1193,11 @@ function configureMock(pr: Subset<linter.GitHubPr>, 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'
})),
}
}
}
Expand Down

0 comments on commit c5da0d3

Please sign in to comment.