Skip to content

Commit 1f0f582

Browse files
committed
move get_select_repos() to gh_utils and allow it and get_select_repos() to be called without gh_org_cc or github_client, respectively
1 parent fbff426 commit 1f0f582

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

ccos/gh_utils.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def set_up_github_client():
5454
return github_client
5555

5656

57-
def get_cc_organization(github_client):
57+
def get_cc_organization(github_client=None):
58+
if github_client is None:
59+
github_client = set_up_github_client()
5860
LOG.info("Getting CC's GitHub organization...")
5961
try:
6062
gh_org_cc = github_client.get_organization(GITHUB_ORGANIZATION)
@@ -68,6 +70,35 @@ def get_cc_organization(github_client):
6870
return gh_org_cc
6971

7072

73+
def get_select_repos(args, gh_org_cc=None):
74+
if gh_org_cc is None:
75+
gh_org_cc = get_cc_organization()
76+
LOG.info("Get select GitHub repositories")
77+
LOG.change_indent(-1)
78+
repos = list(gh_org_cc.get_repos())
79+
LOG.change_indent(+1)
80+
# Skip archived repos
81+
repos_selected = []
82+
for repo in repos:
83+
if not repo.archived:
84+
repos_selected.append(repo)
85+
repos = repos_selected
86+
# Skip non-selected repos
87+
if args.repos:
88+
repos_selected = []
89+
for repo in repos:
90+
if repo.name in args.repos:
91+
repos_selected.append(repo)
92+
repos = repos_selected
93+
if not repos:
94+
raise Exception(
95+
"Specified repositories do not include any valid"
96+
f" repositories: {args.repos}"
97+
)
98+
repos.sort(key=lambda repo: repo.name)
99+
return repos
100+
101+
71102
def get_team_slug_name(project_name, role):
72103
"""
73104
Get the team name and team slug based on GitHub's naming scheme. By

normalize_repos.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,6 @@ def setup():
6565
return args
6666

6767

68-
def get_cc_repos(github):
69-
cc = gh_utils.get_cc_organization(github)
70-
return cc.get_repos()
71-
72-
73-
def get_select_repos(args):
74-
LOG.info("Get GitHub data")
75-
github = gh_utils.set_up_github_client()
76-
LOG.change_indent(-1)
77-
repos = list(get_cc_repos(github))
78-
LOG.change_indent(+1)
79-
# Skip archived repos
80-
repos_selected = []
81-
for repo in repos:
82-
if not repo.archived:
83-
repos_selected.append(repo)
84-
repos = repos_selected
85-
# Skip non-selected repos
86-
if args.repos:
87-
repos_selected = []
88-
for repo in repos:
89-
if repo.name in args.repos:
90-
repos_selected.append(repo)
91-
repos = repos_selected
92-
if not repos:
93-
raise ScriptError(
94-
"Specified repositories do not include any valid"
95-
f" repositories: {args.repos}"
96-
)
97-
repos.sort(key=lambda repo: repo.name)
98-
return repos
99-
100-
10168
def set_repo_labels(args, repos):
10269
if args.skip_labels:
10370
return
@@ -179,7 +146,7 @@ def update_branches(args, repos):
179146
def main():
180147
args = setup()
181148
LOG.info("Starting normalization")
182-
repos = get_select_repos(args)
149+
repos = gh_utils.get_select_repos(args)
183150
set_repo_labels(args, repos)
184151
validate_issue_labels(args, repos)
185152
update_branches(args, repos)

0 commit comments

Comments
 (0)