Bulk Remove Labels

gh pr list --label "[Status] Needs Review" --state closed --json number -L 350| jq '.[].number' | xargs -L 1 gh pr edit --remove-label "[Status] Needs Review"

We usually have an automation that removes some labels from a PR once it is merged. I haven’t looked into why that happened, but wanted to bulk remove it without having to use the UI.

This uses the gh cli command, installed via brew install gh on OS X and jq command, installed via brew install jq

First, it requests a list of PRs with the given label, that are closed, outputted in JSON with just the PR number with a limit of up to 350 issues (we had like 330 that were missed).

That pipes it to jq which parses out, in this case, the number field from every json object.

That’s piped to xargs which takes one line per execution and passes it to gh‘s pr edit command to remove that specific label.

Advertisement

One thought on “Bulk Remove Labels

  1. Yes, probably could have a faster method here that gets the result from the API, then passes it up to the API. But, I didn’t want to have to deal with authentication and this should be only a one-off event.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s