Skip to content

Commit 5c172d9

Browse files
authored
feat: add worker to comment on a PR (#123)
I used this to tell depdendabot to ignore all all the open `tap` PRs: ```sh stafftools dependabot comment --filter 'title: "bump tap"' --body '@dependabot ignore this major version' ```
1 parent d9317f6 commit 5c172d9

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed

lib/gh/workers/comment.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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: 'Comment on pull requests',
10+
builder: (yargs) =>
11+
yargs.options({
12+
body: {
13+
default: false,
14+
desc: 'the body to post',
15+
type: 'string',
16+
},
17+
...apiOnlyOptions(),
18+
}),
19+
}
20+
21+
export const success = ({ item }) => item.url
22+
23+
export default [
24+
({ item, argv }) => [
25+
'gh',
26+
[
27+
'pr',
28+
'comment',
29+
item.number,
30+
`--repo='${item.nameWithOwner}'`,
31+
'--body',
32+
`'${argv.body}'`,
33+
],
34+
],
35+
]

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

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gh
1010
gh closed-pending-release
1111
gh closed-pending-release remove-label
1212
gh dependabot
13+
gh dependabot comment
1314
gh dependabot merge
1415
gh dependabot pr-engines
1516
gh dependabot remove-label
@@ -18,6 +19,7 @@ gh dependabot review
1819
gh graphql
1920
gh graphql add-template-oss
2021
gh graphql clone
22+
gh graphql comment
2123
gh graphql delete-branches
2224
gh graphql merge
2325
gh graphql metrics
@@ -33,13 +35,15 @@ gh graphql set-secret
3335
gh graphql template-oss-fix
3436
gh labels
3537
gh pending-release
38+
gh pending-release comment
3639
gh pending-release merge
3740
gh pending-release pr-engines
3841
gh pending-release publish-release
3942
gh pending-release remove-label
4043
gh pending-release rerun-failed-workflows
4144
gh pending-release review
4245
gh pull-requests
46+
gh pull-requests comment
4347
gh pull-requests merge
4448
gh pull-requests pr-engines
4549
gh pull-requests remove-label
@@ -55,6 +59,7 @@ gh repos pull
5559
gh repos repo-settings
5660
gh repos set-secret
5761
gh template-oss
62+
gh template-oss comment
5863
gh template-oss merge
5964
gh template-oss pr-engines
6065
gh template-oss remove-label
@@ -165,6 +170,7 @@ npx -p @npmcli/stafftools gh dependabot
165170
Fetch dependabot pull requests
166171
167172
Commands:
173+
npx -p @npmcli/stafftools gh dependabot comment Comment on pull requests
168174
npx -p @npmcli/stafftools gh dependabot merge Merge pull requests
169175
npx -p @npmcli/stafftools gh dependabot pr-engines Get engine changes in a pull request
170176
npx -p @npmcli/stafftools gh dependabot remove-label Remove a label from pull requests
@@ -194,6 +200,35 @@ Other Options:
194200
--config Path to JSON config file
195201
`
196202

203+
exports[`test/gh.mjs TAP all commands help dependabot comment > must match snapshot 1`] = `
204+
npx -p @npmcli/stafftools gh dependabot comment
205+
206+
Comment on pull requests
207+
208+
Command Options:
209+
--cache how long for gh to cache the query [string] [default: "1m"]
210+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
211+
--table shorthand for --template=table [boolean] [default: false]
212+
--confirm shorthand for --template=confirm [boolean] [default: false]
213+
--report shorthand for --template=report [boolean] [default: false]
214+
--body the body to post [string] [default: false]
215+
216+
Global Options:
217+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
218+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
219+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
220+
--clean whether to rimraf the cwd first [boolean] [default: false]
221+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
222+
--sort key to sort results by [string] [default: "id"]
223+
--json shorthand for --template=json [boolean] [default: false]
224+
--silent shorthand for --template=silent [boolean] [default: false]
225+
226+
Other Options:
227+
--help Show help [boolean]
228+
--version Show version number [boolean]
229+
--config Path to JSON config file
230+
`
231+
197232
exports[`test/gh.mjs TAP all commands help dependabot merge > must match snapshot 1`] = `
198233
npx -p @npmcli/stafftools gh dependabot merge
199234
@@ -349,6 +384,7 @@ Fetch a graphql query
349384
Commands:
350385
npx -p @npmcli/stafftools gh graphql add-template-oss Add template-oss to a repo
351386
npx -p @npmcli/stafftools gh graphql clone Clone repos into a directory
387+
npx -p @npmcli/stafftools gh graphql comment Comment on pull requests
352388
npx -p @npmcli/stafftools gh graphql delete-branches Delete branches of repos with no remote counterpart
353389
npx -p @npmcli/stafftools gh graphql merge Merge pull requests
354390
npx -p @npmcli/stafftools gh graphql pr-engines Get engine changes in a pull request
@@ -444,6 +480,33 @@ Other Options:
444480
--config Path to JSON config file
445481
`
446482

483+
exports[`test/gh.mjs TAP all commands help graphql comment > must match snapshot 1`] = `
484+
npx -p @npmcli/stafftools gh graphql comment
485+
486+
Comment on pull requests
487+
488+
Command Options:
489+
--query path to a query file passed directly to gh api graphql [string] [required]
490+
--cache how long for gh to cache the query [string] [default: "1m"]
491+
--report shorthand for --template=report [boolean] [default: false]
492+
--body the body to post [string] [default: false]
493+
494+
Global Options:
495+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
496+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
497+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
498+
--clean whether to rimraf the cwd first [boolean] [default: false]
499+
--template how to format the final output [string] [required] [choices: "json", "silent", "report"] [default: "report"]
500+
--sort key to sort results by [string] [default: "id"]
501+
--json shorthand for --template=json [boolean] [default: false]
502+
--silent shorthand for --template=silent [boolean] [default: false]
503+
504+
Other Options:
505+
--help Show help [boolean]
506+
--version Show version number [boolean]
507+
--config Path to JSON config file
508+
`
509+
447510
exports[`test/gh.mjs TAP all commands help graphql delete-branches > must match snapshot 1`] = `
448511
npx -p @npmcli/stafftools gh graphql delete-branches
449512
@@ -848,6 +911,7 @@ npx -p @npmcli/stafftools gh pending-release
848911
Fetch pending release pull requests
849912
850913
Commands:
914+
npx -p @npmcli/stafftools gh pending-release comment Comment on pull requests
851915
npx -p @npmcli/stafftools gh pending-release merge Merge pull requests
852916
npx -p @npmcli/stafftools gh pending-release pr-engines Get engine changes in a pull request
853917
npx -p @npmcli/stafftools gh pending-release publish-release Merge pending release PRs and publish the resulting release
@@ -880,6 +944,37 @@ Other Options:
880944
--config Path to JSON config file
881945
`
882946

947+
exports[`test/gh.mjs TAP all commands help pending-release comment > must match snapshot 1`] = `
948+
npx -p @npmcli/stafftools gh pending-release comment
949+
950+
Comment on pull requests
951+
952+
Command Options:
953+
--cache how long for gh to cache the query [string] [default: "1m"]
954+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
955+
--noDeps Only return items that do not depend on any other items returned [boolean] [default: false]
956+
--depsPrs Only return items that have no open deps PRs [string] [choices: "", "none", "any"] [default: ""]
957+
--table shorthand for --template=table [boolean] [default: false]
958+
--confirm shorthand for --template=confirm [boolean] [default: false]
959+
--report shorthand for --template=report [boolean] [default: false]
960+
--body the body to post [string] [default: false]
961+
962+
Global Options:
963+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
964+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
965+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
966+
--clean whether to rimraf the cwd first [boolean] [default: false]
967+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
968+
--sort key to sort results by [string] [default: "id"]
969+
--json shorthand for --template=json [boolean] [default: false]
970+
--silent shorthand for --template=silent [boolean] [default: false]
971+
972+
Other Options:
973+
--help Show help [boolean]
974+
--version Show version number [boolean]
975+
--config Path to JSON config file
976+
`
977+
883978
exports[`test/gh.mjs TAP all commands help pending-release merge > must match snapshot 1`] = `
884979
npx -p @npmcli/stafftools gh pending-release merge
885980
@@ -1076,6 +1171,7 @@ npx -p @npmcli/stafftools gh pull-requests
10761171
Fetch pull requests
10771172
10781173
Commands:
1174+
npx -p @npmcli/stafftools gh pull-requests comment Comment on pull requests
10791175
npx -p @npmcli/stafftools gh pull-requests merge Merge pull requests
10801176
npx -p @npmcli/stafftools gh pull-requests pr-engines Get engine changes in a pull request
10811177
npx -p @npmcli/stafftools gh pull-requests remove-label Remove a label from pull requests
@@ -1107,6 +1203,37 @@ Other Options:
11071203
--config Path to JSON config file
11081204
`
11091205

1206+
exports[`test/gh.mjs TAP all commands help pull-requests comment > must match snapshot 1`] = `
1207+
npx -p @npmcli/stafftools gh pull-requests comment
1208+
1209+
Comment on pull requests
1210+
1211+
Command Options:
1212+
--cache how long for gh to cache the query [string] [default: "1m"]
1213+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1214+
--label label to filter pull requests [string]
1215+
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
1216+
--table shorthand for --template=table [boolean] [default: false]
1217+
--confirm shorthand for --template=confirm [boolean] [default: false]
1218+
--report shorthand for --template=report [boolean] [default: false]
1219+
--body the body to post [string] [default: false]
1220+
1221+
Global Options:
1222+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
1223+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
1224+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
1225+
--clean whether to rimraf the cwd first [boolean] [default: false]
1226+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
1227+
--sort key to sort results by [string] [default: "id"]
1228+
--json shorthand for --template=json [boolean] [default: false]
1229+
--silent shorthand for --template=silent [boolean] [default: false]
1230+
1231+
Other Options:
1232+
--help Show help [boolean]
1233+
--version Show version number [boolean]
1234+
--config Path to JSON config file
1235+
`
1236+
11101237
exports[`test/gh.mjs TAP all commands help pull-requests merge > must match snapshot 1`] = `
11111238
npx -p @npmcli/stafftools gh pull-requests merge
11121239
@@ -1558,6 +1685,7 @@ npx -p @npmcli/stafftools gh template-oss
15581685
Fetch template-oss pull requests
15591686
15601687
Commands:
1688+
npx -p @npmcli/stafftools gh template-oss comment Comment on pull requests
15611689
npx -p @npmcli/stafftools gh template-oss merge Merge pull requests
15621690
npx -p @npmcli/stafftools gh template-oss pr-engines Get engine changes in a pull request
15631691
npx -p @npmcli/stafftools gh template-oss remove-label Remove a label from pull requests
@@ -1588,6 +1716,35 @@ Other Options:
15881716
--config Path to JSON config file
15891717
`
15901718

1719+
exports[`test/gh.mjs TAP all commands help template-oss comment > must match snapshot 1`] = `
1720+
npx -p @npmcli/stafftools gh template-oss comment
1721+
1722+
Comment on pull requests
1723+
1724+
Command Options:
1725+
--cache how long for gh to cache the query [string] [default: "1m"]
1726+
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
1727+
--table shorthand for --template=table [boolean] [default: false]
1728+
--confirm shorthand for --template=confirm [boolean] [default: false]
1729+
--report shorthand for --template=report [boolean] [default: false]
1730+
--body the body to post [string] [default: false]
1731+
1732+
Global Options:
1733+
-c, --cwd base directory to run filesystem related commands [string] [default: null]
1734+
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
1735+
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
1736+
--clean whether to rimraf the cwd first [boolean] [default: false]
1737+
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
1738+
--sort key to sort results by [string] [default: "id"]
1739+
--json shorthand for --template=json [boolean] [default: false]
1740+
--silent shorthand for --template=silent [boolean] [default: false]
1741+
1742+
Other Options:
1743+
--help Show help [boolean]
1744+
--version Show version number [boolean]
1745+
--config Path to JSON config file
1746+
`
1747+
15911748
exports[`test/gh.mjs TAP all commands help template-oss merge > must match snapshot 1`] = `
15921749
npx -p @npmcli/stafftools gh template-oss merge
15931750

0 commit comments

Comments
 (0)