Skip to content

Commit

Permalink
make it possible to update all repos of a single team in an organization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marcohutzsch1234 committed Oct 21, 2020
1 parent f889d0f commit 5152434
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@ Run with the `--verbose` flag to see debug information

## Options

| Flag | Description | Default |
| ------------------------------- | -------------------------------------------------------------- | ------- |
| --pat <token> | GitHub API Token | N/A |
| --repo <name> | The repo to update (format: user/repo) | N/A |
| --user <name> | Update all repos owned by the provided user (example: my-user) | N/A |
| --org <name> | 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 <token> | GitHub API Token | N/A |
| --repo <name> | The repo to update (format: user/repo) | N/A |
| --user <name> | Update all repos owned by the provided user (example: my-user) | N/A |
| --org <name> | Update all repos in the provided org (example: my-org-name) | N/A |
| --team <name> | 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

Expand Down
5 changes: 5 additions & 0 deletions bin/github-default-branch
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion src/get-repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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,
Expand Down

0 comments on commit 5152434

Please sign in to comment.