Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add worker to comment on a PR #123

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/gh/workers/comment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { OPEN_PR } from '../types.mjs'
import { apiOnlyOptions } from '../yargs/utils.mjs'

export const type = OPEN_PR

export const filter = []

export const args = {
desc: 'Comment on pull requests',
builder: (yargs) =>
yargs.options({
body: {
default: false,
desc: 'the body to post',
type: 'string',
},
...apiOnlyOptions(),
}),
}

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

export default [
({ item, argv }) => [
'gh',
[
'pr',
'comment',
item.number,
`--repo='${item.nameWithOwner}'`,
'--body',
`'${argv.body}'`,
],
],
]
157 changes: 157 additions & 0 deletions tap-snapshots/test/gh.mjs.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gh
gh closed-pending-release
gh closed-pending-release remove-label
gh dependabot
gh dependabot comment
gh dependabot merge
gh dependabot pr-engines
gh dependabot remove-label
Expand All @@ -18,6 +19,7 @@ gh dependabot review
gh graphql
gh graphql add-template-oss
gh graphql clone
gh graphql comment
gh graphql delete-branches
gh graphql merge
gh graphql pr-engines
Expand All @@ -32,13 +34,15 @@ gh graphql set-secret
gh graphql template-oss-fix
gh labels
gh pending-release
gh pending-release comment
gh pending-release merge
gh pending-release pr-engines
gh pending-release publish-release
gh pending-release remove-label
gh pending-release rerun-failed-workflows
gh pending-release review
gh pull-requests
gh pull-requests comment
gh pull-requests merge
gh pull-requests pr-engines
gh pull-requests remove-label
Expand All @@ -53,6 +57,7 @@ gh repos pull
gh repos repo-settings
gh repos set-secret
gh template-oss
gh template-oss comment
gh template-oss merge
gh template-oss pr-engines
gh template-oss remove-label
Expand Down Expand Up @@ -163,6 +168,7 @@ npx -p @npmcli/stafftools gh dependabot
Fetch dependabot pull requests

Commands:
npx -p @npmcli/stafftools gh dependabot comment Comment on pull requests
npx -p @npmcli/stafftools gh dependabot merge Merge pull requests
npx -p @npmcli/stafftools gh dependabot pr-engines Get engine changes in a pull request
npx -p @npmcli/stafftools gh dependabot remove-label Remove a label from pull requests
Expand Down Expand Up @@ -192,6 +198,35 @@ Other Options:
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help dependabot comment > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh dependabot comment

Comment on pull requests

Command Options:
--cache how long for gh to cache the query [string] [default: "1m"]
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
--table shorthand for --template=table [boolean] [default: false]
--confirm shorthand for --template=confirm [boolean] [default: false]
--report shorthand for --template=report [boolean] [default: false]
--body the body to post [string] [default: false]

Global Options:
-c, --cwd base directory to run filesystem related commands [string] [default: null]
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
--clean whether to rimraf the cwd first [boolean] [default: false]
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
--sort key to sort results by [string] [default: "id"]
--json shorthand for --template=json [boolean] [default: false]
--silent shorthand for --template=silent [boolean] [default: false]

Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help dependabot merge > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh dependabot merge

Expand Down Expand Up @@ -347,6 +382,7 @@ Fetch a graphql query
Commands:
npx -p @npmcli/stafftools gh graphql add-template-oss Add template-oss to a repo
npx -p @npmcli/stafftools gh graphql clone Clone repos into a directory
npx -p @npmcli/stafftools gh graphql comment Comment on pull requests
npx -p @npmcli/stafftools gh graphql delete-branches Delete branches of repos with no remote counterpart
npx -p @npmcli/stafftools gh graphql merge Merge pull requests
npx -p @npmcli/stafftools gh graphql pr-engines Get engine changes in a pull request
Expand Down Expand Up @@ -442,6 +478,33 @@ Other Options:
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help graphql comment > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh graphql comment

Comment on pull requests

Command Options:
--query path to a query file passed directly to gh api graphql [string] [required]
--cache how long for gh to cache the query [string] [default: "1m"]
--report shorthand for --template=report [boolean] [default: false]
--body the body to post [string] [default: false]

Global Options:
-c, --cwd base directory to run filesystem related commands [string] [default: null]
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
--clean whether to rimraf the cwd first [boolean] [default: false]
--template how to format the final output [string] [required] [choices: "json", "silent", "report"] [default: "report"]
--sort key to sort results by [string] [default: "id"]
--json shorthand for --template=json [boolean] [default: false]
--silent shorthand for --template=silent [boolean] [default: false]

Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help graphql delete-branches > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh graphql delete-branches

Expand Down Expand Up @@ -820,6 +883,7 @@ npx -p @npmcli/stafftools gh pending-release
Fetch pending release pull requests

