Skip to content

Commit 3015374

Browse files
fix: lint files
1 parent 29b62e3 commit 3015374

File tree

4 files changed

+159
-52
lines changed

4 files changed

+159
-52
lines changed

auth.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,30 @@ def auth_to_github(
2929
gh = github3.github.GitHubEnterprise(url=ghe)
3030
else:
3131
gh = github3.github.GitHub()
32-
gh.login_as_app_installation(gh_app_private_key_bytes, gh_app_id, gh_app_installation_id)
32+
gh.login_as_app_installation(
33+
gh_app_private_key_bytes, gh_app_id, gh_app_installation_id
34+
)
3335
github_connection = gh
3436
elif ghe and token:
3537
github_connection = github3.github.GitHubEnterprise(url=ghe, token=token)
3638
elif token:
3739
github_connection = github3.login(token=token)
3840
else:
39-
raise ValueError("GH_TOKEN or the set of [GH_APP_ID, GH_APP_INSTALLATION_ID, GH_APP_PRIVATE_KEY] environment variables are not set")
41+
raise ValueError(
42+
"GH_TOKEN or the set of [GH_APP_ID, GH_APP_INSTALLATION_ID, GH_APP_PRIVATE_KEY] environment variables are not set"
43+
)
4044

4145
if not github_connection:
4246
raise ValueError("Unable to authenticate to GitHub")
4347
return github_connection # type: ignore
4448

4549

46-
def get_github_app_installation_token(ghe: str, gh_app_id: str, gh_app_private_key_bytes: bytes, gh_app_installation_id: str) -> str | None:
50+
def get_github_app_installation_token(
51+
ghe: str,
52+
gh_app_id: str,
53+
gh_app_private_key_bytes: bytes,
54+
gh_app_installation_id: str,
55+
) -> str | None:
4756
"""
4857
Get a GitHub App Installation token.
4958
API: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation

evergreen.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,28 @@ def main(): # pragma: no cover
4545
) = env.get_env_vars()
4646

4747
# Auth to GitHub.com or GHE
48-
github_connection = auth.auth_to_github(token, gh_app_id, gh_app_installation_id, gh_app_private_key, ghe)
48+
github_connection = auth.auth_to_github(
49+
token, gh_app_id, gh_app_installation_id, gh_app_private_key, ghe
50+
)
4951

5052
if not token and gh_app_id and gh_app_installation_id and gh_app_private_key:
51-
token = auth.get_github_app_installation_token(ghe, gh_app_id, gh_app_private_key, gh_app_installation_id)
53+
token = auth.get_github_app_installation_token(
54+
ghe, gh_app_id, gh_app_private_key, gh_app_installation_id
55+
)
5256

5357
# If Project ID is set, lookup the global project ID
5458
if project_id:
5559
# Check Organization is set as it is required for linking to a project
5660
if not organization:
57-
raise ValueError("ORGANIZATION environment variable was not set. Please set it")
61+
raise ValueError(
62+
"ORGANIZATION environment variable was not set. Please set it"
63+
)
5864
project_id = get_global_project_id(ghe, token, organization, project_id)
5965

6066
# Get the repositories from the organization, team name, or list of repositories
61-
repos = get_repos_iterator(organization, team_name, repository_list, github_connection)
67+
repos = get_repos_iterator(
68+
organization, team_name, repository_list, github_connection
69+
)
6270

6371
# Iterate through the repositories and open an issue/PR if dependabot is not enabled
6472
count_eligible = 0
@@ -88,10 +96,14 @@ def main(): # pragma: no cover
8896
break
8997

9098
if existing_config and not update_existing:
91-
print(f"Skipping {repo.full_name} (dependabot file already exists and update_existing is False)")
99+
print(
100+
f"Skipping {repo.full_name} (dependabot file already exists and update_existing is False)"
101+
)
92102
continue
93103

94-
if created_after_date and is_repo_created_date_before(repo.created_at, created_after_date):
104+
if created_after_date and is_repo_created_date_before(
105+
repo.created_at, created_after_date
106+
):
95107
print(f"Skipping {repo.full_name} (created after filter)")
96108
continue
97109

@@ -131,7 +143,9 @@ def main(): # pragma: no cover
131143

132144
# Get dependabot security updates enabled if possible
133145
if enable_security_updates:
134-
if not is_dependabot_security_updates_enabled(ghe, repo.owner, repo.name, token):
146+
if not is_dependabot_security_updates_enabled(
147+
ghe, repo.owner, repo.name, token
148+
):
135149
enable_dependabot_security_updates(ghe, repo.owner, repo.name, token)
136150

137151
if follow_up_type == "issue":
@@ -142,7 +156,9 @@ def main(): # pragma: no cover
142156
issue = repo.create_issue(title, body_issue)
143157
print(f"\tCreated issue {issue.html_url}")
144158
if project_id:
145-
issue_id = get_global_issue_id(ghe, token, organization, repo.name, issue.number)
159+
issue_id = get_global_issue_id(
160+
ghe, token, organization, repo.name, issue.number
161+
)
146162
link_item_to_project(ghe, token, project_id, issue_id)
147163
print(f"\tLinked issue to project {project_id}")
148164
else:
@@ -164,7 +180,9 @@ def main(): # pragma: no cover
164180
)
165181
print(f"\tCreated pull request {pull.html_url}")
166182
if project_id:
167-
pr_id = get_global_pr_id(ghe, token, organization, repo.name, pull.number)
183+
pr_id = get_global_pr_id(
184+
ghe, token, organization, repo.name, pull.number
185+
)
168186
response = link_item_to_project(ghe, token, project_id, pr_id)
169187
if response:
170188
print(f"\tLinked pull request to project {project_id}")
@@ -178,7 +196,9 @@ def main(): # pragma: no cover
178196
def is_repo_created_date_before(repo_created_at: str, created_after_date: str):
179197
"""Check if the repository was created before the created_after_date"""
180198
repo_created_at_date = datetime.fromisoformat(repo_created_at).replace(tzinfo=None)
181-
return created_after_date and repo_created_at_date < datetime.strptime(created_after_date, "%Y-%m-%d")
199+
return created_after_date and repo_created_at_date < datetime.strptime(
200+
created_after_date, "%Y-%m-%d"
201+
)
182202

183203

184204
def is_dependabot_security_updates_enabled(ghe, owner, repo, access_token):
@@ -255,7 +275,9 @@ def get_repos_iterator(organization, team_name, repository_list, github_connecti
255275
else:
256276
# Get the repositories from the repository_list
257277
for repo in repository_list:
258-
repos.append(github_connection.repository(repo.split("/")[0], repo.split("/")[1]))
278+
repos.append(
279+
github_connection.repository(repo.split("/")[0], repo.split("/")[1])
280+
)
259281

260282
return repos
261283

@@ -314,7 +336,9 @@ def commit_changes(
314336
branch=branch_name,
315337
)
316338

317-
pull = repo.create_pull(title=title, body=body, head=branch_name, base=repo.default_branch)
339+
pull = repo.create_pull(
340+
title=title, body=body, head=branch_name, base=repo.default_branch
341+
)
318342
return pull
319343

320344

@@ -326,7 +350,9 @@ def get_global_project_id(ghe, token, organization, number):
326350
api_endpoint = f"{ghe}/api/v3" if ghe else "https://api.github.com"
327351
url = f"{api_endpoint}/graphql"
328352
headers = {"Authorization": f"Bearer {token}"}
329-
data = {"query": f'query{{organization(login: "{organization}") {{projectV2(number: {number}){{id}}}}}}'}
353+
data = {
354+
"query": f'query{{organization(login: "{organization}") {{projectV2(number: {number}){{id}}}}}}'
355+
}
330356

331357
try:
332358
response = requests.post(url, headers=headers, json=data, timeout=20)
@@ -418,7 +444,9 @@ def link_item_to_project(ghe, token, project_id, item_id):
418444
api_endpoint = f"{ghe}/api/v3" if ghe else "https://api.github.com"
419445
url = f"{api_endpoint}/graphql"
420446
headers = {"Authorization": f"Bearer {token}"}
421-
data = {"query": f'mutation {{addProjectV2ItemById(input: {{projectId: "{project_id}", contentId: "{item_id}"}}) {{item {{id}}}}}}'}
447+
data = {
448+
"query": f'mutation {{addProjectV2ItemById(input: {{projectId: "{project_id}", contentId: "{item_id}"}}) {{item {{id}}}}}}'
449+
}
422450

423451
try:
424452
response = requests.post(url, headers=headers, json=data, timeout=20)

test_auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def test_get_github_app_installation_token(self, mock_post):
5757
mock_response.json.return_value = {"token": dummy_token}
5858
mock_post.return_value = mock_response
5959

60-
result = auth.get_github_app_installation_token(b"ghe", "gh_private_token", "gh_app_id", "gh_installation_id")
60+
result = auth.get_github_app_installation_token(
61+
b"ghe", "gh_private_token", "gh_app_id", "gh_installation_id"
62+
)
6163

6264
self.assertEqual(result, dummy_token)
6365

0 commit comments

Comments
 (0)