-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(seer): Skip the iteration push when the PR is closed #123831
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
15abd62
4982808
1965d75
2a1009d
429f5b6
1520e5a
c985ea2
c4cb914
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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Read the live state of the pull requests an Autofix run opened. | ||
|
|
||
| Closing a PR is how someone tells Seer to stop working on it. Both ends of an | ||
| iteration ask here: the consume task before it spends an agent run, and the | ||
| completion hook before it pushes what that run produced. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from scm import actions as scm_actions | ||
| from scm.types import GetPullRequestProtocol | ||
|
|
||
| from sentry.models.organization import Organization | ||
| from sentry.models.repository import Repository | ||
| from sentry.scm.factory import new as make_scm | ||
| from sentry.seer.agent.client_models import SeerRunState | ||
| from sentry.seer.autofix.pr_iteration.constants import PR_ITERATION_PROVIDER_SLUG | ||
| from sentry.utils import metrics | ||
|
|
||
| PR_CLOSED_METRIC = "autofix.pr_iteration.pr_closed" | ||
|
|
||
| # Where we caught it: before the agent run, or before the push. The only tag on | ||
| # the metric, and closed so it stays two time series. | ||
| PrClosedGate = Literal["consume", "push"] | ||
|
|
||
|
|
||
| def record_pr_closed(gate: PrClosedGate) -> None: | ||
| metrics.incr(PR_CLOSED_METRIC, tags={"gate": gate}) | ||
|
|
||
|
|
||
| def iteration_prs_any_closed(organization: Organization, state: SeerRunState) -> bool: | ||
| """True when any PR on the run reads back as closed. | ||
|
|
||
| One closed PR stops the whole run: an iteration pushes to every repo at | ||
| once, so there is no way to serve the open PRs while leaving the closed one | ||
| alone. | ||
|
|
||
| A PR we cannot read (no number, repo gone, unsupported provider, API error) | ||
| is passed over: a transient read failure should not silently drop an | ||
| iteration's work. | ||
| """ | ||
| for repo_name, pr_state in state.repo_pr_states.items(): | ||
| pr_number = pr_state.pr_number | ||
| if pr_number is None: | ||
| continue | ||
|
|
||
| repo, _resolution = Repository.objects.resolve_active( | ||
| organization_id=organization.id, | ||
| name=repo_name, | ||
| normalized_provider=PR_ITERATION_PROVIDER_SLUG, | ||
| ) | ||
| if repo is None: | ||
| continue | ||
|
|
||
| try: | ||
| scm = make_scm(organization.id, repo.id, referrer="seer") | ||
| except Exception: | ||
| continue | ||
|
|
||
| if not isinstance(scm, GetPullRequestProtocol): | ||
| continue | ||
|
|
||
| try: | ||
| pull_request = scm_actions.get_pull_request(scm, str(pr_number)) | ||
| except Exception: | ||
| continue | ||
|
|
||
| if pull_request["data"]["state"] == "closed": | ||
| return True | ||
|
|
||
| return False | ||
|
Comment on lines
+42
to
+73
Contributor
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. good approach for now
Member
Author
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. hm true, we can prob store the closed/open state in the metadata, we could reflect this on the ui as well tbh forgot that we get pr closed webhooks 😢 will add it as follow-up |
||
Uh oh!
There was an error while loading. Please reload this page.