Skip to content

Commit 6ff3b4e

Browse files
committed
repos -r option for specific repos, closes #42
1 parent 78b2dc8 commit 6ff3b4e

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ You can pass more than one username to fetch for multiple users or organizations
9191

9292
$ github-to-sqlite repos github.db simonw dogsheep
9393

94+
## Fetching specific repositories
95+
96+
You can use `-r` with the `repos` command one or more times to fetch just specific repositories.
97+
98+
$ github-to-sqlite repos github.db -r simonw/datasette -r dogsheep/github-to-sqlite
99+
94100
## Fetching repos that have been starred by a user
95101

96102
The `starred` command fetches the repos that have been starred by a user.

github_to_sqlite/cli.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,35 @@ def stargazers(db_path, repos, auth):
172172
default="auth.json",
173173
help="Path to auth.json token file",
174174
)
175+
@click.option(
176+
"-r",
177+
"--repo",
178+
multiple=True,
179+
help="Just fetch these repos",
180+
)
175181
@click.option(
176182
"--load",
177183
type=click.Path(file_okay=True, dir_okay=False, allow_dash=True, exists=True),
178184
help="Load issues JSON from this file instead of the API",
179185
)
180-
def repos(db_path, usernames, auth, load):
186+
def repos(db_path, usernames, auth, repo, load):
181187
"Save repos owened by the specified (or authenticated) username or organization"
182188
db = sqlite_utils.Database(db_path)
183189
token = load_token(auth)
184190
if load:
185-
for repo in json.load(open(load)):
186-
utils.save_repo(db, repo)
191+
for loaded_repo in json.load(open(load)):
192+
utils.save_repo(db, loaded_repo)
187193
else:
188-
if not usernames:
189-
usernames = [None]
190-
for username in usernames:
191-
for repo in utils.fetch_all_repos(username, token):
192-
utils.save_repo(db, repo)
194+
if repo:
195+
# Just these repos
196+
for full_name in repo:
197+
utils.save_repo(db, utils.fetch_repo(full_name, token))
198+
else:
199+
if not usernames:
200+
usernames = [None]
201+
for username in usernames:
202+
for repo in utils.fetch_all_repos(username, token):
203+
utils.save_repo(db, repo)
193204
utils.ensure_db_shape(db)
194205

195206

0 commit comments

Comments
 (0)