Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support private repos for organizations #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions github_to_sqlite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ def stargazers(db_path, repos, auth):
type=click.Path(file_okay=True, dir_okay=False, allow_dash=True, exists=True),
help="Load repos JSON from this file instead of the API",
)
@click.option(
"--org",
"orgs",
help="Fetch all pull requests from this GitHub organization",
multiple=True,
)
@click.option(
"--readme",
is_flag=True,
Expand All @@ -278,7 +284,7 @@ def stargazers(db_path, repos, auth):
is_flag=True,
help="Fetch HTML rendered README into 'readme_html' column",
)
def repos(db_path, usernames, auth, repo, load, readme, readme_html):
def repos(db_path, usernames, auth, repo, load, orgs, readme, readme_html):
"Save repos owned by the specified (or authenticated) username or organization"
db = sqlite_utils.Database(db_path)
token = load_token(auth)
Expand All @@ -292,14 +298,20 @@ def repos(db_path, usernames, auth, repo, load, readme, readme_html):
repo_id = utils.save_repo(db, utils.fetch_repo(full_name, token))
_repo_readme(db, token, repo_id, full_name, readme, readme_html)
else:
if not usernames:
repo_lists = []
if orgs:
repo_lists.extend(utils.fetch_all_repos(None, token, org) for org in orgs)
elif not usernames:
# if an org was specified, don't fetch the current user's repos
usernames = [None]
for username in usernames:
for repo in utils.fetch_all_repos(username, token):
repo_id = utils.save_repo(db, repo)
_repo_readme(
db, token, repo_id, repo["full_name"], readme, readme_html
)

repo_lists.extend(utils.fetch_all_repos(username, token) for username in usernames)

for repo in itertools.chain(*repo_lists):
repo_id = utils.save_repo(db, repo)
_repo_readme(
db, token, repo_id, repo["full_name"], readme, readme_html
)
utils.ensure_db_shape(db)


Expand Down