Skip to content

Commit 28895db

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

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

lib/gh/workers/trigger-ci.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
8+
export const args = {
9+
desc: 'Trigger CI workflows for pull requests',
10+
builder: (yargs) =>
11+
yargs
12+
.options({
13+
workflow: {
14+
demand: true,
15+
default: 'CI',
16+
desc: 'Name of the workflow to trigger',
17+
},
18+
...apiOnlyOptions(),
19+
})
20+
.example(
21+
"npx -p @npmcli/stafftools@latest gh template-oss trigger-ci --reject 'status: SUCCESS' --reject 'status: FAILURE'",
22+
'Trigger CI for template-oss PRs without definitive status'
23+
),
24+
}
25+
26+
export const success = ({ item }) => item.url
27+
28+
export default [
29+
({ item, argv }) => [
30+
'gh',
31+
[
32+
'workflow',
33+
'run',
34+
`"${argv.workflow}"`,
35+
`--repo=${item.nameWithOwner}`,
36+
'--ref',
37+
item.headRef,
38+
],
39+
],
40+
]

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

Lines changed: 172 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
179185
180186
Command Options:
181187
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -376,6 +382,38 @@ 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
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+
--workflow Name of the workflow to trigger [required] [default: "CI"]
397+
398+
Global Options:
399+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
400+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
401+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
402+
--clean whether to rimraf the cwd first [boolean] [default: false]
403+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
404+
--sort key to sort results by [string] [default: "id"]
405+
--json shorthand for --template=json [boolean] [default: false]
406+
--silent shorthand for --template=silent [boolean] [default: false]
407+
408+
Other Options:
409+
--help Show help [boolean]
410+
--version Show version number [boolean]
411+
--config Path to JSON config file
412+
413+
Examples:
414+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci --reject 'status: SUCCESS' --reject 'status: FAILURE' Trigger CI for template-oss PRs without definitive status
415+
`
416+
379417
exports[`test/gh.mjs TAP all commands help graphql > must match snapshot 1`] = `
380418
npx -p @npmcli/stafftools gh graphql
381419
@@ -397,6 +435,7 @@ Commands:
397435
npx -p @npmcli/stafftools gh graphql review Review pull requests
398436
npx -p @npmcli/stafftools gh graphql set-secret Set Publish Tokens
399437
npx -p @npmcli/stafftools gh graphql template-oss-fix Fix failing template-oss pull requests
438+
npx -p @npmcli/stafftools gh graphql trigger-ci Trigger CI workflows for pull requests
400439
401440
Command Options:
402441
--query path to a query file passed directly to gh api graphql [string] [required]
@@ -877,6 +916,36 @@ Other Options:
877916
--config Path to JSON config file
878917
`
879918

919+
exports[`test/gh.mjs TAP all commands help graphql trigger-ci > must match snapshot 1`] = `
920+
npx -p @npmcli/stafftools gh graphql trigger-ci
921+
922+
Trigger CI workflows for pull requests
923+
924+
Command Options:
925+
--query path to a query file passed directly to gh api graphql [string] [required]
926+
--cache how long for gh to cache the query [string] [default: "1m"]
927+
--report shorthand for --template=report [boolean] [default: false]
928+
--workflow Name of the workflow to trigger [required] [default: "CI"]
929+
930+
Global Options:
931+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
932+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
933+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
934+
--clean whether to rimraf the cwd first [boolean] [default: false]
935+
--template how to format the final output [string] [required] [choices: "json", "silent", "report"] [default: "report"]
936+
--sort key to sort results by [string] [default: "id"]
937+
--json shorthand for --template=json [boolean] [default: false]
938+
--silent shorthand for --template=silent [boolean] [default: false]
939+
940+
Other Options:
941+
--help Show help [boolean]
942+
--version Show version number [boolean]
943+
--config Path to JSON config file
944+
945+
Examples:
946+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci --reject 'status: SUCCESS' --reject 'status: FAILURE' Trigger CI for template-oss PRs without definitive status
947+
`
948+
880949
exports[`test/gh.mjs TAP all commands help labels > must match snapshot 1`] = `
881950
npx -p @npmcli/stafftools gh labels
882951
@@ -919,6 +988,7 @@ Commands:
919988
npx -p @npmcli/stafftools gh pending-release remove-label Remove a label from pull requests
920989
npx -p @npmcli/stafftools gh pending-release rerun-failed-workflows Get engine changes in a pull request
921990
npx -p @npmcli/stafftools gh pending-release review Review pull requests
991+
npx -p @npmcli/stafftools gh pending-release trigger-ci Trigger CI workflows for pull requests
922992
923993
Command Options:
924994
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -1166,6 +1236,40 @@ Other Options:
11661236
--config Path to JSON config file
11671237
`
11681238

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

1500+
exports[`test/gh.mjs TAP all commands help pull-requests trigger-ci > must match snapshot 1`] = `
1501+
npx -p @npmcli/stafftools gh pull-requests trigger-ci
1502+
1503+
Trigger CI workflows for pull requests
1504+
1505+
Command Options:
1506+
--cache how long for gh to cache the query [string] [default: "1m"]
1507+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1508+
--label label to filter pull requests [string]
1509+
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
1510+
--table shorthand for --template=table [boolean] [default: false]
1511+
--confirm shorthand for --template=confirm [boolean] [default: false]
1512+
--report shorthand for --template=report [boolean] [default: false]
1513+
--workflow Name of the workflow to trigger [required] [default: "CI"]
1514+
1515+
Global Options:
1516+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
1517+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
1518+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
1519+
--clean whether to rimraf the cwd first [boolean] [default: false]
1520+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
1521+
--sort key to sort results by [string] [default: "id"]
1522+
--json shorthand for --template=json [boolean] [default: false]
1523+
--silent shorthand for --template=silent [boolean] [default: false]
1524+
1525+
Other Options:
1526+
--help Show help [boolean]
1527+
--version Show version number [boolean]
1528+
--config Path to JSON config file
1529+
1530+
Examples:
1531+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci --reject 'status: SUCCESS' --reject 'status: FAILURE' Trigger CI for template-oss PRs without definitive status
1532+
`
1533+
13951534
exports[`test/gh.mjs TAP all commands help repos > must match snapshot 1`] = `
13961535
npx -p @npmcli/stafftools gh repos
13971536
@@ -1693,6 +1832,7 @@ Commands:
16931832
npx -p @npmcli/stafftools gh template-oss rerun-failed-workflows Get engine changes in a pull request
16941833
npx -p @npmcli/stafftools gh template-oss review Review pull requests
16951834
npx -p @npmcli/stafftools gh template-oss template-oss-fix Fix failing template-oss pull requests
1835+
npx -p @npmcli/stafftools gh template-oss trigger-ci Trigger CI workflows for pull requests
16961836
16971837
Command Options:
16981838
--cache how long for gh to cache the query [string] [default: "1m"]
@@ -1924,3 +2064,35 @@ Other Options:
19242064
--version Show version number [boolean]
19252065
--config Path to JSON config file
19262066
`
2067+
2068+
exports[`test/gh.mjs TAP all commands help template-oss trigger-ci > must match snapshot 1`] = `
2069+
npx -p @npmcli/stafftools gh template-oss trigger-ci
2070+
2071+
Trigger CI workflows for pull requests
2072+
2073+
Command Options:
2074+
--cache how long for gh to cache the query [string] [default: "1m"]
2075+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
2076+
--table shorthand for --template=table [boolean] [default: false]
2077+
--confirm shorthand for --template=confirm [boolean] [default: false]
2078+
--report shorthand for --template=report [boolean] [default: false]
2079+
--workflow Name of the workflow to trigger [required] [default: "CI"]
2080+
2081+
Global Options:
2082+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
2083+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
2084+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
2085+
--clean whether to rimraf the cwd first [boolean] [default: false]
2086+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
2087+
--sort key to sort results by [string] [default: "id"]
2088+
--json shorthand for --template=json [boolean] [default: false]
2089+
--silent shorthand for --template=silent [boolean] [default: false]
2090+
2091+
Other Options:
2092+
--help Show help [boolean]
2093+
--version Show version number [boolean]
2094+
--config Path to JSON config file
2095+
2096+
Examples:
2097+
npx -p @npmcli/stafftools@latest gh template-oss trigger-ci --reject 'status: SUCCESS' --reject 'status: FAILURE' Trigger CI for template-oss PRs without definitive status
2098+
`

0 commit comments

Comments
 (0)