This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch add-pr-changes
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/add-pr-changes by this push:
new 51304215c fix: add pr Additions and Deletions
51304215c is described below
commit 51304215c58ccc708b9ad4f24a290f95c71fdbed
Author: abeizn <[email protected]>
AuthorDate: Wed Jul 10 14:41:16 2024 +0800
fix: add pr Additions and Deletions
---
.../core/models/domainlayer/code/pull_request.go | 5 +-
.../migrationscripts/20240710_add_changes_to_pr.go | 53 +++++++++++
backend/core/models/migrationscripts/register.go | 1 +
backend/plugins/github/tasks/pr_convertor.go | 2 +
backend/plugins/github_graphql/impl/impl.go | 102 ++++++++++-----------
.../plugins/github_graphql/tasks/pr_collector.go | 2 +
.../plugins/github_graphql/tasks/pr_extractor.go | 5 +-
7 files changed, 115 insertions(+), 55 deletions(-)
diff --git a/backend/core/models/domainlayer/code/pull_request.go
b/backend/core/models/domainlayer/code/pull_request.go
index 0c3be7f8d..840aad3fe 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"
)
@@ -55,6 +56,8 @@ type PullRequest struct {
BaseRef string `gorm:"type:varchar(255)"`
BaseCommitSha string `gorm:"type:varchar(40)"`
HeadCommitSha string `gorm:"type:varchar(40)"`
+ Additions int
+ Deletions int
}
func (PullRequest) TableName() string {
diff --git a/backend/core/models/migrationscripts/20240710_add_changes_to_pr.go
b/backend/core/models/migrationscripts/20240710_add_changes_to_pr.go
new file mode 100644
index 000000000..0e56579e1
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240710_add_changes_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 = (*addChangesToPr)(nil)
+
+type pr20240710 struct {
+ Additions int
+ Deletions int
+}
+
+func (pr20240710) TableName() string {
+ return "pull_requests"
+}
+
+type addChangesToPr struct{}
+
+func (*addChangesToPr) Up(basicRes context.BasicRes) errors.Error {
+ db := basicRes.GetDal()
+ if err := db.AutoMigrate(&pr20240710{}); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (*addChangesToPr) Version() uint64 {
+ return 20240710142100
+}
+
+func (*addChangesToPr) Name() string {
+ return "add additions and deletions to pr"
+}
diff --git a/backend/core/models/migrationscripts/register.go
b/backend/core/models/migrationscripts/register.go
index 6caa89677..afb5ebeda 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(addChangesToPr),
}
}
diff --git a/backend/plugins/github/tasks/pr_convertor.go
b/backend/plugins/github/tasks/pr_convertor.go
index 6f7250127..d3272eb3f 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,
+ Additions: pr.Additions,
+ Deletions: pr.Deletions,
}
if pr.State == "open" || pr.State == "OPEN" {
domainPr.Status = code.OPEN
diff --git a/backend/plugins/github_graphql/impl/impl.go
b/backend/plugins/github_graphql/impl/impl.go
index 8045cd145..cc1733858 100644
--- a/backend/plugins/github_graphql/impl/impl.go
+++ b/backend/plugins/github_graphql/impl/impl.go
@@ -81,62 +81,62 @@ func (p GithubGraphql) GetTablesInfo() []dal.Tabler {
func (p GithubGraphql) SubTaskMetas() []plugin.SubTaskMeta {
return []plugin.SubTaskMeta{
- // collect millstones
- githubTasks.CollectMilestonesMeta,
- githubTasks.ExtractMilestonesMeta,
+ // // collect millstones
+ // githubTasks.CollectMilestonesMeta,
+ // githubTasks.ExtractMilestonesMeta,
- // collect issue & pr, deps on millstone
- tasks.CollectIssuesMeta,
- tasks.ExtractIssuesMeta,
+ // // collect issue & pr, deps on millstone
+ // tasks.CollectIssuesMeta,
+ // tasks.ExtractIssuesMeta,
tasks.CollectPrsMeta,
tasks.ExtractPrsMeta,
- // collect workflow run & job
- githubTasks.CollectRunsMeta,
- githubTasks.ExtractRunsMeta,
- tasks.CollectJobsMeta,
- tasks.ExtractJobsMeta,
-
- // collect others
- githubTasks.CollectApiCommentsMeta,
- githubTasks.ExtractApiCommentsMeta,
- githubTasks.CollectApiEventsMeta,
- githubTasks.ExtractApiEventsMeta,
- githubTasks.CollectApiPrReviewCommentsMeta,
- githubTasks.ExtractApiPrReviewCommentsMeta,
-
- // collect account, deps on all before
- tasks.CollectAccountMeta,
- tasks.ExtractAccountsMeta,
-
- // convert to domain layer
- githubTasks.ConvertRunsMeta,
- githubTasks.ConvertJobsMeta,
- githubTasks.EnrichPullRequestIssuesMeta,
- githubTasks.ConvertRepoMeta,
- githubTasks.ConvertIssuesMeta,
- githubTasks.ConvertCommitsMeta,
- githubTasks.ConvertIssueLabelsMeta,
- githubTasks.ConvertPullRequestCommitsMeta,
+ // // collect workflow run & job
+ // githubTasks.CollectRunsMeta,
+ // githubTasks.ExtractRunsMeta,
+ // tasks.CollectJobsMeta,
+ // tasks.ExtractJobsMeta,
+
+ // // collect others
+ // githubTasks.CollectApiCommentsMeta,
+ // githubTasks.ExtractApiCommentsMeta,
+ // githubTasks.CollectApiEventsMeta,
+ // githubTasks.ExtractApiEventsMeta,
+ // githubTasks.CollectApiPrReviewCommentsMeta,
+ // githubTasks.ExtractApiPrReviewCommentsMeta,
+
+ // // collect account, deps on all before
+ // tasks.CollectAccountMeta,
+ // tasks.ExtractAccountsMeta,
+
+ // // convert to domain layer
+ // githubTasks.ConvertRunsMeta,
+ // githubTasks.ConvertJobsMeta,
+ // githubTasks.EnrichPullRequestIssuesMeta,
+ // githubTasks.ConvertRepoMeta,
+ // githubTasks.ConvertIssuesMeta,
+ // githubTasks.ConvertCommitsMeta,
+ // githubTasks.ConvertIssueLabelsMeta,
+ // githubTasks.ConvertPullRequestCommitsMeta,
githubTasks.ConvertPullRequestsMeta,
- githubTasks.ConvertPullRequestReviewsMeta,
- githubTasks.ConvertPullRequestLabelsMeta,
- githubTasks.ConvertPullRequestIssuesMeta,
- githubTasks.ConvertIssueAssigneeMeta,
- githubTasks.ConvertIssueCommentsMeta,
- githubTasks.ConvertPullRequestCommentsMeta,
- githubTasks.ConvertMilestonesMeta,
- githubTasks.ConvertAccountsMeta,
-
- // deployment
- tasks.CollectDeploymentsMeta,
- tasks.ExtractDeploymentsMeta,
- tasks.ConvertDeploymentsMeta,
-
- // releases
- tasks.CollectReleaseMeta,
- tasks.ExtractReleasesMeta,
- githubTasks.ConvertReleasesMeta,
+ // githubTasks.ConvertPullRequestReviewsMeta,
+ // githubTasks.ConvertPullRequestLabelsMeta,
+ // githubTasks.ConvertPullRequestIssuesMeta,
+ // githubTasks.ConvertIssueAssigneeMeta,
+ // githubTasks.ConvertIssueCommentsMeta,
+ // githubTasks.ConvertPullRequestCommentsMeta,
+ // githubTasks.ConvertMilestonesMeta,
+ // githubTasks.ConvertAccountsMeta,
+
+ // // deployment
+ // tasks.CollectDeploymentsMeta,
+ // tasks.ExtractDeploymentsMeta,
+ // tasks.ConvertDeploymentsMeta,
+
+ // // releases
+ // tasks.CollectReleaseMeta,
+ // tasks.ExtractReleasesMeta,
+ // githubTasks.ConvertReleasesMeta,
}
}
diff --git a/backend/plugins/github_graphql/tasks/pr_collector.go
b/backend/plugins/github_graphql/tasks/pr_collector.go
index 903ce6c5b..3f86582a6 100644
--- a/backend/plugins/github_graphql/tasks/pr_collector.go
+++ b/backend/plugins/github_graphql/tasks/pr_collector.go
@@ -85,6 +85,8 @@ type GraphqlQueryPr struct {
TotalCount graphql.Int
Nodes []GraphqlQueryReview `graphql:"nodes"`
} `graphql:"reviews(first: 100)"`
+ Additions int
+ Deletions int
}
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..030161ef2 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)
}
@@ -173,6 +170,8 @@ func convertGithubPullRequest(pull GraphqlQueryPr, connId
uint64, repoId int) (*
BaseCommitSha: pull.BaseRefOid,
HeadRef: pull.HeadRefName,
HeadCommitSha: pull.HeadRefOid,
+ Additions: pull.Additions,
+ Deletions: pull.Deletions,
}
if pull.MergeCommit != nil {
githubPull.MergeCommitSha = pull.MergeCommit.Oid