Skip to content

Commit a6a52f7

Browse files
committed
testing new version
1 parent 1ff8b64 commit a6a52f7

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

devolv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.2.19"
1+
__version__ = "0.2.20"
22

devolv/drift/cli.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,31 @@
1313
app = typer.Typer()
1414

1515
def push_branch(branch_name: str):
16+
import subprocess
17+
import typer
18+
1619
try:
20+
# Create or switch to branch safely
1721
subprocess.run(["git", "checkout", "-B", branch_name], check=True)
22+
23+
# Ensure Git identity is set
1824
subprocess.run(["git", "config", "user.email", "github-actions@users.noreply.github.com"], check=True)
1925
subprocess.run(["git", "config", "user.name", "github-actions"], check=True)
26+
27+
# Add, commit
2028
subprocess.run(["git", "add", "."], check=True)
2129
subprocess.run(["git", "commit", "-m", f"Update policy: {branch_name}"], check=True)
2230

31+
# Try pushing
2332
try:
2433
subprocess.run(["git", "push", "--set-upstream", "origin", branch_name], check=True)
2534
except subprocess.CalledProcessError:
26-
typer.echo("⚠️ Push failed. Trying to pull + re-push...")
35+
typer.echo("⚠️ Initial push failed. Attempting rebase + push...")
2736
subprocess.run(["git", "pull", "--rebase", "origin", branch_name], check=True)
2837
subprocess.run(["git", "push", "--set-upstream", "origin", branch_name], check=True)
2938

3039
typer.echo(f"✅ Pushed branch {branch_name} to origin.")
40+
3141
except subprocess.CalledProcessError as e:
3242
typer.echo(f"❌ Git command failed: {e}")
3343
raise typer.Exit(1)
@@ -105,28 +115,36 @@ def _update_aws_policy(iam, policy_arn, policy_doc):
105115
)
106116

107117
def _update_local_and_create_pr(doc, policy_file, repo_full_name, policy_name, issue_num, token, description=""):
118+
import json
119+
from github import Github
120+
from devolv.drift.github_approvals import create_github_pr
121+
108122
new_content = json.dumps(doc, indent=2)
109123
with open(policy_file, "w") as f:
110124
f.write(new_content)
111125

112-
branch_base = (
126+
# Clean branch name
127+
branch = (
113128
f"{description.replace(' ', '-').replace('+', 'plus').replace('/', '-')}-policy-{policy_name}"
114129
.strip("-")
115130
.lower()
116131
)
117-
branch_name = push_branch(branch_base)
132+
133+
push_branch(branch)
118134

119135
pr_title = f"Update {policy_file} {description}".strip()
120136
pr_body = f"This PR updates `{policy_file}` {description}.\n\nLinked to issue #{issue_num}.".strip()
121-
pr_num, pr_url = create_github_pr(repo_full_name, branch_name, pr_title, pr_body, issue_num=issue_num)
137+
138+
# ✅ Pass correct branch name
139+
pr_num, pr_url = create_github_pr(repo_full_name, branch, pr_title, pr_body, issue_num=issue_num)
122140

123141
typer.echo(f"✅ Created PR #{pr_num}: {pr_url}")
124142

125-
# Close issue *immediately after PR link is posted*
143+
# ✅ Auto-close issue immediately
126144
gh = Github(token)
127145
repo = gh.get_repo(repo_full_name)
128146
issue = repo.get_issue(number=issue_num)
129147
issue.create_comment(f"✅ PR created and linked: {pr_url}. Closing issue.")
130148
issue.edit(state="closed")
131-
typer.echo(f"💬 Commented on and closed issue #{issue_num}")
149+
132150

devolv/drift/github_approvals.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ def create_github_issue(repo: str, title: str, body: str, assignees: list) -> tu
3232

3333
def create_github_pr(repo: str, head_branch: str, title: str, body: str, base: str = "main", issue_num: int = None) -> tuple:
3434
"""
35-
Create a GitHub PR. If issue_num is provided, comment on the issue and close it.
35+
Create a GitHub PR. If issue_num is provided, comment on the issue.
3636
Return (PR number, PR URL).
3737
"""
38+
from github import Github
39+
3840
try:
3941
repo_obj = _get_github_repo(repo)
4042
pr = repo_obj.create_pull(
@@ -43,37 +45,46 @@ def create_github_pr(repo: str, head_branch: str, title: str, body: str, base: s
4345
head=head_branch,
4446
base=base
4547
)
46-
print(f"✅ Created PR #{pr.number}: {pr.html_url}")
48+
print(f"✅ Created PR #{pr.number} in {repo}: {pr.html_url}")
4749

4850
if issue_num:
4951
issue = repo_obj.get_issue(number=issue_num)
5052
issue.create_comment(f"A PR has been created for this sync: {pr.html_url}")
51-
53+
5254
return pr.number, pr.html_url
5355

5456
except Exception as e:
5557
print(f"❌ Failed to create PR: {e}")
5658
raise
5759

58-
59-
6060
def push_branch(branch_name: str):
61+
import subprocess
62+
import typer
63+
6164
try:
65+
# Create or switch to branch safely
6266
subprocess.run(["git", "checkout", "-B", branch_name], check=True)
67+
68+
# Ensure Git identity is set
6369
subprocess.run(["git", "config", "user.email", "github-actions@users.noreply.github.com"], check=True)
6470
subprocess.run(["git", "config", "user.name", "github-actions"], check=True)
71+
72+
# Add, commit
6573
subprocess.run(["git", "add", "."], check=True)
6674
subprocess.run(["git", "commit", "-m", f"Update policy: {branch_name}"], check=True)
6775

76+
# Try pushing
6877
try:
6978
subprocess.run(["git", "push", "--set-upstream", "origin", branch_name], check=True)
7079
except subprocess.CalledProcessError:
71-
typer.echo("⚠️ Push failed. Trying to pull + re-push...")
80+
typer.echo("⚠️ Initial push failed. Attempting rebase + push...")
7281
subprocess.run(["git", "pull", "--rebase", "origin", branch_name], check=True)
7382
subprocess.run(["git", "push", "--set-upstream", "origin", branch_name], check=True)
7483

7584
typer.echo(f"✅ Pushed branch {branch_name} to origin.")
85+
7686
except subprocess.CalledProcessError as e:
7787
typer.echo(f"❌ Git command failed: {e}")
7888
raise typer.Exit(1)
7989

90+

0 commit comments

Comments
 (0)