@@ -9,19 +9,28 @@ import github from "@actions/github";
9
9
import { RequestError } from "@octokit/request-error" ;
10
10
import { getGithubToken , getRepoInfo } from "./helpers.js" ;
11
11
12
- // Script parameters
13
12
const CLOSING_COMMENT = `
14
13
\rThis PR has been automatically closed due to inactivity. Please feel free to reopen it if you need to continue working on it.\
15
14
\rThank you for your contributions.
16
15
` ;
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
+ } ;
17
25
18
26
/**
19
27
* Fetch open PRs from a given repository.
20
28
* @param user The user name of the repository owner.
21
29
* @param repo The name of the repository.
30
+ * @param reviewer The reviewer to filter by.
22
31
* @returns The open PRs.
23
32
*/
24
- export const fetchOpenPRs = async ( octokit , user , repo ) => {
33
+ export const fetchOpenPRs = async ( octokit , user , repo , reviewer ) => {
25
34
const openPRs = [ ] ;
26
35
let hasNextPage = true ;
27
36
let endCursor ;
@@ -49,9 +58,9 @@ export const fetchOpenPRs = async (octokit, user, repo) => {
49
58
name
50
59
}
51
60
}
52
- reviews(first: 1 , states: CHANGES_REQUESTED, author: "github-actions[bot] ") {
61
+ reviews(first: 100 , states: CHANGES_REQUESTED, author: "${ reviewer } ") {
53
62
nodes {
54
- updatedAt
63
+ submittedAt
55
64
}
56
65
}
57
66
}
@@ -99,11 +108,13 @@ const isStale = (pullRequest, staleDays) => {
99
108
pullRequest . commits . nodes [ 0 ] . commit . pushedDate ,
100
109
) ;
101
110
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
+ ) ;
103
114
const lastUpdateDate =
104
115
lastCommitDate >= lastReviewDate ? lastCommitDate : lastReviewDate ;
105
116
const now = new Date ( ) ;
106
- return now - lastUpdateDate > 1000 * 60 * 60 * 24 * staleDays ;
117
+ return ( now - lastUpdateDate ) / ( 1000 * 60 * 60 * 24 ) >= staleDays ;
107
118
} else {
108
119
return false ;
109
120
}
@@ -120,10 +131,11 @@ const run = async () => {
120
131
debug ( "Creating octokit client..." ) ;
121
132
const octokit = github . getOctokit ( getGithubToken ( ) ) ;
122
133
const { owner, repo } = getRepoInfo ( github . context ) ;
134
+ const reviewer = getReviewer ( ) ;
123
135
124
136
// Retrieve all theme pull requests.
125
137
debug ( "Retrieving all theme pull requests..." ) ;
126
- const prs = await fetchOpenPRs ( octokit , owner , repo ) ;
138
+ const prs = await fetchOpenPRs ( octokit , owner , repo , reviewer ) ;
127
139
const themePRs = pullsWithLabel ( prs , "themes" ) ;
128
140
const invalidThemePRs = pullsWithLabel ( themePRs , "invalid" ) ;
129
141
debug ( "Retrieving stale theme PRs..." ) ;
0 commit comments