Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d10912

Browse files
authored
ci: fix stale closer action review sort bug (anuraghazra#2201)
This commit makes sure the PR staleness is checked by the latest review that is done.
1 parent bb56e3b commit 1d10912

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

scripts/close-stale-theme-prs.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ import github from "@actions/github";
99
import { RequestError } from "@octokit/request-error";
1010
import { getGithubToken, getRepoInfo } from "./helpers.js";
1111

12-
// Script parameters
1312
const CLOSING_COMMENT = `
1413
\rThis PR has been automatically closed due to inactivity. Please feel free to reopen it if you need to continue working on it.\
1514
\rThank you for your contributions.
1615
`;
16+
const REVIEWER = "github-actions[bot]";
17+
18+
/**
19+
* Retrieve the review user.
20+
* @returns {string} review user.
21+
*/
22+
const getReviewer = () => {
23+
return process.env.REVIEWER ? process.env.REVIEWER : REVIEWER;
24+
};
1725

1826
/**
1927
* Fetch open PRs from a given repository.
2028
* @param user The user name of the repository owner.
2129
* @param repo The name of the repository.
30+
* @param reviewer The reviewer to filter by.
2231
* @returns The open PRs.
2332
*/
24-
export const fetchOpenPRs = async (octokit, user, repo) => {
33+
export const fetchOpenPRs = async (octokit, user, repo, reviewer) => {
2534
const openPRs = [];
2635
let hasNextPage = true;
2736
let endCursor;
@@ -49,9 +58,9 @@ export const fetchOpenPRs = async (octokit, user, repo) => {
4958
name
5059
}
5160
}
52-
reviews(first: 1, states: CHANGES_REQUESTED, author: "github-actions[bot]") {
61+
reviews(first: 100, states: CHANGES_REQUESTED, author: "${reviewer}") {
5362
nodes {
54-
updatedAt
63+
submittedAt
5564
}
5665
}
5766
}
@@ -99,11 +108,13 @@ const isStale = (pullRequest, staleDays) => {
99108
pullRequest.commits.nodes[0].commit.pushedDate,
100109
);
101110
if (pullRequest.reviews.nodes[0]) {
102-
const lastReviewDate = new Date(pullRequest.reviews.nodes[0].updatedAt);
111+
const lastReviewDate = new Date(
112+
pullRequest.reviews.nodes.sort((a, b) => (a < b ? 1 : -1))[0].submittedAt,
113+
);
103114
const lastUpdateDate =
104115
lastCommitDate >= lastReviewDate ? lastCommitDate : lastReviewDate;
105116
const now = new Date();
106-
return now - lastUpdateDate > 1000 * 60 * 60 * 24 * staleDays;
117+
return (now - lastUpdateDate) / (1000 * 60 * 60 * 24) >= staleDays;
107118
} else {
108119
return false;
109120
}
@@ -120,10 +131,11 @@ const run = async () => {
120131
debug("Creating octokit client...");
121132
const octokit = github.getOctokit(getGithubToken());
122133
const { owner, repo } = getRepoInfo(github.context);
134+
const reviewer = getReviewer();
123135

124136
// Retrieve all theme pull requests.
125137
debug("Retrieving all theme pull requests...");
126-
const prs = await fetchOpenPRs(octokit, owner, repo);
138+
const prs = await fetchOpenPRs(octokit, owner, repo, reviewer);
127139
const themePRs = pullsWithLabel(prs, "themes");
128140
const invalidThemePRs = pullsWithLabel(themePRs, "invalid");
129141
debug("Retrieving stale theme PRs...");

scripts/helpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { getInput } from "@actions/core";
66

7-
// Script variables.
87
const OWNER = "anuraghazra";
98
const REPO = "github-readme-stats";
109

scripts/preview-theme.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { isValidHexColor } from "../src/common/utils.js";
1616
import { themes } from "../themes/index.js";
1717
import { getGithubToken, getRepoInfo } from "./helpers.js";
1818

19-
// Script variables.
2019
const COMMENTER = "github-actions[bot]";
2120

2221
const COMMENT_TITLE = "Automated Theme Preview";

0 commit comments

Comments
 (0)