Skip to content

Commit 044caf0

Browse files
committed
feat: adds ability to approve items with failing CI
1 parent 605faf6 commit 044caf0

File tree

3 files changed

+66
-39
lines changed

3 files changed

+66
-39
lines changed

lib/gh/workers/merge.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import { OPEN_PR } from '../types.mjs'
33

44
export const type = OPEN_PR
55

6-
export const filter = [
7-
'status: SUCCESS',
8-
{ value: 'reviewDecision: REVIEW_REQUIRED', reject: true },
9-
]
10-
116
export const args = {
127
desc: 'Merge pull requests',
138
builder: (yargs) =>
@@ -27,7 +22,19 @@ export const args = {
2722
desc: 'whether to approve the pr',
2823
type: 'boolean',
2924
},
25+
requireSuccess: {
26+
default: true,
27+
desc: 'only merge PRs with successful CI status',
28+
type: 'boolean',
29+
},
3030
}),
31+
filter: (argv) => {
32+
const filters = [{ value: 'reviewDecision: REVIEW_REQUIRED', reject: true }]
33+
if (argv.requireSuccess) {
34+
filters.push('status: SUCCESS')
35+
}
36+
return filters
37+
},
3138
}
3239

3340
export const success = ({ item }) => item.url

lib/gh/workers/review.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { apiOnlyOptions } from '../yargs/utils.mjs'
33

44
export const type = OPEN_PR
55

6-
export const filter = ['status: SUCCESS', 'reviewDecision: REVIEW_REQUIRED']
7-
86
export const args = {
97
desc: 'Review pull requests',
108
builder: (yargs) =>
@@ -14,8 +12,20 @@ export const args = {
1412
desc: 'whether to approve the pr',
1513
type: 'boolean',
1614
},
15+
requireSuccess: {
16+
default: true,
17+
desc: 'only review PRs with successful CI status',
18+
type: 'boolean',
19+
},
1720
...apiOnlyOptions(),
1821
}),
22+
filter: (argv) => {
23+
const filters = ['reviewDecision: REVIEW_REQUIRED']
24+
if (argv.requireSuccess) {
25+
filters.push('status: SUCCESS')
26+
}
27+
return filters
28+
},
1929
}
2030

2131
export const success = ({ item }) => item.url

