@@ -45,20 +45,28 @@ def main(): # pragma: no cover
45
45
) = env .get_env_vars ()
46
46
47
47
# 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
+ )
49
51
50
52
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
+ )
52
56
53
57
# If Project ID is set, lookup the global project ID
54
58
if project_id :
55
59
# Check Organization is set as it is required for linking to a project
56
60
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
+ )
58
64
project_id = get_global_project_id (ghe , token , organization , project_id )
59
65
60
66
# 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
+ )
62
70
63
71
# Iterate through the repositories and open an issue/PR if dependabot is not enabled
64
72
count_eligible = 0
@@ -88,10 +96,14 @@ def main(): # pragma: no cover
88
96
break
89
97
90
98
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
+ )
92
102
continue
93
103
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
+ ):
95
107
print (f"Skipping { repo .full_name } (created after filter)" )
96
108
continue
97
109
@@ -131,7 +143,9 @@ def main(): # pragma: no cover
131
143
132
144
# Get dependabot security updates enabled if possible
133
145
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
+ ):
135
149
enable_dependabot_security_updates (ghe , repo .owner , repo .name , token )
136
150
137
151
if follow_up_type == "issue" :
@@ -142,7 +156,9 @@ def main(): # pragma: no cover
142
156
issue = repo .create_issue (title , body_issue )
143
157
print (f"\t Created issue { issue .html_url } " )
144
158
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
+ )
146
162
link_item_to_project (ghe , token , project_id , issue_id )
147
163
print (f"\t Linked issue to project { project_id } " )
148
164
else :
@@ -164,7 +180,9 @@ def main(): # pragma: no cover
164
180
)
165
181
print (f"\t Created pull request { pull .html_url } " )
166
182
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
+ )
168
186
response = link_item_to_project (ghe , token , project_id , pr_id )
169
187
if response :
170
188
print (f"\t Linked pull request to project { project_id } " )
@@ -178,7 +196,9 @@ def main(): # pragma: no cover
178
196
def is_repo_created_date_before (repo_created_at : str , created_after_date : str ):
179
197
"""Check if the repository was created before the created_after_date"""
180
198
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
+ )
182
202
183
203
184
204
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
255
275
else :
256
276
# Get the repositories from the repository_list
257
277
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
+ )
259
281
260
282
return repos
261
283
@@ -314,7 +336,9 @@ def commit_changes(
314
336
branch = branch_name ,
315
337
)
316
338
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
+ )
318
342
return pull
319
343
320
344
@@ -326,7 +350,9 @@ def get_global_project_id(ghe, token, organization, number):
326
350
api_endpoint = f"{ ghe } /api/v3" if ghe else "https://api.github.com"
327
351
url = f"{ api_endpoint } /graphql"
328
352
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
+ }
330
356
331
357
try :
332
358
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):
418
444
api_endpoint = f"{ ghe } /api/v3" if ghe else "https://api.github.com"
419
445
url = f"{ api_endpoint } /graphql"
420
446
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
+ }
422
450
423
451
try :
424
452
response = requests .post (url , headers = headers , json = data , timeout = 20 )
0 commit comments