|
1 | 1 | import os |
| 2 | +import subprocess |
2 | 3 | from github import Github |
3 | 4 |
|
4 | 5 | def _get_github_token(): |
@@ -48,14 +49,21 @@ def create_github_pr(repo: str, head_branch: str, title: str, body: str, base: s |
48 | 49 |
|
49 | 50 | def push_branch(branch_name: str): |
50 | 51 | """ |
51 | | - Create, commit, and push a branch with local changes to GitHub. |
| 52 | + Create and push a branch with committed changes. |
52 | 53 | """ |
53 | 54 | try: |
54 | | - os.system(f"git checkout -b {branch_name}") |
55 | | - os.system("git add .") |
56 | | - os.system("git commit -m 'Update policy via Devolv drift'") |
57 | | - os.system(f"git push origin {branch_name}") |
58 | | - print(f"✅ Pushed branch {branch_name} to origin") |
59 | | - except Exception as e: |
60 | | - print(f"❌ Failed to push branch {branch_name}: {e}") |
61 | | - raise |
| 55 | + subprocess.run(["git", "checkout", "-b", branch_name], check=True) |
| 56 | + |
| 57 | + # Configure git user identity locally |
| 58 | + subprocess.run(["git", "config", "user.email", "github-actions@users.noreply.github.com"], check=True) |
| 59 | + subprocess.run(["git", "config", "user.name", "github-actions"], check=True) |
| 60 | + |
| 61 | + subprocess.run(["git", "add", "."], check=True) |
| 62 | + subprocess.run(["git", "commit", "-m", f"Update policy from AWS: {branch_name}"], check=True) |
| 63 | + subprocess.run(["git", "push", "--set-upstream", "origin", branch_name], check=True) |
| 64 | + |
| 65 | + typer.echo(f"✅ Pushed branch {branch_name} to origin.") |
| 66 | + except subprocess.CalledProcessError as e: |
| 67 | + typer.echo(f"❌ Git command failed: {e}") |
| 68 | + raise typer.Exit(1) |
| 69 | + |
0 commit comments