tap-snapshots/test/gh.mjs.test.cjs

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Command Options:
243243
--merge-strategy strategy to use when merging the pull request [required] [choices: "squash", "rebase"]
244244
--remote name of the remote [required] [default: "origin"]
245245
--approve whether to approve the pr [boolean] [default: false]
246+
--requireSuccess only merge PRs with successful CI status [boolean] [default: true]
246247
247248
Global Options:
248249
-c, --cwd base directory to run filesystem related commands [string] [default: "$HOME/projects"]
@@ -353,12 +354,13 @@ npx -p @npmcli/stafftools gh dependabot review
353354
Review pull requests
354355
355356
Command Options:
356-
--cache how long for gh to cache the query [string] [default: "1m"]
357-
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
358-
--table shorthand for --template=table [boolean] [default: false]
359-
--confirm shorthand for --template=confirm [boolean] [default: false]
360-
--report shorthand for --template=report [boolean] [default: false]
361-
--approve whether to approve the pr [boolean] [default: false]
357+
--cache how long for gh to cache the query [string] [default: "1m"]
358+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
359+
--table shorthand for --template=table [boolean] [default: false]
360+
--confirm shorthand for --template=confirm [boolean] [default: false]
361+
--report shorthand for --template=report [boolean] [default: false]
362+
--approve whether to approve the pr [boolean] [default: false]
363+
--requireSuccess only review PRs with successful CI status [boolean] [default: true]
362364
363365
Global Options:
364366
-c, --cwd base directory to run filesystem related commands [string] [default: null]
@@ -549,6 +551,7 @@ Command Options:
549551
--merge-strategy strategy to use when merging the pull request [required] [choices: "squash", "rebase"]
550552
--remote name of the remote [required] [default: "origin"]
551553
--approve whether to approve the pr [boolean] [default: false]
554+
--requireSuccess only merge PRs with successful CI status [boolean] [default: true]
552555
553556
Global Options:
554557
-c, --cwd base directory to run filesystem related commands [string] [default: "$HOME/projects"]
@@ -796,10 +799,11 @@ npx -p @npmcli/stafftools gh graphql review
796799
Review pull requests
797800
798801
Command Options:
799-
--query path to a query file passed directly to gh api graphql [string] [required]
800-
--cache how long for gh to cache the query [string] [default: "1m"]
801-
--report shorthand for --template=report [boolean] [default: false]
802-
--approve whether to approve the pr [boolean] [default: false]
802+
--query path to a query file passed directly to gh api graphql [string] [required]
803+
--cache how long for gh to cache the query [string] [default: "1m"]
804+
--report shorthand for --template=report [boolean] [default: false]
805+
--approve whether to approve the pr [boolean] [default: false]
806+
--requireSuccess only review PRs with successful CI status [boolean] [default: true]
803807
804808
Global Options:
805809
-c, --cwd base directory to run filesystem related commands [string] [default: null]
@@ -992,6 +996,7 @@ Command Options:
992996
--merge-strategy strategy to use when merging the pull request [required] [choices: "squash", "rebase"]
993997
--remote name of the remote [required] [default: "origin"]
994998
--approve whether to approve the pr [boolean] [default: false]
999+
--requireSuccess only merge PRs with successful CI status [boolean] [default: true]
9951000
9961001
Global Options:
9971002
-c, --cwd base directory to run filesystem related commands [string] [default: "$HOME/projects"]
@@ -1141,14 +1146,15 @@ npx -p @npmcli/stafftools gh pending-release review
11411146
Review pull requests
11421147
11431148
Command Options:
1144-
--cache how long for gh to cache the query [string] [default: "1m"]
1145-
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1146-
--noDeps Only return items that do not depend on any other items returned [boolean] [default: false]
1147-
--depsPrs Only return items that have no open deps PRs [string] [choices: "", "none", "any"] [default: ""]
1148-
--table shorthand for --template=table [boolean] [default: false]
1149-
--confirm shorthand for --template=confirm [boolean] [default: false]
1150-
--report shorthand for --template=report [boolean] [default: false]
1151-
--approve whether to approve the pr [boolean] [default: false]
1149+
--cache how long for gh to cache the query [string] [default: "1m"]
1150+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1151+
--noDeps Only return items that do not depend on any other items returned [boolean] [default: false]
1152+
--depsPrs Only return items that have no open deps PRs [string] [choices: "", "none", "any"] [default: ""]
1153+
--table shorthand for --template=table [boolean] [default: false]
1154+
--confirm shorthand for --template=confirm [boolean] [default: false]
1155+
--report shorthand for --template=report [boolean] [default: false]
1156+
--approve whether to approve the pr [boolean] [default: false]
1157+
--requireSuccess only review PRs with successful CI status [boolean] [default: true]
11521158
11531159
Global Options:
11541160
-c, --cwd base directory to run filesystem related commands [string] [default: null]
@@ -1251,6 +1257,7 @@ Command Options:
12511257
--merge-strategy strategy to use when merging the pull request [required] [choices: "squash", "rebase"]
12521258
--remote name of the remote [required] [default: "origin"]
12531259
--approve whether to approve the pr [boolean] [default: false]
1260+
--requireSuccess only merge PRs with successful CI status [boolean] [default: true]
12541261
12551262
Global Options:
12561263
-c, --cwd base directory to run filesystem related commands [string] [default: "$HOME/projects"]
@@ -1367,14 +1374,15 @@ npx -p @npmcli/stafftools gh pull-requests review
13671374
Review pull requests
13681375
13691376
Command Options:
1370-
--cache how long for gh to cache the query [string] [default: "1m"]
1371-
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1372-
--label label to filter pull requests [string]
1373-
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
1374-
--table shorthand for --template=table [boolean] [default: false]
1375-
--confirm shorthand for --template=confirm [boolean] [default: false]
1376-
--report shorthand for --template=report [boolean] [default: false]
1377-
--approve whether to approve the pr [boolean] [default: false]
1377+
--cache how long for gh to cache the query [string] [default: "1m"]
1378+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1379+
--label label to filter pull requests [string]
1380+
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
1381+
--table shorthand for --template=table [boolean] [default: false]
1382+
--confirm shorthand for --template=confirm [boolean] [default: false]
1383+
--report shorthand for --template=report [boolean] [default: false]
1384+
--approve whether to approve the pr [boolean] [default: false]
1385+
--requireSuccess only review PRs with successful CI status [boolean] [default: true]
13781386
13791387
Global Options:
13801388
-c, --cwd base directory to run filesystem related commands [string] [default: null]
@@ -1760,6 +1768,7 @@ Command Options:
17601768
--merge-strategy strategy to use when merging the pull request [required] [choices: "squash", "rebase"]
17611769
--remote name of the remote [required] [default: "origin"]
17621770
--approve whether to approve the pr [boolean] [default: false]
1771+
--requireSuccess only merge PRs with successful CI status [boolean] [default: true]
17631772
17641773
Global Options:
17651774
-c, --cwd base directory to run filesystem related commands [string] [default: "$HOME/projects"]
@@ -1870,12 +1879,13 @@ npx -p @npmcli/stafftools gh template-oss review
18701879
Review pull requests
18711880
18721881
Command Options:
1873-
--cache how long for gh to cache the query [string] [default: "1m"]
1874-
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1875-
--table shorthand for --template=table [boolean] [default: false]
1876-
--confirm shorthand for --template=confirm [boolean] [default: false]
1877-
--report shorthand for --template=report [boolean] [default: false]
1878-
--approve whether to approve the pr [boolean] [default: false]
1882+
--cache how long for gh to cache the query [string] [default: "1m"]
1883+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1884+
--table shorthand for --template=table [boolean] [default: false]
1885+
--confirm shorthand for --template=confirm [boolean] [default: false]
1886+
--report shorthand for --template=report [boolean] [default: false]
1887+
--approve whether to approve the pr [boolean] [default: false]
1888+
--requireSuccess only review PRs with successful CI status [boolean] [default: true]
18791889
18801890
Global Options:
18811891
-c, --cwd base directory to run filesystem related commands [string] [default: null]

0 commit comments

Comments
 (0)