Skip to content

Commit

Permalink
fix: add pr Additions and Deletions (#7714)
Browse files Browse the repository at this point in the history
* fix: add pr Additions and Deletions

* fix: add pr Additions and Deletions

* fix: e2e test

* fix: e2e test

* fix: gitlab e2e

* fix: migration conflict

* fix: lint
  • Loading branch information
abeizn committed Jul 12, 2024
1 parent 68a19ed commit 469e773
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 73 deletions.
2 changes: 2 additions & 0 deletions backend/core/models/domainlayer/code/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 {
Expand Down
53 changes: 53 additions & 0 deletions backend/core/models/migrationscripts/20240710_add_changes_to_pr.go
Original file line number Diff line number Diff line change
@@ -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 prChange20240710 struct {
Additions int
Deletions int
}

func (prChange20240710) TableName() string {
return "pull_requests"
}

type addChangesToPr struct{}

func (*addChangesToPr) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
if err := db.AutoMigrate(&prChange20240710{}); err != nil {
return err
}
return nil
}

func (*addChangesToPr) Version() uint64 {
return 20240710142100
}

func (*addChangesToPr) Name() string {
return "add additions and deletions to pr"
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func All() []plugin.MigrationScript {
new(modifyCicdPipelineCommitsRepoUrlLength),
new(addPrAssigneeAndReviewer),
new(modifyPrAssigneeAndReviewerId),
new(addChangesToPr),
new(addMergedByToPr),
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,base_repo_id,head_repo_id,status,original_status,title,description,url,author_name,author_id,parent_pr_id,pull_request_key,created_date,merged_date,closed_date,type,component,merge_commit_sha,head_ref,base_ref,base_commit_sha,head_commit_sha
azuredevops_go:AzuredevopsPullRequest:1:1,azuredevops_go:AzuredevopsRepo:1:0d50ba13-f9ad-49b0-9b21-d29eda50ca33,azuredevops_go:AzuredevopsRepo:1:0d50ba13-f9ad-49b0-9b21-d29eda50ca33,OPEN,OPEN,ticket-2PR,Updatedmain.javabyticket-2,https://dev.azure.com/johndoe/7a3fd40e-2aed-4fac-bac9-511bf1a70206/_apis/git/repositories/0d50ba13-f9ad-49b0-9b21-d29eda50ca33/pullRequests/1,JohnDoe,azuredevops_go:AzuredevopsUser:1:bc538feb-9fdd-6cf8-80e1-7c56950d0289,,1,2023-02-07T04:41:26.642+00:00,,"",,,ebc6c7a2a5e3c155510d0ba44fd4385bf7ae6e22,refs/heads/ticket-2,refs/heads/main,4bc26d92b5dbee7837a4d221035a4e2f8df120b2,85ede91717145a1e6e2bdab4cab689ac8f2fa3a2
id,base_repo_id,head_repo_id,status,original_status,title,description,url,author_name,author_id,parent_pr_id,pull_request_key,created_date,merged_date,closed_date,type,component,merge_commit_sha,head_ref,base_ref,base_commit_sha,head_commit_sha,additions,deletions
azuredevops_go:AzuredevopsPullRequest:1:1,azuredevops_go:AzuredevopsRepo:1:0d50ba13-f9ad-49b0-9b21-d29eda50ca33,azuredevops_go:AzuredevopsRepo:1:0d50ba13-f9ad-49b0-9b21-d29eda50ca33,OPEN,OPEN,ticket-2PR,Updatedmain.javabyticket-2,https://dev.azure.com/johndoe/7a3fd40e-2aed-4fac-bac9-511bf1a70206/_apis/git/repositories/0d50ba13-f9ad-49b0-9b21-d29eda50ca33/pullRequests/1,JohnDoe,azuredevops_go:AzuredevopsUser:1:bc538feb-9fdd-6cf8-80e1-7c56950d0289,,1,2023-02-07T04:41:26.642+00:00,,,,,ebc6c7a2a5e3c155510d0ba44fd4385bf7ae6e22,refs/heads/ticket-2,refs/heads/main,4bc26d92b5dbee7837a4d221035a4e2f8df120b2,85ede91717145a1e6e2bdab4cab689ac8f2fa3a2,0,0
2 changes: 2 additions & 0 deletions backend/plugins/github/e2e/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func TestPrDataFlow(t *testing.T) {
"base_ref",
"base_commit_sha",
"head_commit_sha",
"additions",
"deletions",
"_raw_data_params",
"_raw_data_table",
"_raw_data_id",
Expand Down

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions backend/plugins/github/e2e/snapshot_tables/pull_requests.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/plugins/github/tasks/pr_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
MergedByName: pr.MergedByName,
MergedById: accountIdGen.Generate(data.Options.ConnectionId, pr.MergedById),
}
Expand Down
2 changes: 2 additions & 0 deletions backend/plugins/github_graphql/tasks/pr_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type GraphqlQueryPr struct {
TotalCount graphql.Int
Nodes []GraphqlQueryReview `graphql:"nodes"`
} `graphql:"reviews(first: 100)"`
Additions int
Deletions int
MergedBy *GraphqlInlineAccountQuery
ReviewRequests struct {
Nodes []ReviewRequestNode `graphql:"nodes"`
Expand Down
2 changes: 2 additions & 0 deletions backend/plugins/github_graphql/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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.MergedBy != nil {
githubPull.MergedByName = pull.MergedBy.Login
Expand Down
Loading

0 comments on commit 469e773

Please sign in to comment.