@@ -17,26 +17,48 @@ def _get_github_repo(repo_full_name: str):
1717 gh = Github (_get_github_token ())
1818 return gh .get_repo (repo_full_name )
1919
20- def create_github_issue (repo : str , title : str , body : str , assignees : list ) -> tuple :
20+ def create_github_issue (repo : str , policy_name : str , assignees : list , drift_detected : bool = True ) -> tuple :
2121 """
22- Create a GitHub issue and return (number, url)
22+ Create a GitHub issue with dynamic body based on drift_detected.
23+ Returns (issue number, issue URL)
2324 """
2425 try :
2526 repo_obj = _get_github_repo (repo )
27+ approver_list = ", " .join ([f"@{ a } " for a in assignees ]) if assignees else "anyone"
28+
29+ title = f"Approval needed for IAM policy: { policy_name } "
30+ if drift_detected :
31+ body = (
32+ f"Please review and approve the sync for `{ policy_name } `.\n \n "
33+ f"✅ **Allowed approvers:** { approver_list } \n \n "
34+ "**Reply with one of the following commands to proceed:**\n "
35+ "- `local->aws` → Apply local policy changes to AWS\n "
36+ "- `aws->local` → Update local policy file from AWS\n "
37+ "- `aws<->local` → Sync both ways (superset, update AWS + local)\n "
38+ "- `skip` → Skip this sync"
39+ )
40+ else :
41+ body = (
42+ f"Please review and approve the current state for `{ policy_name } ` (✅ No drift detected).\n \n "
43+ f"✅ **Allowed approvers:** { approver_list } \n \n "
44+ "**Reply with one of the following commands to proceed:**\n "
45+ "- `accept` → Approve the current state, no further action\n "
46+ "- `reject` → Reject the current state (no changes will be made)"
47+ )
48+
2649 issue = repo_obj .create_issue (title = title , body = body , assignees = assignees )
2750 print (f"✅ Created issue #{ issue .number } in { repo } : { issue .html_url } " )
2851 return issue .number , issue .html_url
52+
2953 except Exception as e :
3054 print (f"❌ Failed to create issue in { repo } : { e } " )
3155 raise
3256
3357def create_github_pr (repo : str , head_branch : str , title : str , body : str , base : str = "main" , issue_num : int = None ) -> tuple :
3458 """
35- Create a GitHub PR. If issue_num is provided, comment on the issue.
36- Return (PR number, PR URL).
59+ Create a GitHub PR. Optionally comments on linked issue.
60+ Returns (PR number, PR URL)
3761 """
38- from github import Github
39-
4062 try :
4163 repo_obj = _get_github_repo (repo )
4264 pr = repo_obj .create_pull (
@@ -45,35 +67,29 @@ def create_github_pr(repo: str, head_branch: str, title: str, body: str, base: s
4567 head = head_branch ,
4668 base = base
4769 )
48- #print(f"✅ Created PR #{pr.number} in {repo}: {pr.html_url}")
4970
5071 if issue_num :
5172 issue = repo_obj .get_issue (number = issue_num )
52- issue .create_comment (f"A PR has been created for this sync: { pr .html_url } " )
53-
73+ issue .create_comment (f"✅ PR created and linked: { pr .html_url } " )
74+
75+ print (f"✅ Created PR #{ pr .number } in { repo } : { pr .html_url } " )
5476 return pr .number , pr .html_url
5577
5678 except Exception as e :
57- print (f"❌ Failed to create PR: { e } " )
79+ print (f"❌ Failed to create PR in { repo } : { e } " )
5880 raise
5981
6082def push_branch (branch_name : str ):
61- import subprocess
62- import typer
63-
83+ """
84+ Create, commit to, and push a git branch, rebasing if needed.
85+ """
6486 try :
65- # Create or switch to branch safely
6687 subprocess .run (["git" , "checkout" , "-B" , branch_name ], check = True )
67-
68- # Ensure Git identity is set
6988 subprocess .run (["git" , "config" , "user.email" , "github-actions@users.noreply.github.com" ], check = True )
7089 subprocess .run (["git" , "config" , "user.name" , "github-actions" ], check = True )
71-
72- # Add, commit
7390 subprocess .run (["git" , "add" , "." ], check = True )
7491 subprocess .run (["git" , "commit" , "-m" , f"Update policy: { branch_name } " ], check = True )
7592
76- # Try pushing
7793 try :
7894 subprocess .run (["git" , "push" , "--set-upstream" , "origin" , branch_name ], check = True )
7995 except subprocess .CalledProcessError :
@@ -86,5 +102,3 @@ def push_branch(branch_name: str):
86102 except subprocess .CalledProcessError as e :
87103 typer .echo (f"❌ Git command failed: { e } " )
88104 raise typer .Exit (1 )
89-
90-
0 commit comments