diff --git a/.github/publish.yml b/.github/publish.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.kokoro/continuous/node10/lint.cfg b/.kokoro/continuous/node12/lint.cfg similarity index 100% rename from .kokoro/continuous/node10/lint.cfg rename to .kokoro/continuous/node12/lint.cfg diff --git a/.kokoro/continuous/node10/samples-test.cfg b/.kokoro/continuous/node12/samples-test.cfg similarity index 100% rename from .kokoro/continuous/node10/samples-test.cfg rename to .kokoro/continuous/node12/samples-test.cfg diff --git a/.kokoro/continuous/node10/system-test.cfg b/.kokoro/continuous/node12/system-test.cfg similarity index 100% rename from .kokoro/continuous/node10/system-test.cfg rename to .kokoro/continuous/node12/system-test.cfg diff --git a/.kokoro/presubmit/node10/samples-test.cfg b/.kokoro/presubmit/node12/samples-test.cfg similarity index 100% rename from .kokoro/presubmit/node10/samples-test.cfg rename to .kokoro/presubmit/node12/samples-test.cfg diff --git a/.kokoro/presubmit/node10/system-test.cfg b/.kokoro/presubmit/node12/system-test.cfg similarity index 100% rename from .kokoro/presubmit/node10/system-test.cfg rename to .kokoro/presubmit/node12/system-test.cfg diff --git a/.kokoro/release/docs-devsite.sh b/.kokoro/release/docs-devsite.sh index 3b93137..fa089cf 100755 --- a/.kokoro/release/docs-devsite.sh +++ b/.kokoro/release/docs-devsite.sh @@ -36,6 +36,11 @@ NAME=$(cat .repo-metadata.json | json name) mkdir ./_devsite cp ./yaml/$NAME/* ./_devsite + +# Delete SharePoint item, see https://github.com/microsoft/rushstack/issues/1229 +sed -i -e '1,3d' ./yaml/toc.yml +sed -i -e 's/^ //' ./yaml/toc.yml + cp ./yaml/toc.yml ./_devsite/toc.yml # create docs.metadata, based on package.json and .repo-metadata.json. diff --git a/.kokoro/release/publish.cfg b/.kokoro/release/publish.cfg index d4600c6..37f07b6 100644 --- a/.kokoro/release/publish.cfg +++ b/.kokoro/release/publish.cfg @@ -49,7 +49,7 @@ before_action { env_vars: { key: "SECRET_MANAGER_KEYS" - value: "npm_publish_token" + value: "npm_publish_token,releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } # Download trampoline resources. @@ -61,7 +61,7 @@ build_file: "github-repo-automation/.kokoro/trampoline.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:8-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user" } env_vars: { diff --git a/.kokoro/samples-test.sh b/.kokoro/samples-test.sh index 86e83c9..c0c4013 100755 --- a/.kokoro/samples-test.sh +++ b/.kokoro/samples-test.sh @@ -41,7 +41,7 @@ if [ -f samples/package.json ]; then cd .. # If tests are running against master, configure Build Cop # to open issues on failures: - if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then + if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]] || [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"nightly"* ]]; then export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml export MOCHA_REPORTER=xunit cleanup() { diff --git a/.kokoro/system-test.sh b/.kokoro/system-test.sh index dfae142..283f170 100755 --- a/.kokoro/system-test.sh +++ b/.kokoro/system-test.sh @@ -35,7 +35,7 @@ npm install # If tests are running against master, configure Build Cop # to open issues on failures: -if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then +if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]] || [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"nightly"* ]]; then export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml export MOCHA_REPORTER=xunit cleanup() { diff --git a/.kokoro/test.sh b/.kokoro/test.sh index 8d9c295..47be59b 100755 --- a/.kokoro/test.sh +++ b/.kokoro/test.sh @@ -23,7 +23,7 @@ cd $(dirname $0)/.. npm install # If tests are running against master, configure Build Cop # to open issues on failures: -if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then +if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]] || [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"nightly"* ]]; then export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml export MOCHA_REPORTER=xunit cleanup() { diff --git a/CHANGELOG.md b/CHANGELOG.md index b6f4802..5124780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ [1]: https://www.npmjs.com/package/@google/repo?activeTab=versions +## [4.2.0](https://www.github.com/googleapis/github-repo-automation/compare/v4.1.0...v4.2.0) (2020-08-28) + + +### Features + +* add functionality to remove labels ([#454](https://www.github.com/googleapis/github-repo-automation/issues/454)) ([2cb06b7](https://www.github.com/googleapis/github-repo-automation/commit/2cb06b7174e89aea6d4bbecac7638990afd97c16)) + ## [4.1.0](https://www.github.com/googleapis/github-repo-automation/compare/v4.0.2...v4.1.0) (2020-08-11) diff --git a/package.json b/package.json index 4c425de..411fa57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@google/repo", - "version": "4.1.0", + "version": "4.2.0", "repository": "googleapis/github-repo-automation", "description": "A tool for automating multiple GitHub repositories.", "engines": { diff --git a/samples/package.json b/samples/package.json index cb437ba..5414a1f 100644 --- a/samples/package.json +++ b/samples/package.json @@ -14,7 +14,7 @@ "test": "mocha system-test" }, "dependencies": { - "@google/repo": "^4.1.0" + "@google/repo": "^4.2.0" }, "devDependencies": { "mocha": "^8.0.0" diff --git a/src/cli.ts b/src/cli.ts index fbe5c87..344f506 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -27,6 +27,7 @@ import {sync, exec} from './sync'; import * as meow from 'meow'; import * as updateNotifier from 'update-notifier'; import {tag} from './tag-prs'; +import {untag} from './untag-prs'; /* eslint-disable @typescript-eslint/no-var-requires */ const pkg = require('../../package.json'); @@ -81,6 +82,7 @@ const cli = meow( $ 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 untag [--branch branch] [--author author] [--title title] label1 $ repo apply --branch branch --message message --comment comment [--reviewers username[,username...]] [--silent] command $ repo check $ repo sync @@ -120,6 +122,9 @@ switch (cli.input[0]) { case 'apply': p = apply(cli); break; + case 'untag': + p = untag(cli); + break; case 'tag': p = tag(cli); break; diff --git a/src/lib/github.ts b/src/lib/github.ts index 354129d..e5be43b 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -503,6 +503,24 @@ export class GitHubRepository { return result.data; } + /** + * Removes label with a given name to a given pull request. + * @param {Object} pr Pull request object, as returned by GitHib API. + * @param {Array} labels Labels to apply to the PR + * @returns A list of labels that was added to the issue.. + */ + async unTagPullRequest(pr: PullRequest, name: string) { + const owner = this.repository.owner.login; + const repo = this.repository.name; + const url = `/repos/${owner}/${repo}/issues/${pr.number}/labels/${name}`; + const result = await this.client.request({ + url, + method: 'DELETE', + data: {name}, + }); + return result.data; + } + /** * Closes the given pull request without merging it. * @param {Object} pr Pull request object, as returned by GitHub API. diff --git a/src/untag-prs.ts b/src/untag-prs.ts new file mode 100644 index 0000000..bcb7745 --- /dev/null +++ b/src/untag-prs.ts @@ -0,0 +1,46 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import * as meow from 'meow'; +import {meowFlags} from './cli'; + +import {GitHubRepository, PullRequest} from './lib/github'; +import {processPRs} from './lib/asyncItemIterator'; + +let name: string; + +async function processMethod(repository: GitHubRepository, pr: PullRequest) { + try { + await repository.unTagPullRequest(pr, name); + } catch (err) { + console.warn( + ` error trying to untag PR ${pr.html_url}:`, + err.toString() + ); + return false; + } + return true; +} + +export async function untag(cli: meow.Result) { + name = cli.input[1]; + return processPRs(cli, { + commandName: 'untag', + commandActive: 'untagging', + commandNamePastTense: 'untagged', + commandDesc: + 'Will remove label(s) to all open PRs with title matching regex.', + processMethod, + }); +} diff --git a/synth.metadata b/synth.metadata index 2a019c7..f1b4acc 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,65 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/github-repo-automation.git", - "sha": "3b5f955b24722fa883e6d5b423da3f11217be64a" + "sha": "ad7eac25d74add9b7b0c856e25578bf6bb68fc9f" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "94421c47802f56a44c320257b2b4c190dc7d6b68" + "sha": "8cf6d2834ad14318e64429c3b94f6443ae83daf9" } } + ], + "generatedFiles": [ + ".eslintignore", + ".eslintrc.json", + ".gitattributes", + ".github/ISSUE_TEMPLATE/bug_report.md", + ".github/ISSUE_TEMPLATE/feature_request.md", + ".github/ISSUE_TEMPLATE/support_request.md", + ".github/PULL_REQUEST_TEMPLATE.md", + ".github/release-please.yml", + ".github/workflows/ci.yaml", + ".kokoro/.gitattributes", + ".kokoro/common.cfg", + ".kokoro/continuous/node10/common.cfg", + ".kokoro/continuous/node10/docs.cfg", + ".kokoro/continuous/node10/test.cfg", + ".kokoro/continuous/node12/common.cfg", + ".kokoro/continuous/node12/lint.cfg", + ".kokoro/continuous/node12/samples-test.cfg", + ".kokoro/continuous/node12/system-test.cfg", + ".kokoro/continuous/node12/test.cfg", + ".kokoro/docs.sh", + ".kokoro/lint.sh", + ".kokoro/populate-secrets.sh", + ".kokoro/presubmit/node10/common.cfg", + ".kokoro/presubmit/node12/common.cfg", + ".kokoro/presubmit/node12/samples-test.cfg", + ".kokoro/presubmit/node12/system-test.cfg", + ".kokoro/presubmit/node12/test.cfg", + ".kokoro/publish.sh", + ".kokoro/release/docs-devsite.cfg", + ".kokoro/release/docs-devsite.sh", + ".kokoro/release/docs.cfg", + ".kokoro/release/docs.sh", + ".kokoro/release/publish.cfg", + ".kokoro/samples-test.sh", + ".kokoro/system-test.sh", + ".kokoro/test.bat", + ".kokoro/test.sh", + ".kokoro/trampoline.sh", + ".mocharc.js", + ".nycrc", + ".prettierignore", + ".prettierrc.js", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE", + "api-extractor.json", + "renovate.json", + "samples/README.md" ] } \ No newline at end of file