Skip to content

Commit af473b4

Browse files
committed
feat(finalize): add fork commit instructions comment
Add functionality to post a comment with git commands when the finalize job completes for a fork PR. The comment provides users with the exact bash commands needed to commit agent changes to their fork. Changes: - Add read_parsed_input() to read artifact data - Add post_fork_commit_comment() to post instructions - Integrate fork detection into main flow - Post comment only when head_repo is present 🤖 Assisted by the code-assist SOP
1 parent 6165aff commit af473b4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

strands-command/scripts/python/write_executor.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,51 @@
3535
logger = logging.getLogger("write_executor")
3636

3737

38+
def read_parsed_input() -> Dict[str, Any] | None:
39+
"""Read parsed input artifact if it exists.
40+
41+
Returns:
42+
Dictionary with parsed input data or None if not found
43+
"""
44+
artifact_path = Path("strands-parsed-input.json")
45+
if not artifact_path.exists():
46+
logger.debug("Parsed input artifact not found")
47+
return None
48+
49+
try:
50+
with open(artifact_path, 'r') as f:
51+
return json.load(f)
52+
except Exception as e:
53+
logger.error(f"Failed to read parsed input: {e}")
54+
return None
55+
56+
57+
def post_fork_commit_comment(issue_id: int, branch_name: str, head_repo: str):
58+
"""Post a comment with fork commit instructions.
59+
60+
Args:
61+
issue_id: Issue number to comment on
62+
branch_name: Branch name created by agent
63+
head_repo: Fork repository name
64+
"""
65+
comment = f"""## 🔀 Fork Changes Ready
66+
67+
The agent has completed its work on your fork. To commit these changes to your fork, run:
68+
69+
```bash
70+
git fetch origin {branch_name}
71+
git checkout {branch_name}
72+
git add .
73+
git commit -m "Apply agent changes"
74+
git push origin {branch_name}
75+
```
76+
77+
This will push the changes to your fork at `{head_repo}`."""
78+
79+
logger.info(f"Posting fork commit instructions to issue #{issue_id}")
80+
add_issue_comment(issue_id, comment)
81+
82+
3883
def get_function_mapping() -> Dict[str, Any]:
3984
"""Get mapping of function names to actual functions."""
4085
return {
@@ -149,6 +194,18 @@ def main():
149194

150195
# Process the JSONL file
151196
process_jsonl_file(artifact_path, args.issue_id)
197+
198+
# Check if this is a fork PR and post commit instructions
199+
parsed_input = read_parsed_input()
200+
if parsed_input and args.issue_id:
201+
head_repo = parsed_input.get("head_repo")
202+
branch_name = parsed_input.get("branch_name")
203+
204+
if head_repo and branch_name:
205+
logger.info("Fork PR detected - posting commit instructions")
206+
post_fork_commit_comment(args.issue_id, branch_name, head_repo)
207+
else:
208+
logger.debug("Not a fork PR or missing required fields")
152209

153210
if __name__ == "__main__":
154211
main()

0 commit comments

Comments
 (0)