Skip to content

Commit 9d7903b

Browse files
committed
Add --user support
1 parent 75be1f1 commit 9d7903b

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ Run with the `--verbose` flag to see debug information
3535

3636
## Options
3737

38-
| Flag | Description | Default |
39-
| ------------- | -------------------------------- | ------- |
40-
| --pat <token> | GitHub API Token | N/A |
41-
| --repo <name> | user/repo | N/A |
42-
| --org <name> | my-org-name | N/A |
43-
| --keep-old | | false |
44-
| --old | The name of the branch to rename | master |
45-
| --new | The new branch name | main |
38+
| Flag | Description | Default |
39+
| ------------- | -------------------------------------------------------------- | ------- |
40+
| --pat <token> | GitHub API Token | N/A |
41+
| --repo <name> | The repo to update (format: user/repo) | N/A |
42+
| --user <name> | Update all repos owned by the provided user (example: my-user) | N/A |
43+
| --org <name> | Update all repos in the provided org (example: my-org-name) | N/A |
44+
| --keep-old | | false |
45+
| --old | The name of the branch to rename | master |
46+
| --new | The new branch name | main |
4647

4748
## Enhancements
4849

bin/github-default-branch

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
const { argv } = require("yargs");
44

55
// Up front validation
6-
if (!argv.org && !argv.repo) {
7-
console.log("❎ You must provide --org or --repo");
6+
const providedRepoSelectors = [argv.org, argv.user, argv.repo].filter(
7+
(v) => v
8+
).length;
9+
10+
if (providedRepoSelectors === 0) {
11+
console.log("❎ You must provide --org, --user or --repo");
812
return;
913
}
1014

11-
if (argv.org && argv.repo) {
12-
console.log("❎ Only --org OR --repo is supported");
15+
if (providedRepoSelectors > 1) {
16+
console.log("❎ Only --org OR --user OR --repo is supported");
1317
return;
1418
}
1519

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/get-repos.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ module.exports = async function (args, octokit) {
33
return [args.repo];
44
}
55

6-
const { data: repos } = await octokit.repos.listForOrg({
7-
org: args.org,
8-
});
6+
let repos;
7+
if (args.org) {
8+
({ data: repos } = await octokit.repos.listForOrg({
9+
org: args.org,
10+
}));
11+
}
12+
13+
if (args.user) {
14+
({ data: repos } = await octokit.repos.listForAuthenticatedUser());
15+
16+
// Filter down to repos owned by the provided user
17+
// This is different to using affiliation: owner as it allows
18+
// the consumer to update repos that they have admin access to
19+
// but do not own
20+
repos = repos.filter((repo) => repo.owner.login == args.user);
21+
}
922

1023
return repos.map((repo) => repo.full_name);
1124
};

0 commit comments

Comments
 (0)