Skip to content

Commit 0c4deb4

Browse files
feat(dora): exclude bot/automation accounts from PR Pickup Time calculation
1 parent 9e8ca1b commit 0c4deb4

5 files changed

Lines changed: 45 additions & 1 deletion

File tree

backend/core/models/domainlayer/crossdomain/account.go

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

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

2526
type Account struct {
@@ -31,6 +32,7 @@ type Account struct {
3132
Organization string `gorm:"type:varchar(255)"`
3233
CreatedDate *time.Time
3334
Status int
35+
IsBot bool `gorm:"default:false"`
3436
}
3537

3638
func (Account) TableName() string {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package migrationscripts
2+
3+
import (
4+
"github.com/apache/incubator-devlake/core/context"
5+
"github.com/apache/incubator-devlake/core/errors"
6+
"github.com/apache/incubator-devlake/core/plugin"
7+
)
8+
9+
var _ plugin.MigrationScript = (*addIsBotToAccounts)(nil)
10+
11+
type account20260720 struct {
12+
IsBot bool `gorm:"default:false"`
13+
}
14+
15+
func (account20260720) TableName() string {
16+
return "accounts"
17+
}
18+
19+
type addIsBotToAccounts struct{}
20+
21+
func (*addIsBotToAccounts) Up(basicRes context.BasicRes) errors.Error {
22+
db := basicRes.GetDal()
23+
if err := db.AutoMigrate(&account20260720{}); err != nil {
24+
return err
25+
}
26+
return nil
27+
}
28+
29+
func (*addIsBotToAccounts) Version() uint64 {
30+
return 20260720120000
31+
}
32+
33+
func (*addIsBotToAccounts) Name() string {
34+
return "add is_bot to accounts so bot/automation activity can be excluded from metrics, according to #8974"
35+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ func All() []plugin.MigrationScript {
148148
new(changeIssueComponentToText),
149149
new(changeCqIssueCodeBlocksComponentToText),
150150
new(addCqProjectMetricsHistory),
151+
new(addIsBotToAccounts),
151152
}
152153
}

backend/plugins/dora/tasks/change_lead_time_calculator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ func batchFetchFirstReviews(projectName string, db dal.Dal) (map[string]*code.Pu
248248
SELECT prc2.pull_request_id, MIN(prc2.created_date) as min_date
249249
FROM pull_request_comments prc2
250250
INNER JOIN pull_requests pr2 ON pr2.id = prc2.pull_request_id
251+
LEFT JOIN accounts acc2 ON acc2.id = prc2.account_id
251252
WHERE (pr2.author_id IS NULL OR pr2.author_id = '' OR prc2.account_id != pr2.author_id)
253+
AND COALESCE(acc2.is_bot, false) = false
252254
GROUP BY prc2.pull_request_id
253255
) first_reviews ON prc.pull_request_id = first_reviews.pull_request_id
254256
AND prc.created_date = first_reviews.min_date`),

backend/plugins/github/tasks/account_convertor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type repoAccountForConvert struct {
4141
Name string
4242
Email string
4343
AvatarUrl string
44+
Type string
4445
common.NoPKModel
4546
}
4647

@@ -96,6 +97,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
9697
COALESCE(ga.name, '') AS name,
9798
COALESCE(ga.email, '') AS email,
9899
COALESCE(ga.avatar_url, '') AS avatar_url,
100+
COALESCE(ga.type, '') AS type,
99101
COALESCE(ga._raw_data_params, _tool_github_repo_accounts._raw_data_params) AS _raw_data_params,
100102
COALESCE(ga._raw_data_table, _tool_github_repo_accounts._raw_data_table) AS _raw_data_table,
101103
COALESCE(ga._raw_data_id, _tool_github_repo_accounts._raw_data_id) AS _raw_data_id,
@@ -145,6 +147,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
145147
orgStr = orgStr[:255]
146148
}
147149
}
150+
isBot := githubUser.Type == "Bot" || strings.HasSuffix(githubUser.Login, "[bot]")
148151

149152
domainUser := &crossdomain.Account{
150153
DomainEntity: domainlayer.DomainEntity{Id: accountIdGen.Generate(data.Options.ConnectionId, githubUser.Id)},
@@ -153,6 +156,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
153156
UserName: githubUser.Login,
154157
AvatarUrl: githubUser.AvatarUrl,
155158
Organization: orgStr,
159+
IsBot: isBot,
156160
}
157161
return []interface{}{
158162
domainUser,

0 commit comments

Comments
 (0)