Skip to content

Commit 5b70040

Browse files
committed
feat: decrease-otel-sample-rate
1 parent 5e82fcc commit 5b70040

File tree

8 files changed

+1023
-796
lines changed

8 files changed

+1023
-796
lines changed

backend/plugins/bitbucket/impl/impl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (p Bitbucket) GetTablesInfo() []dal.Tabler {
8080
&models.BitbucketDeployment{},
8181
&models.BitbucketPipelineStep{},
8282
&models.BitbucketPrCommit{},
83+
&models.BitbucketPrReviewer{},
8384
&models.BitbucketScopeConfig{},
8485
}
8586
}
@@ -125,6 +126,7 @@ func (p Bitbucket) SubTaskMetas() []plugin.SubTaskMeta {
125126
tasks.ConvertRepoMeta,
126127
tasks.ConvertAccountsMeta,
127128
tasks.ConvertPullRequestsMeta,
129+
tasks.ConvertPrReviewersMeta,
128130
tasks.ConvertPrCommentsMeta,
129131
tasks.ConvertPrCommitsMeta,
130132
tasks.ConvertCommitsMeta,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
"time"
22+
23+
"github.com/apache/incubator-devlake/core/context"
24+
"github.com/apache/incubator-devlake/core/errors"
25+
"github.com/apache/incubator-devlake/core/models/common"
26+
"github.com/apache/incubator-devlake/core/plugin"
27+
)
28+
29+
var _ plugin.MigrationScript = (*addPrReviewerTable)(nil)
30+
31+
type prReviewer20251226 struct {
32+
ConnectionId uint64 `gorm:"primaryKey"`
33+
RepoId string `gorm:"primaryKey;type:varchar(255)"`
34+
PullRequestId int `gorm:"primaryKey"`
35+
AccountId string `gorm:"primaryKey;type:varchar(255)"`
36+
DisplayName string `gorm:"type:varchar(255)"`
37+
Role string `gorm:"type:varchar(100)"`
38+
State string `gorm:"type:varchar(100)"`
39+
Approved bool
40+
ParticipatedOn *time.Time
41+
common.NoPKModel
42+
}
43+
44+
func (prReviewer20251226) TableName() string {
45+
return "_tool_bitbucket_pr_reviewers"
46+
}
47+
48+
type addPrReviewerTable struct{}
49+
50+
func (*addPrReviewerTable) Up(basicRes context.BasicRes) errors.Error {
51+
db := basicRes.GetDal()
52+
if err := db.AutoMigrate(&prReviewer20251226{}); err != nil {
53+
return err
54+
}
55+
return nil
56+
}
57+
58+
func (*addPrReviewerTable) Version() uint64 {
59+
return 20251226100000
60+
}
61+
62+
func (*addPrReviewerTable) Name() string {
63+
return "add _tool_bitbucket_pr_reviewers table"
64+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ func All() []plugin.MigrationScript {
4343
new(addMergedByToPr),
4444
new(changeIssueComponentType),
4545
new(addApiTokenAuth),
46+
new(addPrReviewerTable),
4647
}
4748
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 models
19+
20+
import (
21+
"time"
22+
23+
"github.com/apache/incubator-devlake/core/models/common"
24+
)
25+
26+
type BitbucketPrReviewer struct {
27+
ConnectionId uint64 `gorm:"primaryKey"`
28+
RepoId string `gorm:"primaryKey;type:varchar(255)"`
29+
PullRequestId int `gorm:"primaryKey"`
30+
AccountId string `gorm:"primaryKey;type:varchar(255)"`
31+
DisplayName string `gorm:"type:varchar(255)"`
32+
Role string `gorm:"type:varchar(100)"` // PARTICIPANT, REVIEWER
33+
State string `gorm:"type:varchar(100)"` // approved, changes_requested, null
34+
Approved bool
35+
ParticipatedOn *time.Time
36+
common.NoPKModel
37+
}
38+
39+
func (BitbucketPrReviewer) TableName() string {
40+
return "_tool_bitbucket_pr_reviewers"
41+
}

backend/plugins/bitbucket/tasks/pr_collector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func CollectApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
5353
`values.merge_commit.hash,values.merge_commit.date,values.links.html,values.author,values.created_on,values.updated_on,`+
5454
`values.destination.branch.name,values.destination.commit.hash,values.destination.repository.full_name,`+
5555
`values.source.branch.name,values.source.commit.hash,values.source.repository.full_name,`+
56+
`values.participants.user.account_id,values.participants.user.display_name,`+
57+
`values.participants.role,values.participants.state,values.participants.approved,values.participants.participated_on,`+
5658
`page,pagelen,size`,
5759
collectorWithState),
5860
GetTotalPages: GetTotalPagesFromResponse,

