This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch add-github-request-reviewer
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/add-github-request-reviewer by
this push:
new 776fe755d feat: add pr merge by field
776fe755d is described below
commit 776fe755d77e6627145f8d7867204049f5fbc03d
Author: abeizn <[email protected]>
AuthorDate: Wed Jul 10 19:31:21 2024 +0800
feat: add pr merge by field
---
.../core/models/domainlayer/code/pull_request.go | 5 +-
.../20240710_add_merge_by_to_pr.go | 53 ++++++++++++++++++++++
backend/core/models/migrationscripts/register.go | 1 +
.../20240710_add_merge_by_to_pr.go | 53 ++++++++++++++++++++++
.../github/models/migrationscripts/register.go | 1 +
backend/plugins/github/models/pr.go | 5 +-
backend/plugins/github/tasks/pr_convertor.go | 2 +
.../plugins/github_graphql/tasks/pr_collector.go | 1 +
.../plugins/github_graphql/tasks/pr_extractor.go | 7 +--
9 files changed, 123 insertions(+), 5 deletions(-)
diff --git a/backend/core/models/domainlayer/code/pull_request.go
b/backend/core/models/domainlayer/code/pull_request.go
index 0c3be7f8d..1c63df50f 100644
--- a/backend/core/models/domainlayer/code/pull_request.go
+++ b/backend/core/models/domainlayer/code/pull_request.go
@@ -19,9 +19,10 @@ package code
import (
"fmt"
- "github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
"time"
+ "github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
+
"github.com/apache/incubator-devlake/core/models/domainlayer"
)
@@ -43,6 +44,8 @@ type PullRequest struct {
AuthorName string `gorm:"type:varchar(100)"`
//User domainUser.User `gorm:"foreignKey:AuthorId"`
AuthorId string `gorm:"type:varchar(100)"`
+ MergedByName string `gorm:"type:varchar(100)"`
+ MergedById string `gorm:"type:varchar(100)"`
ParentPrId string `gorm:"index;type:varchar(100)"`
PullRequestKey int
CreatedDate time.Time
diff --git
a/backend/core/models/migrationscripts/20240710_add_merge_by_to_pr.go
b/backend/core/models/migrationscripts/20240710_add_merge_by_to_pr.go
new file mode 100644
index 000000000..ab24d9ecb
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240710_add_merge_by_to_pr.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+)
+
+var _ plugin.MigrationScript = (*addMergedByToPr)(nil)
+
+type pr20240710 struct {
+ MergedByName string `gorm:"type:varchar(100)"`
+ MergedById string `gorm:"type:varchar(100)"`
+}
+
+func (pr20240710) TableName() string {
+ return "pull_requests"
+}
+
+type addMergedByToPr struct{}
+
+func (*addMergedByToPr) Up(basicRes context.BasicRes) errors.Error {
+ db := basicRes.GetDal()
+ if err := db.AutoMigrate(&pr20240710{}); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (*addMergedByToPr) Version() uint64 {
+ return 20240710142101
+}
+
+func (*addMergedByToPr) Name() string {
+ return "add merged by to pull_requests"
+}
diff --git a/backend/core/models/migrationscripts/register.go
b/backend/core/models/migrationscripts/register.go
index 6caa89677..0ce4680ce 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -125,5 +125,6 @@ func All() []plugin.MigrationScript {
new(addPullRequestIdIndexToPullRequestComments),
new(initIncidentRelatedTables),
new(renameProjectIssueMetrics),
+ new(addMergedByToPr),
}
}
diff --git
a/backend/plugins/github/models/migrationscripts/20240710_add_merge_by_to_pr.go
b/backend/plugins/github/models/migrationscripts/20240710_add_merge_by_to_pr.go
new file mode 100644
index 000000000..6c65eadb0
--- /dev/null
+++
b/backend/plugins/github/models/migrationscripts/20240710_add_merge_by_to_pr.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+)
+
+var _ plugin.MigrationScript = (*addMergedByToPr)(nil)
+
+type pr20240710 struct {
+ MergedByName string `gorm:"type:varchar(100)"`
+ MergedById int
+}
+
+func (pr20240710) TableName() string {
+ return "_tool_github_pull_requests"
+}
+
+type addMergedByToPr struct{}
+
+func (*addMergedByToPr) Up(basicRes context.BasicRes) errors.Error {
+ db := basicRes.GetDal()
+ if err := db.AutoMigrate(&pr20240710{}); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (*addMergedByToPr) Version() uint64 {
+ return 20240710142100
+}
+
+func (*addMergedByToPr) Name() string {
+ return "add merged by to _tool_github_pull_requests"
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go
b/backend/plugins/github/models/migrationscripts/register.go
index 496f54544..35ad1b1dc 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/register.go
@@ -50,5 +50,6 @@ func All() []plugin.MigrationScript {
new(addWorkflowDisplayTitle),
new(addReleaseTable),
new(addReleaseCommitSha),
+ new(addMergedByToPr),
}
}
diff --git a/backend/plugins/github/models/pr.go
b/backend/plugins/github/models/pr.go
index bd2e15d0d..b8e8fa78a 100644
--- a/backend/plugins/github/models/pr.go
+++ b/backend/plugins/github/models/pr.go
@@ -18,8 +18,9 @@ limitations under the License.
package models
import (
- "github.com/apache/incubator-devlake/core/models/common"
"time"
+
+ "github.com/apache/incubator-devlake/core/models/common"
)
type GithubPullRequest struct {
@@ -52,6 +53,8 @@ type GithubPullRequest struct {
Url string `gorm:"type:varchar(255)"`
AuthorName string `gorm:"type:varchar(100)"`
AuthorId int
+ MergedByName string `gorm:"type:varchar(100)"`
+ MergedById int
common.NoPKModel
}
diff --git a/backend/plugins/github/tasks/pr_convertor.go
b/backend/plugins/github/tasks/pr_convertor.go
index 6f7250127..da935c300 100644
--- a/backend/plugins/github/tasks/pr_convertor.go
+++ b/backend/plugins/github/tasks/pr_convertor.go
@@ -102,6 +102,8 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext)
errors.Error {
BaseCommitSha: pr.BaseCommitSha,
HeadRef: pr.HeadRef,
HeadCommitSha: pr.HeadCommitSha,
+ MergedByName: pr.MergedByName,
+ MergedById:
accountIdGen.Generate(data.Options.ConnectionId, pr.MergedById),
}
if pr.State == "open" || pr.State == "OPEN" {
domainPr.Status = code.OPEN
diff --git a/backend/plugins/github_graphql/tasks/pr_collector.go
b/backend/plugins/github_graphql/tasks/pr_collector.go
index 903ce6c5b..82e5da69a 100644
--- a/backend/plugins/github_graphql/tasks/pr_collector.go
+++ b/backend/plugins/github_graphql/tasks/pr_collector.go
@@ -85,6 +85,7 @@ type GraphqlQueryPr struct {
TotalCount graphql.Int
Nodes []GraphqlQueryReview `graphql:"nodes"`
} `graphql:"reviews(first: 100)"`
+ MergedBy *GraphqlInlineAccountQuery
}
type GraphqlQueryReview struct {
diff --git a/backend/plugins/github_graphql/tasks/pr_extractor.go
b/backend/plugins/github_graphql/tasks/pr_extractor.go
index c82975fc8..163fa4c84 100644
--- a/backend/plugins/github_graphql/tasks/pr_extractor.go
+++ b/backend/plugins/github_graphql/tasks/pr_extractor.go
@@ -137,9 +137,6 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error
{
CommitAuthorEmail:
githubCommit.AuthorEmail,
CommitAuthoredDate:
githubCommit.AuthoredDate,
}
- if err != nil {
- return nil, err
- }
results = append(results,
githubPullRequestCommit)
extractGraphqlPreAccount(&results,
apiPullRequestCommit.Commit.Author.User, data.Options.GithubId,
data.Options.ConnectionId)
}
@@ -174,6 +171,10 @@ func convertGithubPullRequest(pull GraphqlQueryPr, connId
uint64, repoId int) (*
HeadRef: pull.HeadRefName,
HeadCommitSha: pull.HeadRefOid,
}
+ if pull.MergedBy != nil {
+ githubPull.MergedByName = pull.MergedBy.Login
+ githubPull.MergedById = pull.MergedBy.Id
+ }
if pull.MergeCommit != nil {
githubPull.MergeCommitSha = pull.MergeCommit.Oid
}