Skip to content

Commit

Permalink
feat: bitbucket add merge by field (#7756) (#7789)
Browse files Browse the repository at this point in the history
* feat: bitbucket add merge by field

* feat: bitbucket add merge by field

Co-authored-by: abeizn <zikuan.an@merico.dev>
  • Loading branch information
github-actions[bot] and abeizn committed Jul 25, 2024
1 parent ff41749 commit 483c93e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
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 = (*addMergedByToPr)(nil)

type pr20240710 struct {
MergedByName string `gorm:"type:varchar(100)"`
MergedById string `gorm:"type:varchar(100)"`
}

func (pr20240710) TableName() string {
return "_tool_bitbucket_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 20240717142100
}

func (*addMergedByToPr) Name() string {
return "add merged by to _tool_bitbucket_pull_requests"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ func All() []plugin.MigrationScript {
new(addRawParamTableForScope),
new(addBuildNumberToPipelines),
new(reCreatBitBucketPipelineSteps),
new(addMergedByToPr),
}
}
5 changes: 4 additions & 1 deletion backend/plugins/bitbucket/models/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 BitbucketPullRequest struct {
Expand Down Expand Up @@ -49,6 +50,8 @@ type BitbucketPullRequest struct {
Url string `gorm:"type:varchar(255)"`
AuthorName string `gorm:"type:varchar(255)"`
AuthorId string `gorm:"type:varchar(255)"`
MergedByName string `gorm:"type:varchar(100)"`
MergedById string `gorm:"type:varchar(100)"`
common.NoPKModel
}

Expand Down
1 change: 1 addition & 0 deletions backend/plugins/bitbucket/tasks/pr_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func CollectApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
UrlTemplate: "repositories/{{ .Params.FullName }}/pullrequests",
Query: GetQueryCreatedAndUpdated(
`values.id,values.comment_count,values.type,values.state,values.title,values.description,`+
`values.closed_by.display_name,values.closed_by.account_id,`+
`values.merge_commit.hash,values.merge_commit.date,values.links.html,values.author,values.created_on,values.updated_on,`+
`values.destination.branch.name,values.destination.commit.hash,values.destination.repository.full_name,`+
`values.source.branch.name,values.source.commit.hash,values.source.repository.full_name,`+
Expand Down
4 changes: 4 additions & 0 deletions backend/plugins/bitbucket/tasks/pr_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
BaseCommitSha: pr.BaseCommitSha,
HeadRef: pr.HeadRef,
HeadCommitSha: pr.HeadCommitSha,
MergedByName: pr.MergedByName,
}
switch pr.State {
case "OPEN":
Expand All @@ -97,6 +98,9 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
default:
domainPr.Status = pr.State
}
if pr.MergedById != "" && pr.State == "MERGED" {
domainPr.MergedById = domainUserIdGen.Generate(data.Options.ConnectionId, pr.MergedById)
}

return []interface{}{
domainPr,
Expand Down
7 changes: 6 additions & 1 deletion backend/plugins/bitbucket/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type BitbucketApiPullRequest struct {
Href string `json:"href"`
} `json:"html"`
} `json:"links"`
//ClosedBy *BitbucketAccountResponse `json:"closed_by"`
ClosedBy *BitbucketAccountResponse `json:"closed_by"`
Author *BitbucketAccountResponse `json:"author"`
BitbucketCreatedAt time.Time `json:"created_on"`
BitbucketUpdatedAt time.Time `json:"updated_on"`
Expand Down Expand Up @@ -154,5 +154,10 @@ func convertBitbucketPullRequest(pull *BitbucketApiPullRequest, connId uint64, r
bitbucketPull.HeadRef = pull.HeadRef.Branch.Name
bitbucketPull.HeadCommitSha = pull.HeadRef.Commit.Hash
}
if pull.ClosedBy != nil {
bitbucketPull.MergedByName = pull.ClosedBy.DisplayName
bitbucketPull.MergedById = pull.ClosedBy.AccountId
}

return bitbucketPull, nil
}

0 comments on commit 483c93e

Please sign in to comment.