-
Notifications
You must be signed in to change notification settings - Fork 345
Improve email for build repair #6329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ab60b0
Add treeherder url
evgenyrp e931da3
Do not pass git commit as input
evgenyrp 95dcbaa
Reply to email for feedback
evgenyrp 600927d
Send email to blamed commit author
evgenyrp 1247814
Add a testing script
evgenyrp fe06a6c
Update readme
evgenyrp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import logging | ||
|
|
||
| import httpx | ||
|
|
||
| from app.config import settings | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _TIMEOUT = httpx.Timeout(30.0) | ||
|
|
||
|
|
||
| def _repo_slug() -> str: | ||
| """``owner/repo`` parsed from the configured firefox git url.""" | ||
| return settings.firefox_git_url.rstrip("/").removeprefix("https://github.com/") | ||
|
|
||
|
|
||
| def commit_author_email(git_commit: str) -> str | None: | ||
| """Author email of a firefox git commit, or None. | ||
|
|
||
| The build-repair agent returns the commit it blamed for the failure; we look | ||
| that commit up in the firefox GitHub mirror to notify its author directly. | ||
| """ | ||
| url = f"https://api.github.com/repos/{_repo_slug()}/commits/{git_commit}" | ||
| headers = {"Accept": "application/vnd.github+json"} | ||
| try: | ||
| resp = httpx.get(url, headers=headers, timeout=_TIMEOUT) | ||
| resp.raise_for_status() | ||
| author = (resp.json().get("commit") or {}).get("author") or {} | ||
| except (httpx.HTTPError, ValueError) as exc: | ||
| logger.warning("Failed to fetch author for commit %s: %s", git_commit, exc) | ||
| return None | ||
| return author.get("email") or None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Trigger a build-repair run for a real failing build task and email the result. | ||
|
|
||
| Drives the listener's normal path (trigger the agent via hackbot-api, poll the | ||
| run to completion, send the notification) from a synthetic pulse message, so you | ||
| can test on a real failure without waiting for a live one. | ||
|
|
||
| Credentials and settings are read from the environment / ``.env`` (see the | ||
| service README): HACKBOT_API_URL, HACKBOT_API_KEY, SENDGRID_API_KEY, | ||
| NOTIFICATION_SENDER, and NOTIFICATION_OVERRIDE_EMAIL. Always set | ||
| NOTIFICATION_OVERRIDE_EMAIL to your own address so the run emails you and not the | ||
| real developer; the script refuses to run otherwise. | ||
|
|
||
| Usage (from the service directory, with the env exported): | ||
|
|
||
| uv run --package hackbot-pulse-listener python scripts/send_test_run.py \ | ||
| <TASK_ID> --label build-linux64/opt [--project autoland] [--force] | ||
|
|
||
| Find a task id on Treeherder: a red build ("B") job -> Task inspector -> taskId. | ||
| """ | ||
|
|
||
| import argparse | ||
| import sys | ||
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
||
| from app import consumer | ||
| from app.config import settings | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | ||
| parser.add_argument("task_id", help="Taskcluster task id of a failed build job") | ||
| parser.add_argument( | ||
| "--label", | ||
| default="build-linux64/opt", | ||
| help="Build task label; must contain 'build' and not 'test'", | ||
| ) | ||
| parser.add_argument("--project", default="autoland", help="Taskcluster project tag") | ||
| parser.add_argument( | ||
| "--created-for", default="", help="createdForUser: the pushing developer email" | ||
| ) | ||
| parser.add_argument( | ||
| "--force", | ||
| action="store_true", | ||
| help="Skip the regression gate so a run always triggers", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| if not settings.notification_override_email: | ||
| parser.error( | ||
| "Set NOTIFICATION_OVERRIDE_EMAIL to your address so the test emails you, " | ||
| "not the real developer." | ||
| ) | ||
|
|
||
| if args.force: | ||
| consumer.regression.is_new_build_failure = lambda *a, **k: True | ||
|
|
||
| if args.project not in settings.watched_repos_set: | ||
| settings.watched_repos = f"{settings.watched_repos},{args.project}" | ||
|
|
||
| msg = { | ||
| "status": {"taskId": args.task_id}, | ||
| "task": { | ||
| "tags": { | ||
| "kind": "build", | ||
| "project": args.project, | ||
| "label": args.label, | ||
| "createdForUser": args.created_for, | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| with ThreadPoolExecutor(max_workers=4) as executor: | ||
| run_id = consumer.process(msg, executor) | ||
| if run_id is None: | ||
| print( | ||
| "No run triggered (filtered out, deduped, or DRY_RUN). Check " | ||
| "WATCHED_REPOS/DRY_RUN, or pass --force to skip the regression gate.", | ||
| file=sys.stderr, | ||
| ) | ||
| return 1 | ||
| print( | ||
| f"Triggered run {run_id}; polling until it finishes and emailing " | ||
| f"{settings.notification_override_email} (this can take several minutes)..." | ||
| ) | ||
| print("Done.") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.