Skip to content

Commit

Permalink
make get_repos public function:
Browse files Browse the repository at this point in the history
init

git meta
  • Loading branch information
scivision committed Jun 4, 2019
1 parent d28d0cc commit 2f34154
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

49 changes: 49 additions & 0 deletions SetArchive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
"""
Archive GitHub repos for a user/organization with repo names matching pattern
Requires GitHub Oauth login with sufficient permissions "repo:public_repo".
(admin:org Oauth does not work)
It's suggested you create an Oauth key for this, and then disable/delete this key permissions when done
to avoid a security issue.
if you get error
github.GithubException.UnknownObjectException: 404 {'message': 'Not Found',
'documentation_url': 'https://developer.github.com/v3/repos/#edit'}
that typically means your Oauth key doesn't have adequte permissions.
"""
from argparse import ArgumentParser
import gitutils.github_base as gb


def main():
p = ArgumentParser(description='Set GitHub repos to Archive matching pattern')
p.add_argument('user', help='GitHub username / organizations')
p.add_argument('oauth', help='Oauth filename')
p.add_argument('pattern', help='archive repos with name starting with this string')
P = p.parse_args()

# %% authentication
sess = gb.github_session(P.oauth)

gb.check_api_limit(sess)
# %% prepare to loop over repos
repos = gb.get_repos(sess, P.user)

to_archive = [repo for repo in repos if repo.name.startswith(P.pattern) and not repo.archived]
if not to_archive:
raise SystemExit(f'no repos left to archive under {P.user}/{P.pattern}')

print('\ntype y to archive', '\n'.join([repo.full_name for repo in to_archive]))
if input() != 'y':
raise SystemExit('Aborted')

for repo in to_archive:
repo.edit(archived=True)
print('archived', repo.full_name)


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions gitutils/github_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,14 @@ def read_repos(fn: Path, sheet: str) -> Dict[str, str]:
repos.dropna(how='any', inplace=True)

return repos.to_dict()


def get_repos(g: github.Github, user: str) -> list:
repo = user.split('/')

if len(repo) == 2: # assuming a single repo is specified
repos = [g.get_user(repo[0]).get_repo(repo[1])]
elif len(repo) == 1:
repos = list(g.get_user(repo[0]).get_repos())

return repos
15 changes: 2 additions & 13 deletions gitutils/github_repo_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import github
import logging

from .github_base import check_api_limit, github_session
from .github_base import check_api_limit, github_session, get_repos


def repo_prober(user: str,
Expand Down Expand Up @@ -44,7 +44,7 @@ def repo_prober(user: str,

check_api_limit(sess)
# %% prepare to loop over repos
repos = _get_repos(sess, user)
repos = get_repos(sess, user)

counts = []
ahead: List[Tuple[str, int]] = []
Expand Down Expand Up @@ -127,14 +127,3 @@ def fork_prober(repo, sess,
print()

return ahead


def _get_repos(g: github.Github, user: str) -> list:
repo = user.split('/')

if len(repo) == 2: # assuming a single repo is specified
repos = [g.get_user(repo[0]).get_repo(repo[1])]
elif len(repo) == 1:
repos = list(g.get_user(repo[0]).get_repos())

return repos
15 changes: 13 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = gitutils
version = 1.2.3
version = 1.2.4
author = Michael Hirsch, Ph.D.
author_email = [email protected]
description = concurrent, pipelined, platform-agnostic Git utilities for managing a large number of Git repositories
Expand Down Expand Up @@ -33,8 +33,19 @@ setup_requires =
setuptools >= 38.6
pip >= 10
twine >= 1.11
include_package_data = True
packages = find:
scripts =
ActOnChanged.py
ListAllGithubRepos.py
branch.py
fetch.py
gitemail.py
pull.py
GithubStarTotal.py
SetArchive.py
check.py
find_missing_file.py
modified.py
install_requires =
colorama

Expand Down

0 comments on commit 2f34154

Please sign in to comment.