-
Notifications
You must be signed in to change notification settings - Fork 11
api.views: add try push handover functionality (bug 2002566) #748
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
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 |
|---|---|---|
|
|
@@ -305,3 +305,48 @@ def get(self, request: WSGIRequest, repo_name: str, number: int) -> JsonResponse | |
| target_repo, pull_request, request | ||
| ) | ||
| return JsonResponse(warnings_and_blockers) | ||
|
|
||
|
|
||
| class PullRequestTryPushAPIView(APIView): | ||
| @method_decorator(require_authenticated_user) | ||
| def post( | ||
| self, request: WSGIRequest, repo_name: str, pull_number: int | ||
| ) -> JsonResponse: | ||
| try: | ||
| try_repo = Repo.objects.get(name="try") | ||
shtrom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except Repo.DoesNotExist: | ||
| return JsonResponse({"errors": ["Try repo does not exist"]}, 500) | ||
|
|
||
| target_repo = Repo.objects.get(name=repo_name) | ||
| client = GitHubAPIClient(target_repo.url) | ||
| ldap_username = request.user.email | ||
| pull_request = client.build_pull_request(pull_number) | ||
|
|
||
| job = LandingJob.objects.create( | ||
| target_repo=target_repo, | ||
| is_handed_over=False, | ||
| is_pull_request_job=True, | ||
| handover_repo=try_repo, | ||
| requester_email=ldap_username, | ||
| ) | ||
zzzeid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| author_name, author_email = pull_request.author | ||
| try: | ||
| timestamp = int(datetime.fromisoformat(pull_request.updated_at).timestamp()) | ||
| except ValueError: | ||
| timestamp = int(datetime.now().timestamp()) | ||
| patch_data = { | ||
| "author_name": author_name, | ||
| "author_email": author_email, | ||
| "commit_message": pull_request.commit_message, | ||
| "timestamp": timestamp, | ||
| } | ||
|
Comment on lines
+337
to
+342
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. note for later: We've been building this often enough, we should make it a method of the PullRequest. |
||
| revision = Revision.objects.create( | ||
| pull_number=pull_request.number, | ||
| patches=pull_request.patch, | ||
| patch_data=patch_data, | ||
| ) | ||
| add_revisions_to_job([revision], job) | ||
| job.status = JobStatus.SUBMITTED | ||
| job.save() | ||
|
|
||
| return JsonResponse({"id": job.id}, status=201) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Generated by Django 5.2.8 on 2025-12-16 17:25 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("main", "0041_revision_pull_base_sha_revision_pull_head_sha"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="landingjob", | ||
| name="handover_repo", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="handover_jobs", | ||
| to="main.repo", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="landingjob", | ||
| name="is_handed_over", | ||
| field=models.BooleanField(blank=True, null=True), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,7 +203,7 @@ def apply_patch_git(self, patch_bytes: bytes): | |
| raise exc | ||
|
|
||
| @detect_patch_conflict | ||
| def get_diff_from_patches(self, patches: str) -> str: | ||
| def add_diff_from_patches(self, patches: str) -> str: | ||
|
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. What motivates the change in name? We do a |
||
| """Apply multiple patches and return the diff output.""" | ||
| # TODO: add error handling so that if something goes wrong here, | ||
| # a meaningful error is stored in the landing job. This would be | ||
|
|
||
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.
If this firefox patch is approved, you'll be able to pass all the
kwargsintry_task_configparameter.Your payload should look like:
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.
Ok, I am going to move these changes to their own PR so that this one can be merged before the schema is finalized. Will update with your suggestion in that other PR.