Skip to content

Commit

Permalink
repos -r option for specific repos, closes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jul 9, 2020
1 parent 78b2dc8 commit 6ff3b4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ You can pass more than one username to fetch for multiple users or organizations

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

## Fetching specific repositories

You can use `-r` with the `repos` command one or more times to fetch just specific repositories.

$ github-to-sqlite repos github.db -r simonw/datasette -r dogsheep/github-to-sqlite

## Fetching repos that have been starred by a user

The `starred` command fetches the repos that have been starred by a user.
Expand Down
27 changes: 19 additions & 8 deletions github_to_sqlite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,35 @@ def stargazers(db_path, repos, auth):
default="auth.json",
help="Path to auth.json token file",
)
@click.option(
"-r",
"--repo",
multiple=True,
help="Just fetch these repos",
)
@click.option(
"--load",
type=click.Path(file_okay=True, dir_okay=False, allow_dash=True, exists=True),
help="Load issues JSON from this file instead of the API",
)
def repos(db_path, usernames, auth, load):
def repos(db_path, usernames, auth, repo, load):
"Save repos owened by the specified (or authenticated) username or organization"
db = sqlite_utils.Database(db_path)
token = load_token(auth)
if load:
for repo in json.load(open(load)):
utils.save_repo(db, repo)
for loaded_repo in json.load(open(load)):
utils.save_repo(db, loaded_repo)
else:
if not usernames:
usernames = [None]
for username in usernames:
for repo in utils.fetch_all_repos(username, token):
utils.save_repo(db, repo)
if repo:
# Just these repos
for full_name in repo:
utils.save_repo(db, utils.fetch_repo(full_name, token))
else:
if not usernames:
usernames = [None]
for username in usernames:
for repo in utils.fetch_all_repos(username, token):
utils.save_repo(db, repo)
utils.ensure_db_shape(db)


Expand Down

0 comments on commit 6ff3b4e

Please sign in to comment.