Commands:
npx -p @npmcli/stafftools gh pending-release comment Comment on pull requests
npx -p @npmcli/stafftools gh pending-release merge Merge pull requests
npx -p @npmcli/stafftools gh pending-release pr-engines Get engine changes in a pull request
npx -p @npmcli/stafftools gh pending-release publish-release Merge pending release PRs and publish the resulting release
Expand Down Expand Up @@ -852,6 +916,37 @@ Other Options:
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help pending-release comment > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh pending-release comment

Comment on pull requests

Command Options:
--cache how long for gh to cache the query [string] [default: "1m"]
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
--noDeps Only return items that do not depend on any other items returned [boolean] [default: false]
--depsPrs Only return items that have no open deps PRs [string] [choices: "", "none", "any"] [default: ""]
--table shorthand for --template=table [boolean] [default: false]
--confirm shorthand for --template=confirm [boolean] [default: false]
--report shorthand for --template=report [boolean] [default: false]
--body the body to post [string] [default: false]

Global Options:
-c, --cwd base directory to run filesystem related commands [string] [default: null]
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
--clean whether to rimraf the cwd first [boolean] [default: false]
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
--sort key to sort results by [string] [default: "id"]
--json shorthand for --template=json [boolean] [default: false]
--silent shorthand for --template=silent [boolean] [default: false]

Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help pending-release merge > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh pending-release merge

Expand Down Expand Up @@ -1048,6 +1143,7 @@ npx -p @npmcli/stafftools gh pull-requests
Fetch pull requests

Commands:
npx -p @npmcli/stafftools gh pull-requests comment Comment on pull requests
npx -p @npmcli/stafftools gh pull-requests merge Merge pull requests
npx -p @npmcli/stafftools gh pull-requests pr-engines Get engine changes in a pull request
npx -p @npmcli/stafftools gh pull-requests remove-label Remove a label from pull requests
Expand Down Expand Up @@ -1079,6 +1175,37 @@ Other Options:
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help pull-requests comment > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh pull-requests comment

Comment on pull requests

Command Options:
--cache how long for gh to cache the query [string] [default: "1m"]
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
--label label to filter pull requests [string]
--state state to filter pull requests [string] [choices: "CLOSED", "MERGED", "OPEN"] [default: "OPEN"]
--table shorthand for --template=table [boolean] [default: false]
--confirm shorthand for --template=confirm [boolean] [default: false]
--report shorthand for --template=report [boolean] [default: false]
--body the body to post [string] [default: false]

Global Options:
-c, --cwd base directory to run filesystem related commands [string] [default: null]
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
--clean whether to rimraf the cwd first [boolean] [default: false]
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
--sort key to sort results by [string] [default: "id"]
--json shorthand for --template=json [boolean] [default: false]
--silent shorthand for --template=silent [boolean] [default: false]

Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help pull-requests merge > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh pull-requests merge

Expand Down Expand Up @@ -1502,6 +1629,7 @@ npx -p @npmcli/stafftools gh template-oss
Fetch template-oss pull requests

Commands:
npx -p @npmcli/stafftools gh template-oss comment Comment on pull requests
npx -p @npmcli/stafftools gh template-oss merge Merge pull requests
npx -p @npmcli/stafftools gh template-oss pr-engines Get engine changes in a pull request
npx -p @npmcli/stafftools gh template-oss remove-label Remove a label from pull requests
Expand Down Expand Up @@ -1532,6 +1660,35 @@ Other Options:
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help template-oss comment > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh template-oss comment

Comment on pull requests

Command Options:
--cache how long for gh to cache the query [string] [default: "1m"]
--repos query to filter repos [string] [required] [default: "org:npm topic:npm-cli fork:true archived:false"]
--table shorthand for --template=table [boolean] [default: false]
--confirm shorthand for --template=confirm [boolean] [default: false]
--report shorthand for --template=report [boolean] [default: false]
--body the body to post [string] [default: false]

Global Options:
-c, --cwd base directory to run filesystem related commands [string] [default: null]
-f, --filter filters to be parsed as relaxed json and applied to the data [array]
-r, --reject rejectors to be parsed as relaxed json and applied to the data [array]
--clean whether to rimraf the cwd first [boolean] [default: false]
--template how to format the final output [string] [required] [choices: "json", "silent", "table", "confirm", "report"] [default: "report"]
--sort key to sort results by [string] [default: "id"]
--json shorthand for --template=json [boolean] [default: false]
--silent shorthand for --template=silent [boolean] [default: false]

Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--config Path to JSON config file
`

exports[`test/gh.mjs TAP all commands help template-oss merge > must match snapshot 1`] = `
npx -p @npmcli/stafftools gh template-oss merge

Expand Down
Loading