Skip to content

Commit 483c93e

Browse files
feat: bitbucket add merge by field (#7756) (#7789)
* feat: bitbucket add merge by field * feat: bitbucket add merge by field Co-authored-by: abeizn <zikuan.an@merico.dev>
1 parent ff41749 commit 483c93e

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
)
25+
26+
var _ plugin.MigrationScript = (*addMergedByToPr)(nil)
27+
28+
type pr20240710 struct {
29+
MergedByName string `gorm:"type:varchar(100)"`
30+
MergedById string `gorm:"type:varchar(100)"`
31+
}
32+
33+
func (pr20240710) TableName() string {
34+
return "_tool_bitbucket_pull_requests"
35+
}
36+
37+
type addMergedByToPr struct{}
38+
39+
func (*addMergedByToPr) Up(basicRes context.BasicRes) errors.Error {
40+
db := basicRes.GetDal()
41+
if err := db.AutoMigrate(&pr20240710{}); err != nil {
42+
return err
43+
}
44+
return nil
45+
}
46+
47+
func (*addMergedByToPr) Version() uint64 {
48+
return 20240717142100
49+
}
50+
51+
func (*addMergedByToPr) Name() string {
52+
return "add merged by to _tool_bitbucket_pull_requests"
53+
}

backend/plugins/bitbucket/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ func All() []plugin.MigrationScript {
4040
new(addRawParamTableForScope),
4141
new(addBuildNumberToPipelines),
4242
new(reCreatBitBucketPipelineSteps),
43+
new(addMergedByToPr),
4344
}
4445
}

backend/plugins/bitbucket/models/pr.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ limitations under the License.
1818
package models
1919

2020
import (
21-
"github.com/apache/incubator-devlake/core/models/common"
2221
"time"
22+
23+
"github.com/apache/incubator-devlake/core/models/common"
2324
)
2425

2526
type BitbucketPullRequest struct {
@@ -49,6 +50,8 @@ type BitbucketPullRequest struct {
4950
Url string `gorm:"type:varchar(255)"`
5051
AuthorName string `gorm:"type:varchar(255)"`
5152
AuthorId string `gorm:"type:varchar(255)"`
53+
MergedByName string `gorm:"type:varchar(100)"`
54+
MergedById string `gorm:"type:varchar(100)"`
5255
common.NoPKModel
5356
}
5457

backend/plugins/bitbucket/tasks/pr_collector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func CollectApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
4949
UrlTemplate: "repositories/{{ .Params.FullName }}/pullrequests",
5050
Query: GetQueryCreatedAndUpdated(
5151
`values.id,values.comment_count,values.type,values.state,values.title,values.description,`+
52+
`values.closed_by.display_name,values.closed_by.account_id,`+
5253
`values.merge_commit.hash,values.merge_commit.date,values.links.html,values.author,values.created_on,values.updated_on,`+
5354
`values.destination.branch.name,values.destination.commit.hash,values.destination.repository.full_name,`+
5455
`values.source.branch.name,values.source.commit.hash,values.source.repository.full_name,`+

backend/plugins/bitbucket/tasks/pr_convertor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
8686
BaseCommitSha: pr.BaseCommitSha,
8787
HeadRef: pr.HeadRef,
8888
HeadCommitSha: pr.HeadCommitSha,
89+
MergedByName: pr.MergedByName,
8990
}
9091
switch pr.State {
9192
case "OPEN":
@@ -97,6 +98,9 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
9798
default:
9899
domainPr.Status = pr.State
99100
}
101+
if pr.MergedById != "" && pr.State == "MERGED" {
102+
domainPr.MergedById = domainUserIdGen.Generate(data.Options.ConnectionId, pr.MergedById)
103+
}
100104

101105
return []interface{}{
102106
domainPr,

backend/plugins/bitbucket/tasks/pr_extractor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type BitbucketApiPullRequest struct {
5555
Href string `json:"href"`
5656
} `json:"html"`
5757
} `json:"links"`
58-
//ClosedBy *BitbucketAccountResponse `json:"closed_by"`
58+
ClosedBy *BitbucketAccountResponse `json:"closed_by"`
5959
Author *BitbucketAccountResponse `json:"author"`
6060
BitbucketCreatedAt time.Time `json:"created_on"`
6161
BitbucketUpdatedAt time.Time `json:"updated_on"`
@@ -154,5 +154,10 @@ func convertBitbucketPullRequest(pull *BitbucketApiPullRequest, connId uint64, r
154154
bitbucketPull.HeadRef = pull.HeadRef.Branch.Name
155155
bitbucketPull.HeadCommitSha = pull.HeadRef.Commit.Hash
156156
}
157+
if pull.ClosedBy != nil {
158+
bitbucketPull.MergedByName = pull.ClosedBy.DisplayName
159+
bitbucketPull.MergedById = pull.ClosedBy.AccountId
160+
}
161+
157162
return bitbucketPull, nil
158163
}

0 commit comments

Comments
 (0)