Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): do not trust committed date #758

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,15 @@ export default class PRChecker {
});

const totalCommits = afterCommits.length;
if (totalCommits === 0 && this.pr.timelineItems.updatedAt > reviewDate) {
// Some commits were pushed, but all the commits have a commit date prior
// to the last review. It means that either that a long time elapsed
// between the commit and the push, or that the clock on the dev machine
// is wrong, or the commit date was forged.
cli.warn('Something was pushed to the Pull Request branch since the last approving review.');
return false;
}

if (totalCommits > 0) {
cli.warn('Commits were pushed since the last approving review:');
const sliceLength = maxCommits === 0 ? totalCommits : -maxCommits;
Expand Down
3 changes: 3 additions & 0 deletions lib/queries/PR.gql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ query PR($prid: Int!, $owner: String!, $repo: String!) {
path
}
},
timelineItems(itemTypes: [HEAD_REF_FORCE_PUSHED_EVENT, PULL_REQUEST_COMMIT]) {
updatedAt
},
title,
baseRefName,
headRefName,
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/semver_major_pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
}
]
},
"timelineItems": {
"updatedAt": "2017-10-24T11:13:43Z"
},
"title": "lib: awesome changes",
"baseRefName": "main",
"headRefName": "awesome-changes"
Expand Down
25 changes: 25 additions & 0 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,31 @@ describe('PRChecker', () => {
cli.assertCalledWith(expectedLogs);
});

it('should return true if PR can be landed', () => {
const expectedLogs = {
warn: [
['Something was pushed to the Pull Request branch since the last approving review.']
],
info: [],
error: []
};

const checker = new PRChecker(cli, {
pr: { ...semverMajorPR, timelineItems: { updatedAt: new Date().toISOString() } },
reviewers: allGreenReviewers,
comments: commentsWithLGTM,
reviews: approvingReviews,
commits: simpleCommits,
collaborators,
authorIsNew: () => true,
getThread: PRData.prototype.getThread
}, {}, argv);

const status = checker.checkCommitsAfterReview();
assert.deepStrictEqual(status, false);
cli.assertCalledWith(expectedLogs);
});

it('should skip the check if there are no reviews', () => {
const { commits } = multipleCommitsAfterReview;
const expectedLogs = {};
Expand Down
Loading