fix(dev-infra): delay checking if a closed pr has been merged by 30 seconds (#40181)
Delaying the check if a closed PR was closed by a merge or just closed by 30 seconds allows for Github to have time to update the PR to be associated to the commit which closed the PR. Without this delay, a race condition can exist in which we check for how a PR was closed before this association is made. PR Close #40181
This commit is contained in:
parent
0153cd0d28
commit
7a819caef6
|
@ -5327,6 +5327,8 @@ const findOwnedForksOfRepoQuery = typedGraphqlify.params({
|
|||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
/** Thirty seconds in milliseconds. */
|
||||
const THIRTY_SECONDS_IN_MS = 30000;
|
||||
/** Gets whether a given pull request has been merged. */
|
||||
function getPullRequestState(api, id) {
|
||||
return tslib.__awaiter(this, void 0, void 0, function* () {
|
||||
|
@ -5334,12 +5336,15 @@ function getPullRequestState(api, id) {
|
|||
if (data.merged) {
|
||||
return 'merged';
|
||||
}
|
||||
else if (data.closed_at !== null) {
|
||||
// Check if the PR was closed more than 30 seconds ago, this extra time gives Github time to
|
||||
// update the closed pull request to be associated with the closing commit.
|
||||
// Note: a Date constructed with `null` creates an object at 0 time, which will never be greater
|
||||
// than the current date time.
|
||||
if (data.closed_at !== null &&
|
||||
(new Date(data.closed_at).getTime() < Date.now() - THIRTY_SECONDS_IN_MS)) {
|
||||
return (yield isPullRequestClosedWithAssociatedCommit(api, id)) ? 'merged' : 'closed';
|
||||
}
|
||||
else {
|
||||
return 'open';
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
import * as Octokit from '@octokit/rest';
|
||||
import {GitClient} from '../../utils/git/index';
|
||||
|
||||
/** Thirty seconds in milliseconds. */
|
||||
const THIRTY_SECONDS_IN_MS = 30000;
|
||||
|
||||
/** State of a pull request in Github. */
|
||||
export type PullRequestState = 'merged'|'closed'|'open';
|
||||
|
||||
|
@ -17,11 +20,16 @@ export async function getPullRequestState(api: GitClient, id: number): Promise<P
|
|||
const {data} = await api.github.pulls.get({...api.remoteParams, pull_number: id});
|
||||
if (data.merged) {
|
||||
return 'merged';
|
||||
} else if (data.closed_at !== null) {
|
||||
return await isPullRequestClosedWithAssociatedCommit(api, id) ? 'merged' : 'closed';
|
||||
} else {
|
||||
return 'open';
|
||||
}
|
||||
// Check if the PR was closed more than 30 seconds ago, this extra time gives Github time to
|
||||
// update the closed pull request to be associated with the closing commit.
|
||||
// Note: a Date constructed with `null` creates an object at 0 time, which will never be greater
|
||||
// than the current date time.
|
||||
if (data.closed_at !== null &&
|
||||
(new Date(data.closed_at).getTime() < Date.now() - THIRTY_SECONDS_IN_MS)) {
|
||||
return await isPullRequestClosedWithAssociatedCommit(api, id) ? 'merged' : 'closed';
|
||||
}
|
||||
return 'open';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue