Skip to content

Commit ace94f5

Browse files
committed
feat: adds method to run workflow for many repos
1 parent f48e990 commit ace94f5

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

lib/gh/workers/trigger-ci.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { OPEN_PR } from '../types.mjs'
2+
import { apiOnlyOptions } from '../yargs/utils.mjs'
3+
4+
export const type = OPEN_PR
5+
6+
export const filter = [
7+
{ value: 'status: SUCCESS', reject: true },
8+
{ value: 'status: FAILURE', reject: true },
9+
]
10+
11+
export const args = {
12+
desc: 'Trigger CI workflows for pull requests by closing and reopening them',
13+
builder: (yargs) =>
14+
yargs
15+
.options({
16+
...apiOnlyOptions(),
17+
})
18+
.example(
19+
'npx -p @npmcli/stafftools@latest gh template-oss trigger-ci',
20+
'Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)'
21+
),
22+
}
23+
24+
export const success = ({ item }) => item.url
25+
26+
export default [
27+
({ item }) => [
28+
'gh',
29+
[
30+
'pr',
31+
'close',
32+
item.number,
33+
`--repo=${item.nameWithOwner}`,
34+
],
35+
],
36+
({ item }) => [
37+
'gh',
38+
[
39+
'pr',
40+
'reopen',
41+
item.number,
42+
`--repo=${item.nameWithOwner}`,
43+
],
44+
],
45+
]

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

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ gh dependabot pr-engines
1616
gh dependabot remove-label
1717
gh dependabot rerun-failed-workflows
1818
gh dependabot review
19+
gh dependabot trigger-ci
1920
gh graphql
2021
gh graphql add-template-oss
2122
gh graphql clone
@@ -33,6 +34,7 @@ gh graphql rerun-failed-workflows
3334
gh graphql review
3435
gh graphql set-secret
3536
gh graphql template-oss-fix
37+
gh graphql trigger-ci
3638
gh labels
3739
gh pending-release
3840
gh pending-release comment
@@ -42,13 +44,15 @@ gh pending-release publish-release
4244
gh pending-release remove-label
4345
gh pending-release rerun-failed-workflows
4446
gh pending-release review
47+
gh pending-release trigger-ci
4548
gh pull-requests
4649
gh pull-requests comment
4750
gh pull-requests merge
4851
gh pull-requests pr-engines
4952
gh pull-requests remove-label
5053
gh pull-requests rerun-failed-workflows
5154
gh pull-requests review
55+
gh pull-requests trigger-ci
5256
gh repos
5357
gh repos add-template-oss
5458
gh repos clone
@@ -66,6 +70,7 @@ gh template-oss remove-label
6670
gh template-oss rerun-failed-workflows
6771
gh template-oss review
6872
gh template-oss template-oss-fix
73+
gh template-oss trigger-ci
6974
`
7075

7176
exports[`test/gh.mjs TAP all commands help > must match snapshot 1`] = `
@@ -176,6 +181,7 @@ Commands:
176181
npx -p @npmcli/stafftools gh dependabot remove-label Remove a label from pull requests
177182
npx -p @npmcli/stafftools gh dependabot rerun-failed-workflows Get engine changes in a pull request
178183
npx -p @npmcli/stafftools gh dependabot review Review pull requests
184+
npx -p @npmcli/stafftools gh dependabot trigger-ci Trigger CI workflows for pull requests by closing and reopening them
179185
180186
Command Options:
181187
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -376,6 +382,37 @@ Other Options:
376382
--config Path to JSON config file
377383
`
378384

385+
exports[`test/gh.mjs TAP all commands help dependabot trigger-ci > must match snapshot 1`] = `
386+
npx -p @npmcli/stafftools gh dependabot trigger-ci
387+
388+
Trigger CI workflows for pull requests by closing and reopening them
389+
390+
Command Options:
391+
--cache how long for gh to cache the query [string] [default: "1m"]
392+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
393+
--table shorthand for --template=table [boolean] [default: false]
394+
--confirm shorthand for --template=confirm [boolean] [default: false]
395+
--report shorthand for --template=report [boolean] [default: false]
396+
397+
Global Options:
398+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
399+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
400+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
401+
--clean whether to rimraf the cwd first [boolean] [default: false]
402+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
403+
--sort key to sort results by [string] [default: "id"]
404+
--json shorthand for --template=json [boolean] [default: false]
405+
--silent shorthand for --template=silent [boolean] [default: false]
406+
407+
Other Options:
408+
--help Show help [boolean]
409+
--version Show version number [boolean]
410+
--config Path to JSON config file
411+
412+
Examples:
413+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)
414+
`
415+
379416
exports[`test/gh.mjs TAP all commands help graphql > must match snapshot 1`] = `
380417
npx -p @npmcli/stafftools gh graphql
381418
@@ -397,6 +434,7 @@ Commands:
397434
npx -p @npmcli/stafftools gh graphql review Review pull requests
398435
npx -p @npmcli/stafftools gh graphql set-secret Set Publish Tokens
399436
npx -p @npmcli/stafftools gh graphql template-oss-fix Fix failing template-oss pull requests
437+
npx -p @npmcli/stafftools gh graphql trigger-ci Trigger CI workflows for pull requests by closing and reopening them
400438
401439
Command Options:
402440
--query path to a query file passed directly to gh api graphql [string] [required]
@@ -877,6 +915,35 @@ Other Options:
877915
--config Path to JSON config file
878916
`
879917

918+
exports[`test/gh.mjs TAP all commands help graphql trigger-ci > must match snapshot 1`] = `
919+
npx -p @npmcli/stafftools gh graphql trigger-ci
920+
921+
Trigger CI workflows for pull requests by closing and reopening them
922+
923+
Command Options:
924+
--query path to a query file passed directly to gh api graphql [string] [required]
925+
--cache how long for gh to cache the query [string] [default: "1m"]
926+
--report shorthand for --template=report [boolean] [default: false]
927+
928+
Global Options:
929+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
930+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
931+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
932+
--clean whether to rimraf the cwd first [boolean] [default: false]
933+
--template how to format the final output [string] [required] [choices: "json", "silent", "report"] [default: "report"]
934+
--sort key to sort results by [string] [default: "id"]
935+
--json shorthand for --template=json [boolean] [default: false]
936+
--silent shorthand for --template=silent [boolean] [default: false]
937+
938+
Other Options:
939+
--help Show help [boolean]
940+
--version Show version number [boolean]
941+
--config Path to JSON config file
942+
943+
Examples:
944+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)
945+
`
946+
880947
exports[`test/gh.mjs TAP all commands help labels > must match snapshot 1`] = `
881948
npx -p @npmcli/stafftools gh labels
882949
@@ -919,6 +986,7 @@ Commands:
919986
npx -p @npmcli/stafftools gh pending-release remove-label Remove a label from pull requests
920987
npx -p @npmcli/stafftools gh pending-release rerun-failed-workflows Get engine changes in a pull request
921988
npx -p @npmcli/stafftools gh pending-release review Review pull requests
989+
npx -p @npmcli/stafftools gh pending-release trigger-ci Trigger CI workflows for pull requests by closing and reopening them
922990
923991
Command Options:
924992
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -1166,6 +1234,39 @@ Other Options:
11661234
--config Path to JSON config file
11671235
`
11681236

1237+
exports[`test/gh.mjs TAP all commands help pending-release trigger-ci > must match snapshot 1`] = `
1238+
npx -p @npmcli/stafftools gh pending-release trigger-ci
1239+
1240+
Trigger CI workflows for pull requests by closing and reopening them
1241+
1242+
Command Options:
1243+
--cache how long for gh to cache the query [string] [default: "1m"]
1244+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1245+
--noDeps Only return items that do not depend on any other items returned [boolean] [default: false]
1246+
--depsPrs Only return items that have no open deps PRs [string] [choices: "", "none", "any"] [default: ""]
1247+
--table shorthand for --template=table [boolean] [default: false]
1248+
--confirm shorthand for --template=confirm [boolean] [default: false]
1249+
--report shorthand for --template=report [boolean] [default: false]
1250+
1251+
Global Options:
1252+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
1253+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
1254+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
1255+
--clean whether to rimraf the cwd first [boolean] [default: false]
1256+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
1257+
--sort key to sort results by [string] [default: "id"]
1258+
--json shorthand for --template=json [boolean] [default: false]
1259+
--silent shorthand for --template=silent [boolean] [default: false]
1260+
1261+
Other Options:
1262+
--help Show help [boolean]
1263+
--version Show version number [boolean]
1264+
--config Path to JSON config file
1265+
1266+
Examples:
1267+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)
1268+
`
1269+
11691270
exports[`test/gh.mjs TAP all commands help pull-requests > must match snapshot 1`] = `
11701271
npx -p @npmcli/stafftools gh pull-requests
11711272
@@ -1178,6 +1279,7 @@ Commands:
11781279
npx -p @npmcli/stafftools gh pull-requests remove-label Remove a label from pull requests
11791280
npx -p @npmcli/stafftools gh pull-requests rerun-failed-workflows Get engine changes in a pull request
11801281
npx -p @npmcli/stafftools gh pull-requests review Review pull requests
1282+
npx -p @npmcli/stafftools gh pull-requests trigger-ci Trigger CI workflows for pull requests by closing and reopening them
11811283
11821284
Command Options:
11831285
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -1392,6 +1494,39 @@ Other Options:
13921494
--config Path to JSON config file
13931495
`
13941496

1497+
exports[`test/gh.mjs TAP all commands help pull-requests trigger-ci > must match snapshot 1`] = `
1498+
npx -p @npmcli/stafftools gh pull-requests trigger-ci
1499+
1500+
Trigger CI workflows for pull requests by closing and reopening them
1501+
1502+
Command Options:
1503+
--cache how long for gh to cache the query [string] [default: "1m"]
1504+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1505+
--label label to filter pull requests [string]
1506+
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
1507+
--table shorthand for --template=table [boolean] [default: false]
1508+
--confirm shorthand for --template=confirm [boolean] [default: false]
1509+
--report shorthand for --template=report [boolean] [default: false]
1510+
1511+
Global Options:
1512+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
1513+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
1514+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
1515+
--clean whether to rimraf the cwd first [boolean] [default: false]
1516+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
1517+
--sort key to sort results by [string] [default: "id"]
1518+
--json shorthand for --template=json [boolean] [default: false]
1519+
--silent shorthand for --template=silent [boolean] [default: false]
1520+
1521+
Other Options:
1522+
--help Show help [boolean]
1523+
--version Show version number [boolean]
1524+
--config Path to JSON config file
1525+
1526+
Examples:
1527+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)
1528+
`
1529+
13951530
exports[`test/gh.mjs TAP all commands help repos > must match snapshot 1`] = `
13961531
npx -p @npmcli/stafftools gh repos
13971532
@@ -1693,6 +1828,7 @@ Commands:
16931828
npx -p @npmcli/stafftools gh template-oss rerun-failed-workflows Get engine changes in a pull request
16941829
npx -p @npmcli/stafftools gh template-oss review Review pull requests
16951830
npx -p @npmcli/stafftools gh template-oss template-oss-fix Fix failing template-oss pull requests
1831+
npx -p @npmcli/stafftools gh template-oss trigger-ci Trigger CI workflows for pull requests by closing and reopening them
16961832
16971833
Command Options:
16981834
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -1924,3 +2060,34 @@ Other Options:
19242060
--version Show version number [boolean]
19252061
--config Path to JSON config file
19262062
`
2063+
2064+
exports[`test/gh.mjs TAP all commands help template-oss trigger-ci > must match snapshot 1`] = `
2065+
npx -p @npmcli/stafftools gh template-oss trigger-ci
2066+
2067+
Trigger CI workflows for pull requests by closing and reopening them
2068+
2069+
Command Options:
2070+
--cache how long for gh to cache the query [string] [default: "1m"]
2071+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
2072+
--table shorthand for --template=table [boolean] [default: false]
2073+
--confirm shorthand for --template=confirm [boolean] [default: false]
2074+
--report shorthand for --template=report [boolean] [default: false]
2075+
2076+
Global Options:
2077+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
2078+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
2079+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
2080+
--clean whether to rimraf the cwd first [boolean] [default: false]
2081+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
2082+
--sort key to sort results by [string] [default: "id"]
2083+
--json shorthand for --template=json [boolean] [default: false]
2084+
--silent shorthand for --template=silent [boolean] [default: false]
2085+
2086+
Other Options:
2087+
--help Show help [boolean]
2088+
--version Show version number [boolean]
2089+
--config Path to JSON config file
2090+
2091+
Examples:
2092+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci Trigger CI for template-oss PRs without definitive status (excludes SUCCESS and FAILURE by default)
2093+
`

0 commit comments

Comments
 (0)