@@ -63,14 +63,17 @@ def main(): # pragma: no cover
6363 ghe , gh_app_id , gh_app_private_key , gh_app_installation_id
6464 )
6565
66+ # Set the project_global_id to None by default
67+ project_global_id = None
68+
6669 # If Project ID is set, lookup the global project ID
6770 if project_id :
6871 # Check Organization is set as it is required for linking to a project
6972 if not organization :
7073 raise ValueError (
7174 "ORGANIZATION environment variable was not set. Please set it"
7275 )
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 )
7477
7578 # Get the repositories from the organization, team name, or list of repositories
7679 repos = get_repos_iterator (
@@ -83,7 +86,7 @@ def main(): # pragma: no cover
8386- **Organization:** { organization }
8487- **Follow Up Type:** { follow_up_type }
8588- **Dry Run:** { dry_run }
86- - **Enable Security Updates:** { enable_security_updates }
89+ - **Enable Security Updates:** { enable_security_updates } \n
8790 """
8891 # Add optional parameters to the summary
8992 if project_id :
@@ -209,21 +212,20 @@ def main(): # pragma: no cover
209212 ):
210213 enable_dependabot_security_updates (ghe , repo .owner , repo .name , token )
211214
212- link = ""
213215 if follow_up_type == "issue" :
214216 skip = check_pending_issues_for_duplicates (title , repo )
215217 if not skip :
216218 count_eligible += 1
217219 body_issue = f"{ body } \n \n ```yaml\n # { dependabot_filename_to_use } \n { dependabot_file } \n ```"
218220 issue = repo .create_issue (title , body_issue )
219- link = issue .html_url
220221 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 :
222224 issue_id = get_global_issue_id (
223225 ghe , token , organization , repo .name , issue .number
224226 )
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 } " )
227229 else :
228230 # Try to detect if the repo already has an open pull request for dependabot
229231 skip = check_pending_pulls_for_duplicates (title , repo )
@@ -241,20 +243,27 @@ def main(): # pragma: no cover
241243 dependabot_filename_to_use ,
242244 existing_config ,
243245 )
244- link = pull .html_url
245246 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 :
247254 pr_id = get_global_pr_id (
248255 ghe , token , organization , repo .name , pull .number
249256 )
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+ )
251260 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+ )
253264 except github3 .exceptions .NotFoundError :
254265 print ("\t Failed to create pull request. Check write permissions." )
255266 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 "
258267
259268 print (f"Done. { str (count_eligible )} repositories were eligible." )
260269 # 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):
506515 return None
507516
508517
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 ):
510519 """
511520 Links an item (issue or pull request) to a project in GitHub.
512521 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):
515524 url = f"{ api_endpoint } /graphql"
516525 headers = {"Authorization" : f"Bearer { token } " }
517526 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}}}}}}'
519528 }
520529
521530 try :
0 commit comments