|
35 | 35 | logger = logging.getLogger("write_executor") |
36 | 36 |
|
37 | 37 |
|
| 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 | + |
38 | 83 | def get_function_mapping() -> Dict[str, Any]: |
39 | 84 | """Get mapping of function names to actual functions.""" |
40 | 85 | return { |
@@ -149,6 +194,18 @@ def main(): |
149 | 194 |
|
150 | 195 | # Process the JSONL file |
151 | 196 | 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") |
152 | 209 |
|
153 | 210 | if __name__ == "__main__": |
154 | 211 | main() |
0 commit comments