From 7f31f735ca0bb9a84e0dc18eb1da0a8652126465ad6b11eaaf97f08b189d6e21 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Wed, 10 Jul 2024 20:41:24 +0200 Subject: [PATCH] . --- bots-common/gitea_utils.go | 8 +- bots-common/request_pr.go | 1 - bots-common/request_pr_test.go | 413 +++++++++++++++++++++++++++++++++ pr-review/main.go | 2 +- 4 files changed, 418 insertions(+), 6 deletions(-) diff --git a/bots-common/gitea_utils.go b/bots-common/gitea_utils.go index 96bcbb0..a52f27c 100644 --- a/bots-common/gitea_utils.go +++ b/bots-common/gitea_utils.go @@ -169,7 +169,7 @@ func (h *RequestHandler) RequestReviews(pr *models.PullRequest, reviewer string) return review.GetPayload() } -func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequest) *models.PullRequest { +func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.PullRequest { if h.HasError() { return nil } @@ -184,7 +184,7 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequest) *models.PullRequ repository. NewRepoListPullRequestsParams(). WithDefaults(). - WithOwner(pr.Repo.Owner.Username). + WithOwner(pr.Repository.Owner.Username). WithRepo(DefaultGitPrj). WithState(&state). WithLimit(&maxSize). @@ -192,12 +192,12 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequest) *models.PullRequ transport.DefaultAuthentication) if err != nil { - h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %v", pr.Repo.Owner.Username, pr.Repo.Name, err) + h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %v", pr.Repository.Owner.Username, pr.Repository.Name, err) return nil } if !prs.IsSuccess() { - h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %s", pr.Repo.Owner.Username, pr.Repo.Name, prs.Error()) + h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %s", pr.Repository.Owner.Username, pr.Repository.Name, prs.Error()) } payload_processing: diff --git a/bots-common/request_pr.go b/bots-common/request_pr.go index cfd4348..92b9784 100644 --- a/bots-common/request_pr.go +++ b/bots-common/request_pr.go @@ -22,7 +22,6 @@ type PullRequest struct { Labels []string Head Head - Repo Repository User User } diff --git a/bots-common/request_pr_test.go b/bots-common/request_pr_test.go index b41efe4..92b91fa 100644 --- a/bots-common/request_pr_test.go +++ b/bots-common/request_pr_test.go @@ -14,6 +14,11 @@ func TestPrParsing(t *testing.T) { if pr == nil { t.Fatalf("parsing PR failed: %v", h.Error) } + + prs := h.parsePullRequest(strings.NewReader(samplePRsync_JSON)) + if prs == nil { + t.Fatalf("parsing PR failed: %v", h.Error) + } }) } @@ -651,3 +656,411 @@ const samplePR_JSON = `{ "review": null } ` + +const samplePRsync_JSON=`{ + "action": "synchronized", + "number": 1, + "pull_request": { + "id": 470, + "url": "https://src.opensuse.org/autogits/_ObsPrj/pulls/1", + "number": 1, + "user": { + "id": 129, + "login": "adamm", + "login_name": "", + "source_id": 0, + "full_name": "Adam Majer", + "email": "adamm@noreply@src.opensuse.org", + "avatar_url": "https://src.opensuse.org/avatar/babb6ae054a709c238a4e9b0f2b53d53", + "html_url": "https://src.opensuse.org/adamm", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-21T16:43:48+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "adamm" + }, + "title": "Forwarded PR: nodejs21", + "body": "This is a forwarded pull request by GiteaBot - AutoStaging\nreferencing the following pull request:\n\nPullRequest: nodejs21#1\n", + "labels": [], + "milestone": null, + "assignee": null, + "assignees": null, + "requested_reviewers": [ + { + "id": 1008, + "login": "autogits_obs_staging_bot", + "login_name": "", + "source_id": 0, + "full_name": "Autogits StagingBot", + "email": "autogits_obs_staging_bot@noreply@src.opensuse.org", + "avatar_url": "https://src.opensuse.org/avatar/b8f40091fbd0a1f1b9e54f539dcdc783", + "html_url": "https://src.opensuse.org/autogits_obs_staging_bot", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-07-06T14:31:34+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "autogits_obs_staging_bot" + } + ], + "state": "open", + "draft": false, + "is_locked": false, + "comments": 0, + "review_comments": 0, + "additions": 1, + "deletions": 1, + "changed_files": 1, + "html_url": "https://src.opensuse.org/autogits/_ObsPrj/pulls/1", + "diff_url": "https://src.opensuse.org/autogits/_ObsPrj/pulls/1.diff", + "patch_url": "https://src.opensuse.org/autogits/_ObsPrj/pulls/1.patch", + "mergeable": false, + "merged": false, + "merged_at": null, + "merge_commit_sha": null, + "merged_by": null, + "allow_maintainer_edit": false, + "base": { + "label": "main", + "ref": "main", + "sha": "b20e37e05f14ba33d39444e297c455d2803998721a4e287099ae7cfb03ea6320", + "repo_id": 90487, + "repo": { + "id": 90487, + "owner": { + "id": 983, + "login": "autogits", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "", + "avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4", + "html_url": "https://src.opensuse.org/autogits", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-06-20T09:46:37+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "autogits" + }, + "name": "_ObsPrj", + "full_name": "autogits/_ObsPrj", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 47, + "language": "", + "languages_url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj/languages", + "html_url": "https://src.opensuse.org/autogits/_ObsPrj", + "url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj", + "link": "", + "ssh_url": "gitea@src.opensuse.org:autogits/_ObsPrj.git", + "clone_url": "https://src.opensuse.org/autogits/_ObsPrj.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 2, + "open_issues_count": 0, + "open_pr_counter": 1, + "release_counter": 0, + "default_branch": "main", + "archived": false, + "created_at": "2024-06-25T13:52:03+02:00", + "updated_at": "2024-07-10T11:25:22+02:00", + "archived_at": "1970-01-01T01:00:00+01:00", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": false, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": true, + "projects_mode": "all", + "has_releases": true, + "has_packages": true, + "has_actions": true, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "allow_fast_forward_only_merge": true, + "allow_rebase_update": true, + "default_delete_branch_after_merge": false, + "default_merge_style": "merge", + "default_allow_maintainer_edit": false, + "avatar_url": "https://src.opensuse.org/", + "internal": false, + "mirror_interval": "", + "object_format_name": "sha256", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": null + } + }, + "head": { + "label": "PR_nodejs21#1", + "ref": "PR_nodejs21#1", + "sha": "3cd37fb6b93c0af07c50c8caa075bbdd1c1202991898ca61482e3cb019a97403", + "repo_id": 90487, + "repo": { + "id": 90487, + "owner": { + "id": 983, + "login": "autogits", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "", + "avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4", + "html_url": "https://src.opensuse.org/autogits", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-06-20T09:46:37+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "autogits" + }, + "name": "_ObsPrj", + "full_name": "autogits/_ObsPrj", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 47, + "language": "", + "languages_url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj/languages", + "html_url": "https://src.opensuse.org/autogits/_ObsPrj", + "url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj", + "link": "", + "ssh_url": "gitea@src.opensuse.org:autogits/_ObsPrj.git", + "clone_url": "https://src.opensuse.org/autogits/_ObsPrj.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 2, + "open_issues_count": 0, + "open_pr_counter": 1, + "release_counter": 0, + "default_branch": "main", + "archived": false, + "created_at": "2024-06-25T13:52:03+02:00", + "updated_at": "2024-07-10T11:25:22+02:00", + "archived_at": "1970-01-01T01:00:00+01:00", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": false, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": true, + "projects_mode": "all", + "has_releases": true, + "has_packages": true, + "has_actions": true, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "allow_fast_forward_only_merge": true, + "allow_rebase_update": true, + "default_delete_branch_after_merge": false, + "default_merge_style": "merge", + "default_allow_maintainer_edit": false, + "avatar_url": "https://src.opensuse.org/", + "internal": false, + "mirror_interval": "", + "object_format_name": "sha256", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": null + } + }, + "merge_base": "b20e37e05f14ba33d39444e297c455d2803998721a4e287099ae7cfb03ea6320", + "due_date": "0001-01-01T00:53:28+00:53", + "created_at": "2024-07-10T11:42:27+02:00", + "updated_at": "2024-07-10T11:42:28+02:00", + "closed_at": null, + "pin_order": 0 + }, + "requested_reviewer": null, + "repository": { + "id": 90487, + "owner": { + "id": 983, + "login": "autogits", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "", + "avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4", + "html_url": "https://src.opensuse.org/autogits", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-06-20T09:46:37+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "autogits" + }, + "name": "_ObsPrj", + "full_name": "autogits/_ObsPrj", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 47, + "language": "", + "languages_url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj/languages", + "html_url": "https://src.opensuse.org/autogits/_ObsPrj", + "url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj", + "link": "", + "ssh_url": "gitea@src.opensuse.org:autogits/_ObsPrj.git", + "clone_url": "https://src.opensuse.org/autogits/_ObsPrj.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 2, + "open_issues_count": 0, + "open_pr_counter": 1, + "release_counter": 0, + "default_branch": "main", + "archived": false, + "created_at": "2024-06-25T13:52:03+02:00", + "updated_at": "2024-07-10T11:42:28+02:00", + "archived_at": "1970-01-01T01:00:00+01:00", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": false, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": true, + "projects_mode": "all", + "has_releases": true, + "has_packages": true, + "has_actions": true, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "allow_fast_forward_only_merge": true, + "allow_rebase_update": true, + "default_delete_branch_after_merge": false, + "default_merge_style": "merge", + "default_allow_maintainer_edit": false, + "avatar_url": "https://src.opensuse.org/", + "internal": false, + "mirror_interval": "", + "object_format_name": "sha256", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": null + }, + "sender": { + "id": 129, + "login": "adamm", + "login_name": "", + "source_id": 0, + "full_name": "Adam Majer", + "email": "adamm@noreply@src.opensuse.org", + "avatar_url": "https://src.opensuse.org/avatar/babb6ae054a709c238a4e9b0f2b53d53", + "html_url": "https://src.opensuse.org/adamm", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-21T16:43:48+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "adamm" + }, + "commit_id": "", + "review": null +} +` diff --git a/pr-review/main.go b/pr-review/main.go index 946d8e0..bd2b7d7 100644 --- a/pr-review/main.go +++ b/pr-review/main.go @@ -18,7 +18,7 @@ func processPullRequestSync(h *common.RequestHandler) error { req := h.Data.(*common.PullRequestAction) // find prjgit pull request associated with this one - h.GetAssociatedPrjGitPR(&req.Pull_Request) + h.GetAssociatedPrjGitPR(req) return nil }