From 5152434b1f574cc19cc728cee7c84a0f32b78473 Mon Sep 17 00:00:00 2001 From: Marco Hutzsch Date: Thu, 15 Oct 2020 07:36:43 +0200 Subject: [PATCH] make it possible to update all repos of a single team in an organization If parameters org and team are provided all repos an existing team are being looked up and updated. There is no functional change on the existing org or user parameters. --- README.md | 29 +++++++++++++++-------------- bin/github-default-branch | 5 +++++ src/get-repos.js | 14 +++++++++++++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e2bb8cf..5d24936 100644 --- a/README.md +++ b/README.md @@ -53,20 +53,21 @@ Run with the `--verbose` flag to see debug information ## Options -| Flag | Description | Default | -| ------------------------------- | -------------------------------------------------------------- | ------- | -| --pat | GitHub API Token | N/A | -| --repo | The repo to update (format: user/repo) | N/A | -| --user | Update all repos owned by the provided user (example: my-user) | N/A | -| --org | Update all repos in the provided org (example: my-org-name) | N/A | -| --keep-old | Keep the old branch rather than deleting it | false | -| --dry-run | Output log messages only. Do not make any changes | false | -| --list-repos-only | List repos that would be affected, then exit | false | -| --skip-forks | Skips forked repositories | false | -| --skip-update-branch-protection | Skip updating branch protections | false | -| --old | The name of the branch to rename | master | -| --new | The new branch name | main | -| --confirm | Run without prompting for confirmation | false | +| Flag | Description | Default | +| ------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ------- | +| --pat | GitHub API Token | N/A | +| --repo | The repo to update (format: user/repo) | N/A | +| --user | Update all repos owned by the provided user (example: my-user) | N/A | +| --org | Update all repos in the provided org (example: my-org-name) | N/A | +| --team | Update all repos in the provided team (example: my-team-name), only usable in combination with org parameter | N/A | +| --keep-old | Keep the old branch rather than deleting it | false | +| --dry-run | Output log messages only. Do not make any changes | false | +| --list-repos-only | List repos that would be affected, then exit | false | +| --skip-forks | Skips forked repositories | false | +| --skip-update-branch-protection | Skip updating branch protections | false | +| --old | The name of the branch to rename | master | +| --new | The new branch name | main | +| --confirm | Run without prompting for confirmation | false | ## Replacements diff --git a/bin/github-default-branch b/bin/github-default-branch index 90d32ac..b787c9a 100755 --- a/bin/github-default-branch +++ b/bin/github-default-branch @@ -17,6 +17,11 @@ description: "Update all repos in the provided org (example: my-org-name)", }, + team: { + type: "string", + description: + "Update all repos in the provided team (example: my-team-name), only usable in combination with org parameter", + }, "keep-old": { type: "boolean", default: false, diff --git a/src/get-repos.js b/src/get-repos.js index 94714a6..c6864eb 100644 --- a/src/get-repos.js +++ b/src/get-repos.js @@ -4,7 +4,7 @@ module.exports = async function (args, octokit) { } let repos = []; - if (args.org) { + if (args.org && !args.team) { repos = await octokit.paginate( octokit.repos.listForOrg, { @@ -15,6 +15,18 @@ module.exports = async function (args, octokit) { ); } + if (args.org && args.team) { + repos = await octokit.paginate( + octokit.teams.listReposInOrg, + { + org: args.org, + team_slug: args.team, + per_page: 100 + }, + (response) => response.data + ); + } + if (args.user) { repos = await octokit.paginate( octokit.repos.listForAuthenticatedUser,