Skip to content

Commit d909f48

Browse files
committed
feat: add flag to ingore public, private or forked repos
1 parent 8271451 commit d909f48

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ npx octoherd-script-get-files \
2727

2828
## Options
2929

30-
| option | type | description |
31-
| --------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
32-
| `--source` | string | **Required.** File to download. This can also be a Glob see [example](#examples). |
33-
| `--output` | string | **Required.** Specify a path to place the downloaded file or directory (instead of using the current working directory). Directories specified in the path will be created by this command. |
34-
| `--ignore-archived` or `--no-ignore-archived` | boolean | Default `true`. Ignores archive repositories |
35-
| `--octoherd-token`, `-T` | string | A personal access token ([create](https://github.com/settings/tokens/new?scopes=repo)). Script will create one if option is not set |
36-
| `--octoherd-repos`, `-R` | array of strings | One or multiple space-separated repositories in the form of `repo-owner/repo-name`. `repo-owner/*` will find all repositories for one owner. `*` will find all repositories the user has access to. Will prompt for repositories if not set |
37-
| `--octoherd-bypass-confirms` | boolean | Bypass prompts to confirm mutating requests |
30+
| option | type| description|
31+
| --- | --- | --- |
32+
| `--source` | string | **Required.** File to download. This can also be a Glob see [example](#examples).|
33+
| `--output` | string | **Required.** Specify a path to place the downloaded file or directory (instead of using the current working directory). Directories specified in the path will be created by this command. |
34+
| `--ignore-archived` or `--no-ignore-archived` | boolean | Default `true`. Ignores archive repositories|
35+
| `--ignore-forks` or `--no-ignore-forks` | boolean | Default `true`. Ignores forked repositories|
36+
| `--ignore-public` or `--no-ignore-public` | boolean | Default `false`. Ignores public repositories|
37+
| `--ignore-private` or `--no-ignore-private` | boolean | Default `false`. Ignores private repositories|
38+
| `--octoherd-token`, `-T`| string | A personal access token ([create](https://github.com/settings/tokens/new?scopes=repo)). Script will create one if option is not set|
39+
| `--octoherd-repos`, `-R` | array of strings | One or multiple space-separated repositories in the form of `repo-owner/repo-name`. `repo-owner/*` will find all repositories for one owner. `*` will find all repositories the user has access to. Will prompt for repositories if not set |
40+
| `--octoherd-bypass-confirms` | boolean | Bypass prompts to confirm mutating requests|
3841

3942
## Examples
4043

script.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ let hasRepoScope;
1313
* @param {import('@octoherd/cli').Repository} repository
1414
* @param {object} options
1515
* @param {boolean} [options.ignoreArchived] Ignores archive repositories
16+
* @param {boolean} [options.ignoreForks] Ignores forks repositories
17+
* @param {boolean} [options.ignorePublic] Ignores public repositories
18+
* @param {boolean} [options.ignorePrivate] Ignores private repositories
1619
* @param {string} options.source Path to the destination directory
1720
* @param {string} options.output File path to download. Note: Directories are not supported yet
1821
*/
19-
export async function script(octokit, repository, { source, output = process.cwd(), ignoreArchived = true }) {
22+
export async function script(octokit, repository, { source, output = process.cwd(), ignoreArchived = true, ignoreForks = true, ignorePublic = false, ignorePrivate = false }) {
2023
if (!hasRepoScope) {
2124
const { headers } = await octokit.request("HEAD /");
2225
const scopes = new Set(headers["x-oauth-scopes"].split(", "));
@@ -34,6 +37,21 @@ export async function script(octokit, repository, { source, output = process.cwd
3437
return;
3538
}
3639

40+
if (ignoreForks && repository.fork) {
41+
octokit.log.warn(`IGNORE repository is a fork`);
42+
return;
43+
}
44+
45+
if (ignorePublic && !repository.private) {
46+
octokit.log.warn(`IGNORE repository is public`);
47+
return;
48+
}
49+
50+
if (ignorePrivate && repository.private) {
51+
octokit.log.warn(`IGNORE repository is private`);
52+
return;
53+
}
54+
3755
if (!source) {
3856
octokit.log.error('Please specify a source file to download with --source=README.md')
3957
process.exit(1);

0 commit comments

Comments
 (0)