-
Notifications
You must be signed in to change notification settings - Fork 15
fix: correct rule YAML format and improve PR creation error handling #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c1c6ec3
9f2fad8
a05e1a2
c37641e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -768,17 +768,36 @@ async def create_git_ref( | |||||||||||||||||||||||||||||||||||||
| sha: str, | ||||||||||||||||||||||||||||||||||||||
| installation_id: int | None = None, | ||||||||||||||||||||||||||||||||||||||
| user_token: str | None = None, | ||||||||||||||||||||||||||||||||||||||
| ) -> bool: | ||||||||||||||||||||||||||||||||||||||
| """Create a new git ref/branch.""" | ||||||||||||||||||||||||||||||||||||||
| ) -> dict[str, Any] | None: | ||||||||||||||||||||||||||||||||||||||
| """Create a new git ref/branch. Returns ref data if successful, None if failed.""" | ||||||||||||||||||||||||||||||||||||||
| headers = await self._get_auth_headers(installation_id=installation_id, user_token=user_token) | ||||||||||||||||||||||||||||||||||||||
| if not headers: | ||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||
| url = f"{config.github.api_base_url}/repos/{repo_full_name}/git/refs" | ||||||||||||||||||||||||||||||||||||||
| ref_clean = ref.removeprefix("refs/heads/") if ref.startswith("refs/heads/") else ref | ||||||||||||||||||||||||||||||||||||||
| payload = {"ref": f"refs/heads/{ref_clean}", "sha": sha} | ||||||||||||||||||||||||||||||||||||||
| session = await self._get_session() | ||||||||||||||||||||||||||||||||||||||
| async with session.post(url, headers=headers, json=payload) as response: | ||||||||||||||||||||||||||||||||||||||
| return response.status in (200, 201) | ||||||||||||||||||||||||||||||||||||||
| if response.status in (200, 201): | ||||||||||||||||||||||||||||||||||||||
| return await response.json() | ||||||||||||||||||||||||||||||||||||||
| # Branch might already exist - check if it exists and points to the same SHA | ||||||||||||||||||||||||||||||||||||||
| if response.status == 422: | ||||||||||||||||||||||||||||||||||||||
| error_data = await response.json() | ||||||||||||||||||||||||||||||||||||||
| if "already exists" in error_data.get("message", "").lower(): | ||||||||||||||||||||||||||||||||||||||
| # Branch exists - verify it's the same SHA | ||||||||||||||||||||||||||||||||||||||
| existing_ref = await self.get_git_ref_sha(repo_full_name, ref_clean, installation_id, user_token) | ||||||||||||||||||||||||||||||||||||||
| if existing_ref == sha: | ||||||||||||||||||||||||||||||||||||||
| logger.info(f"Branch {ref_clean} already exists with same SHA, continuing") | ||||||||||||||||||||||||||||||||||||||
| return {"ref": f"refs/heads/{ref_clean}", "object": {"sha": sha}} | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+784
to
+791
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bug in the error handling logic. If the response status is 422, To fix this, you should handle the non-idempotent 422 error case completely within its block by logging the
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still the case? Should we push a follow up commit to resolve this? @naaa760 |
||||||||||||||||||||||||||||||||||||||
| # Branch exists but with different SHA - log and return None | ||||||||||||||||||||||||||||||||||||||
| logger.error(f"Failed to create branch {ref_clean}: branch exists with different SHA. {error_data}") | ||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||
| # 422 error but not "already exists" - log and return None | ||||||||||||||||||||||||||||||||||||||
| logger.error(f"Failed to create branch {ref_clean}: {error_data}") | ||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||
| error_text = await response.text() | ||||||||||||||||||||||||||||||||||||||
| logger.error(f"Failed to create branch {ref_clean}: {response.status} - {error_text}") | ||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def create_or_update_file( | ||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these hardcoded parameters limit the range of cases the agent can support? For example, can the agent enforce a rule that prevents a specific member from making changes to a specific path or module (e.g. /auth)? @naaa760