backend/plugins/bitbucket/tasks/pr_extractor.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,15 @@ type BitbucketApiPullRequest struct {
7777
} `json:"commit"`
7878
Repo *models.BitbucketApiRepo `json:"repository"`
7979
} `json:"source"`
80-
//Reviewers []BitbucketAccountResponse `json:"reviewers"`
81-
//Participants []BitbucketAccountResponse `json:"participants"`
80+
Participants []BitbucketParticipant `json:"participants"`
81+
}
82+
83+
type BitbucketParticipant struct {
84+
User *BitbucketAccountResponse `json:"user"`
85+
Role string `json:"role"`
86+
State *string `json:"state"`
87+
Approved bool `json:"approved"`
88+
ParticipatedOn *common.Iso8601Time `json:"participated_on"`
8289
}
8390

8491
func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
@@ -117,6 +124,36 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
117124
}
118125
results = append(results, bitbucketPr)
119126

127+
// Extract participants/reviewers
128+
for _, participant := range rawL.Participants {
129+
if participant.User == nil {
130+
continue
131+
}
132+
reviewer := &models.BitbucketPrReviewer{
133+
ConnectionId: data.Options.ConnectionId,
134+
RepoId: data.Options.FullName,
135+
PullRequestId: rawL.BitbucketId,
136+
AccountId: participant.User.AccountId,
137+
DisplayName: participant.User.DisplayName,
138+
Role: participant.Role,
139+
Approved: participant.Approved,
140+
}
141+
if participant.State != nil {
142+
reviewer.State = *participant.State
143+
}
144+
if participant.ParticipatedOn != nil {
145+
reviewer.ParticipatedOn = participant.ParticipatedOn.ToNullableTime()
146+
}
147+
results = append(results, reviewer)
148+
149+
// Also save the user account
150+
bitbucketUser, err := convertAccount(participant.User, data.Options.ConnectionId)
151+
if err != nil {
152+
return nil, err
153+
}
154+
results = append(results, bitbucketUser)
155+
}
156+
120157
return results, nil
121158
},
122159
})
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 tasks
19+
20+
import (
21+
"reflect"
22+
23+
"github.com/apache/incubator-devlake/core/dal"
24+
"github.com/apache/incubator-devlake/core/errors"
25+
"github.com/apache/incubator-devlake/core/models/domainlayer/code"
26+
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
27+
plugin "github.com/apache/incubator-devlake/core/plugin"
28+
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
29+
"github.com/apache/incubator-devlake/plugins/bitbucket/models"
30+
)
31+
32+
var ConvertPrReviewersMeta = plugin.SubTaskMeta{
33+
Name: "Convert PR Reviewers",
34+
EntryPoint: ConvertPrReviewers,
35+
EnabledByDefault: true,
36+
Required: false,
37+
Description: "Convert tool layer PR reviewers to domain layer",
38+
DomainTypes: []string{plugin.DOMAIN_TYPE_CODE_REVIEW},
39+
}
40+
41+
func ConvertPrReviewers(taskCtx plugin.SubTaskContext) errors.Error {
42+
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PULL_REQUEST_TABLE)
43+
db := taskCtx.GetDal()
44+
repoId := data.Options.FullName
45+
46+
cursor, err := db.Cursor(
47+
dal.From(&models.BitbucketPrReviewer{}),
48+
dal.Where("repo_id = ? and connection_id = ?", repoId, data.Options.ConnectionId),
49+
)
50+
if err != nil {
51+
return err
52+
}
53+
defer cursor.Close()
54+
55+
prIdGen := didgen.NewDomainIdGenerator(&models.BitbucketPullRequest{})
56+
accountIdGen := didgen.NewDomainIdGenerator(&models.BitbucketAccount{})
57+
58+
converter, err := api.NewDataConverter(api.DataConverterArgs{
59+
InputRowType: reflect.TypeOf(models.BitbucketPrReviewer{}),
60+
Input: cursor,
61+
RawDataSubTaskArgs: *rawDataSubTaskArgs,
62+
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
63+
reviewer := inputRow.(*models.BitbucketPrReviewer)
64+
domainReviewer := &code.PullRequestReviewer{
65+
PullRequestId: prIdGen.Generate(data.Options.ConnectionId, reviewer.RepoId, reviewer.PullRequestId),
66+
ReviewerId: accountIdGen.Generate(data.Options.ConnectionId, reviewer.AccountId),
67+
Name: reviewer.DisplayName,
68+
UserName: reviewer.DisplayName,
69+
}
70+
return []interface{}{
71+
domainReviewer,
72+
}, nil
73+
},
74+
})
75+
if err != nil {
76+
return err
77+
}
78+
79+
return converter.Execute()
80+
}

0 commit comments

Comments
 (0)