diff --git a/README.md b/README.md index 30d5bec..1fbdc5c 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,11 @@ Now you are good to go! ### repo approve ```sh -$ repo approve [regex] +$ repo approve [--title title] ``` -Iterates over all open pull requests matching `regex` (all PRs if -no regex is given) in all configured repositories. +Iterates over all open pull requests matching `title` (this can be a regex, +and all PRs will be processed if no regex for title is given) in all configured repositories. For each pull request, asks (in console) if it should be approved and merged. Useful for managing GreenKeeper's PRs: @@ -78,36 +78,39 @@ or all PRs with the word `test` in the title: ### repo list ```sh -$ repo list [regex] +$ repo list [--title title] ``` -Iterates over all open pull requests matching `regex` (all PRs if -no regex is given) in all configured repositories, and prints them. +Iterates over all open pull requests matching `title` (this can be a regex, +and all PRs will be processed if no regex for title is given) +in all configured repositories, and prints them. -`$ repo list 🚀` +`$ repo list --title 🚀` or all PRs with the word `test` in the title: -`$ repo list test` +`$ repo list --title test` ### repo reject ```sh -$ repo reject [regex] +$ repo reject [--title title] ``` -Iterates over all open pull requests matching `regex`, and closes +Iterates over all open pull requests matching `title` (this can be a regex, +and all PRs will be processed if no regex for title is given) and closes them. For example, close all PRs with the word `test` in the title: -`$ repo reject test` +`$ repo reject --title test` ### repo rename ```sh -$ repo rename 'title to match' 'new title' +$ repo rename --title title 'new title' ``` -Iterates over all open pull requests matching `regex`, and renames +Iterates over all open pull requests matching `title` (this can be a regex, +and all PRs will be processed if no regex for title is given), and renames them. ### repo apply diff --git a/src/cli.ts b/src/cli.ts index 933188e..fe5555a 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -54,6 +54,10 @@ export const meowFlags: { type: 'boolean', alias: 'q', }, + title: { + type: 'string', + alias: 't', + }, auto: {type: 'boolean'}, concurrency: {type: 'string'}, author: {type: 'string'}, @@ -68,13 +72,13 @@ const cli = meow( $ repo Examples - $ repo list [--branch branch] [--author author] [regex] - $ repo approve [--branch branch] [--author author] [regex] - $ repo update [--branch branch] [--author author] [regex] - $ repo merge [--branch branch] [--author author] [regex] - $ repo reject [--branch branch] [--author author] [regex] - $ repo rename [--branch branch] [--author author] regex 'new PR title' - $ repo tag [--branch branch] [--author author] regex label1 label2 ... + $ repo list [--branch branch] [--author author] [--title title] + $ repo approve [--branch branch] [--author author] [--title title] + $ repo update [--branch branch] [--author author] [--title title] + $ repo merge [--branch branch] [--author author] [--title title] + $ repo reject [--branch branch] [--author author] [--title title] + $ repo rename [--branch branch] [--author author] [--title title] 'new PR title' + $ repo tag [--branch branch] [--author author] [--title title] label1 label2 ... $ repo apply --branch branch --message message --comment comment [--reviewers username[,username...]] [--silent] command $ repo check $ repo sync diff --git a/src/lib/asyncPrIterator.ts b/src/lib/asyncPrIterator.ts index 3ecb1e6..b66d524 100644 --- a/src/lib/asyncPrIterator.ts +++ b/src/lib/asyncPrIterator.ts @@ -42,9 +42,11 @@ export async function process( cli: meow.Result, options: PRIteratorOptions ) { - if (!cli.input[1] && !cli.flags.branch) { - console.log(`Usage: repo ${options.commandName} [--branch branch] [regex]`); - console.log(`Either branch name or regex must present.`); + if (!cli.flags.title && !cli.flags.branch) { + console.log( + `Usage: repo ${options.commandName} [--branch branch] [--title title]` + ); + console.log(`Either branch name or title regex must present.`); console.log(options.commandDesc); return; } @@ -54,7 +56,7 @@ export async function process( : 15; const config = await getConfig(); const github = new GitHub(config); - const regex = new RegExp(cli.input[1] || '.*'); + const regex = new RegExp((cli.flags.title as string) || '.*'); const repos = await github.getRepositories(); const successful: PullRequest[] = []; const failed: PullRequest[] = []; diff --git a/src/rename-prs.ts b/src/rename-prs.ts index fd4a286..71cca72 100644 --- a/src/rename-prs.ts +++ b/src/rename-prs.ts @@ -26,7 +26,11 @@ async function processMethod(repository: GitHubRepository, pr: PullRequest) { } export async function rename(cli: meow.Result) { - title = cli.input[2]; + if (cli.input.length < 2) { + console.log(`New title name must present.`); + return; + } + title = cli.input[1]; console.log(`title: ${title}`); return process(cli, { commandName: 'rename', diff --git a/src/tag-prs.ts b/src/tag-prs.ts index 1b694b7..4eab626 100644 --- a/src/tag-prs.ts +++ b/src/tag-prs.ts @@ -24,7 +24,7 @@ async function processMethod( cli: meow.Result ) { try { - await repository.tagPullRequest(pr, cli.input.slice(2)); + await repository.tagPullRequest(pr, cli.input.slice(1)); } catch (err) { console.warn(` error trying to tag PR ${pr.html_url}:`, err.toString()); return false;