@@ -9,19 +9,28 @@ import github from "@actions/github";
99import { RequestError } from "@octokit/request-error" ;
1010import { getGithubToken , getRepoInfo } from "./helpers.js" ;
1111
12- // Script parameters
1312const 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 ) => {
2534const openPRs = [ ] ;
2635let hasNextPage = true ;
2736let endCursor ;
@@ -49,9 +58,9 @@ export const fetchOpenPRs = async (octokit, user, repo) => {
4958name
5059 }
5160 }
52- reviews(first:1 , states: CHANGES_REQUESTED, author: "github-actions[bot] ") {
61+ reviews(first:100 , states: CHANGES_REQUESTED, author: "${ reviewer } ") {
5362nodes {
54- updatedAt
63+ submittedAt
5564}
5665 }
5766 }
@@ -99,11 +108,13 @@ const isStale = (pullRequest, staleDays) => {
99108pullRequest . commits . nodes [ 0 ] . commit . pushedDate ,
100109) ;
101110if ( 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+ ) ;
103114const lastUpdateDate =
104115lastCommitDate >= lastReviewDate ?lastCommitDate :lastReviewDate ;
105116const now = new Date ( ) ;
106- return now - lastUpdateDate > 1000 * 60 * 60 * 24 * staleDays ;
117+ return ( now - lastUpdateDate ) / ( 1000 * 60 * 60 * 24 ) >= staleDays ;
107118} else {
108119return false ;
109120}
@@ -120,10 +131,11 @@ const run = async () => {
120131debug ( "Creating octokit client..." ) ;
121132const octokit = github . getOctokit ( getGithubToken ( ) ) ;
122133const { owner, repo} = getRepoInfo ( github . context ) ;
134+ const reviewer = getReviewer ( ) ;
123135
124136// Retrieve all theme pull requests.
125137debug ( "Retrieving all theme pull requests..." ) ;
126- const prs = await fetchOpenPRs ( octokit , owner , repo ) ;
138+ const prs = await fetchOpenPRs ( octokit , owner , repo , reviewer ) ;
127139const themePRs = pullsWithLabel ( prs , "themes" ) ;
128140const invalidThemePRs = pullsWithLabel ( themePRs , "invalid" ) ;
129141debug ( "Retrieving stale theme PRs..." ) ;