From 01620be206ac88501758dd0500a77e35e2e3cf27 Mon Sep 17 00:00:00 2001 From: warrenchen <703288221@qq.com> Date: Mon, 21 Feb 2022 21:39:54 +0800 Subject: [PATCH] feat(github): add pr fields Closes #1256 --- models/domainlayer/code/pull_request.go | 4 ++++ plugins/github/github.go | 4 ++-- plugins/github/models/github_pull_request.go | 4 ++++ .../github/tasks/github_pull_request_collector.go | 12 ++++++++++++ .../github/tasks/github_pull_request_converter.go | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/models/domainlayer/code/pull_request.go b/models/domainlayer/code/pull_request.go index 5c05b1330d5..62207f19a95 100644 --- a/models/domainlayer/code/pull_request.go +++ b/models/domainlayer/code/pull_request.go @@ -18,4 +18,8 @@ type PullRequest struct { Type string Component string MergeCommitSha string `gorm:"type:char(40)"` + HeadRef string + BaseRef string + BaseCommitSha string + HeadCommitSha string } diff --git a/plugins/github/github.go b/plugins/github/github.go index af205864e10..0d56ccaef8e 100644 --- a/plugins/github/github.go +++ b/plugins/github/github.go @@ -420,11 +420,11 @@ func main() { //"collectPullRequestCommits", //"collectPullRequestComments", //"enrichIssues", - //"enrichPullRequests", + "enrichPullRequests", //"convertRepos", //"convertIssues", //"convertIssueLabels", - //"convertPullRequests", + "convertPullRequests", //"convertPullRequestLabels", //"convertCommits", //"convertPullRequestCommits", diff --git a/plugins/github/models/github_pull_request.go b/plugins/github/models/github_pull_request.go index d81a402f634..3e4b1b87839 100644 --- a/plugins/github/models/github_pull_request.go +++ b/plugins/github/models/github_pull_request.go @@ -26,5 +26,9 @@ type GithubPullRequest struct { Type string Component string MergeCommitSha string `gorm:"type:char(40)"` + HeadRef string + BaseRef string + BaseCommitSha string + HeadCommitSha string common.NoPKModel } diff --git a/plugins/github/tasks/github_pull_request_collector.go b/plugins/github/tasks/github_pull_request_collector.go index e042600ea7c..32fc87e8bf9 100644 --- a/plugins/github/tasks/github_pull_request_collector.go +++ b/plugins/github/tasks/github_pull_request_collector.go @@ -33,6 +33,14 @@ type GithubApiPullRequest struct { GithubCreatedAt core.Iso8601Time `json:"created_at"` GithubUpdatedAt *core.Iso8601Time `json:"updated_at"` MergeCommitSha string `json:"merge_commit_sha"` + Head struct { + Ref string + Sha string + } + Base struct { + Ref string + Sha string + } } func CollectPullRequests( @@ -106,6 +114,10 @@ func convertGithubPullRequest(pull *GithubApiPullRequest, repoId int) (*models.G ClosedAt: core.Iso8601TimeToTime(pull.ClosedAt), MergedAt: core.Iso8601TimeToTime(pull.MergedAt), MergeCommitSha: pull.MergeCommitSha, + BaseRef: pull.Base.Ref, + BaseCommitSha: pull.Base.Sha, + HeadRef: pull.Head.Ref, + HeadCommitSha: pull.Head.Sha, } return githubPull, nil } diff --git a/plugins/github/tasks/github_pull_request_converter.go b/plugins/github/tasks/github_pull_request_converter.go index 581d0fc7758..ff91d100961 100644 --- a/plugins/github/tasks/github_pull_request_converter.go +++ b/plugins/github/tasks/github_pull_request_converter.go @@ -53,6 +53,10 @@ func convertToPullRequestModel(pr *githubModels.GithubPullRequest, domainGenerat Type: pr.Type, Component: pr.Component, MergeCommitSha: pr.MergeCommitSha, + BaseRef: pr.BaseRef, + BaseCommitSha: pr.BaseCommitSha, + HeadRef: pr.HeadRef, + HeadCommitSha: pr.HeadCommitSha, } return domainPr }