Skip to content

Commit 6dac535

Browse files
committed
testing new drift version
1 parent a1d0bdd commit 6dac535

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

.github/workflows/test-devolv-action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ jobs:
3434
tool: drift
3535
policy-name: DevolvTestPolicyHuge
3636
path: ./test-devolv-policy.json
37+
approvers: RkSinghDeo, devolvdev
3738
github-token: ${{ secrets.GITHUB_TOKEN }}
38-
39+
3940
- name: Run Devolv Validate
4041
uses: devolvdev/devolv-actions@v2
4142
with:

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.13"
1+
__version__ = "0.2.14"
22

devolv/drift/cli.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from devolv.drift.issues import create_approval_issue, wait_for_sync_choice
99
from devolv.drift.github_approvals import create_github_pr
1010
from devolv.drift.report import detect_and_print_drift
11+
from github import Github # Needed for auto-close
1112

1213
app = typer.Typer()
1314

@@ -74,13 +75,13 @@ def drift(
7475
typer.echo(f"✅ AWS policy {policy_arn} updated with local changes (append-only).")
7576

7677
elif choice == "aws->local":
77-
_update_local_and_create_pr(aws_doc, policy_file, repo_full_name, policy_name, issue_num, description="from AWS policy")
78+
_update_local_and_create_pr(aws_doc, policy_file, repo_full_name, policy_name, issue_num, token, "from AWS policy")
7879

7980
elif choice == "aws<->local":
8081
superset_doc = build_superset_policy(local_doc, aws_doc)
8182
_update_aws_policy(iam, policy_arn, superset_doc)
8283
typer.echo(f"✅ AWS policy {policy_arn} updated with superset of local + AWS.")
83-
_update_local_and_create_pr(superset_doc, policy_file, repo_full_name, policy_name, issue_num, description="with superset of local + AWS")
84+
_update_local_and_create_pr(superset_doc, policy_file, repo_full_name, policy_name, issue_num, token, "with superset of local + AWS")
8485

8586
else:
8687
typer.echo("⏭ No synchronization performed (skip).")
@@ -96,16 +97,27 @@ def _update_aws_policy(iam, policy_arn, policy_doc):
9697
SetAsDefault=True
9798
)
9899

99-
def _update_local_and_create_pr(doc, policy_file, repo_full_name, policy_name, issue_num, description=""):
100+
def _update_local_and_create_pr(doc, policy_file, repo_full_name, policy_name, issue_num, token, description=""):
100101
new_content = json.dumps(doc, indent=2)
101102
with open(policy_file, "w") as f:
102103
f.write(new_content)
103104

104-
branch = f"{description.replace(' ', '-')}-policy-{policy_name}".strip("-")
105+
branch = (
106+
f"{description.replace(' ', '-').replace('+', 'plus').replace('/', '-')}-policy-{policy_name}"
107+
.strip("-")
108+
.lower()
109+
)
105110
push_branch(branch)
106111

107112
pr_title = f"Update {policy_file} {description}".strip()
108113
pr_body = f"This PR updates `{policy_file}` {description}.\n\nLinked to issue #{issue_num}.".strip()
109114
pr_num, pr_url = create_github_pr(repo_full_name, branch, pr_title, pr_body, issue_num=issue_num)
110115

111116
typer.echo(f"✅ Created PR #{pr_num}: {pr_url}")
117+
118+
# Auto-close issue
119+
gh = Github(token)
120+
repo = gh.get_repo(repo_full_name)
121+
issue = repo.get_issue(number=issue_num)
122+
issue.create_comment(f"✅ PR created and linked: {pr_url}. Closing issue.")
123+
issue.edit(state="closed")

devolv/drift/issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def wait_for_sync_choice(repo_full_name, issue_number, token):
2626
comments = issue.get_comments()
2727
for comment in comments:
2828
content = comment.body.strip().lower()
29-
if content in ["local->aws", "aws->local", "aws<->local" "skip"]:
29+
if content in ["local->aws", "aws->local", "aws<->local", "skip"]:
3030
return content
3131
print("Waiting for approval comment...")
3232
time.sleep(30) # Poll every 30 seconds

0 commit comments

Comments
 (0)