@@ -63,14 +63,17 @@ def main(): # pragma: no cover
63
63
ghe , gh_app_id , gh_app_private_key , gh_app_installation_id
64
64
)
65
65
66
+ # Set the project_global_id to None by default
67
+ project_global_id = None
68
+
66
69
# If Project ID is set, lookup the global project ID
67
70
if project_id :
68
71
# Check Organization is set as it is required for linking to a project
69
72
if not organization :
70
73
raise ValueError (
71
74
"ORGANIZATION environment variable was not set. Please set it"
72
75
)
73
- project_id = get_global_project_id (ghe , token , organization , project_id )
76
+ project_global_id = get_global_project_id (ghe , token , organization , project_id )
74
77
75
78
# Get the repositories from the organization, team name, or list of repositories
76
79
repos = get_repos_iterator (
@@ -83,7 +86,7 @@ def main(): # pragma: no cover
83
86
- **Organization:** { organization }
84
87
- **Follow Up Type:** { follow_up_type }
85
88
- **Dry Run:** { dry_run }
86
- - **Enable Security Updates:** { enable_security_updates }
89
+ - **Enable Security Updates:** { enable_security_updates } \n
87
90
"""
88
91
# Add optional parameters to the summary
89
92
if project_id :
@@ -209,21 +212,20 @@ def main(): # pragma: no cover
209
212
):
210
213
enable_dependabot_security_updates (ghe , repo .owner , repo .name , token )
211
214
212
- link = ""
213
215
if follow_up_type == "issue" :
214
216
skip = check_pending_issues_for_duplicates (title , repo )
215
217
if not skip :
216
218
count_eligible += 1
217
219
body_issue = f"{ body } \n \n ```yaml\n # { dependabot_filename_to_use } \n { dependabot_file } \n ```"
218
220
issue = repo .create_issue (title , body_issue )
219
- link = issue .html_url
220
221
print (f"\t Created issue { issue .html_url } " )
221
- if project_id :
222
+ summary_content += f"| { repo .full_name } | { '✅' if enable_security_updates else '❌' } | { follow_up_type } | [Link]({ issue .html_url } ) |\n "
223
+ if project_global_id :
222
224
issue_id = get_global_issue_id (
223
225
ghe , token , organization , repo .name , issue .number
224
226
)
225
- link_item_to_project (ghe , token , project_id , issue_id )
226
- print (f"\t Linked issue to project { project_id } " )
227
+ link_item_to_project (ghe , token , project_global_id , issue_id )
228
+ print (f"\t Linked issue to project { project_global_id } " )
227
229
else :
228
230
# Try to detect if the repo already has an open pull request for dependabot
229
231
skip = check_pending_pulls_for_duplicates (title , repo )
@@ -241,20 +243,27 @@ def main(): # pragma: no cover
241
243
dependabot_filename_to_use ,
242
244
existing_config ,
243
245
)
244
- link = pull .html_url
245
246
print (f"\t Created pull request { pull .html_url } " )
246
- if project_id :
247
+ summary_content += (
248
+ f"| { repo .full_name } | "
249
+ f"{ '✅' if enable_security_updates else '❌' } | "
250
+ f"{ follow_up_type } | "
251
+ f"[Link]({ pull .html_url } ) |\n "
252
+ )
253
+ if project_global_id :
247
254
pr_id = get_global_pr_id (
248
255
ghe , token , organization , repo .name , pull .number
249
256
)
250
- response = link_item_to_project (ghe , token , project_id , pr_id )
257
+ response = link_item_to_project (
258
+ ghe , token , project_global_id , pr_id
259
+ )
251
260
if response :
252
- print (f"\t Linked pull request to project { project_id } " )
261
+ print (
262
+ f"\t Linked pull request to project { project_global_id } "
263
+ )
253
264
except github3 .exceptions .NotFoundError :
254
265
print ("\t Failed to create pull request. Check write permissions." )
255
266
continue
256
- # Append the repository to the summary content
257
- summary_content += f"| { repo .full_name } | { '✅' if enable_security_updates else '❌' } | { follow_up_type } | [Link]({ link } ) |\n "
258
267
259
268
print (f"Done. { str (count_eligible )} repositories were eligible." )
260
269
# Append the summary content to the GitHub step summary file
@@ -506,7 +515,7 @@ def get_global_pr_id(ghe, token, organization, repository, pr_number):
506
515
return None
507
516
508
517
509
- def link_item_to_project (ghe , token , project_id , item_id ):
518
+ def link_item_to_project (ghe , token , project_global_id , item_id ):
510
519
"""
511
520
Links an item (issue or pull request) to a project in GitHub.
512
521
API: https://docs.github.com/en/graphql/guides/forming-calls-with-graphql
@@ -515,7 +524,7 @@ def link_item_to_project(ghe, token, project_id, item_id):
515
524
url = f"{ api_endpoint } /graphql"
516
525
headers = {"Authorization" : f"Bearer { token } " }
517
526
data = {
518
- "query" : f'mutation {{addProjectV2ItemById(input: {{projectId: "{ project_id } ", contentId: "{ item_id } "}}) {{item {{id}}}}}}'
527
+ "query" : f'mutation {{addProjectV2ItemById(input: {{projectId: "{ project_global_id } ", contentId: "{ item_id } "}}) {{item {{id}}}}}}'
519
528
}
520
529
521
530
try :
0 commit comments