Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/core/models/domainlayer/crossdomain/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ limitations under the License.
package crossdomain

import (
"github.com/apache/incubator-devlake/core/models/domainlayer"
"time"

"github.com/apache/incubator-devlake/core/models/domainlayer"
)

type Account struct {
Expand All @@ -31,6 +32,7 @@ type Account struct {
Organization string `gorm:"type:varchar(255)"`
CreatedDate *time.Time
Status int
IsBot bool `gorm:"default:false"`
}

func (Account) TableName() string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 = (*addIsBotToAccounts)(nil)

type account20260720 struct {
IsBot bool `gorm:"default:false"`
}

func (account20260720) TableName() string {
return "accounts"
}

type addIsBotToAccounts struct{}

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

func (*addIsBotToAccounts) Version() uint64 {
return 20260720120000
}

func (*addIsBotToAccounts) Name() string {
return "add is_bot to accounts so bot/automation activity can be excluded from metrics, according to #8974"
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ func All() []plugin.MigrationScript {
new(changeIssueComponentToText),
new(changeCqIssueCodeBlocksComponentToText),
new(addCqProjectMetricsHistory),
new(addIsBotToAccounts),
}
}
2 changes: 2 additions & 0 deletions backend/plugins/dora/tasks/change_lead_time_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ func batchFetchFirstReviews(projectName string, db dal.Dal) (map[string]*code.Pu
SELECT prc2.pull_request_id, MIN(prc2.created_date) as min_date
FROM pull_request_comments prc2
INNER JOIN pull_requests pr2 ON pr2.id = prc2.pull_request_id
LEFT JOIN accounts acc2 ON acc2.id = prc2.account_id
WHERE (pr2.author_id IS NULL OR pr2.author_id = '' OR prc2.account_id != pr2.author_id)
AND COALESCE(acc2.is_bot, false) = false
GROUP BY prc2.pull_request_id
) first_reviews ON prc.pull_request_id = first_reviews.pull_request_id
AND prc.created_date = first_reviews.min_date`),
Expand Down
4 changes: 4 additions & 0 deletions backend/plugins/github/tasks/account_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type repoAccountForConvert struct {
Name string
Email string
AvatarUrl string
Type string
common.NoPKModel
}

Expand Down Expand Up @@ -96,6 +97,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
COALESCE(ga.name, '') AS name,
COALESCE(ga.email, '') AS email,
COALESCE(ga.avatar_url, '') AS avatar_url,
COALESCE(ga.type, '') AS type,
COALESCE(ga._raw_data_params, _tool_github_repo_accounts._raw_data_params) AS _raw_data_params,
COALESCE(ga._raw_data_table, _tool_github_repo_accounts._raw_data_table) AS _raw_data_table,
COALESCE(ga._raw_data_id, _tool_github_repo_accounts._raw_data_id) AS _raw_data_id,
Expand Down Expand Up @@ -145,6 +147,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
orgStr = orgStr[:255]
}
}
isBot := githubUser.Type == "Bot" || strings.HasSuffix(githubUser.Login, "[bot]")

domainUser := &crossdomain.Account{
DomainEntity: domainlayer.DomainEntity{Id: accountIdGen.Generate(data.Options.ConnectionId, githubUser.Id)},
Expand All @@ -153,6 +156,7 @@ func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error {
UserName: githubUser.Login,
AvatarUrl: githubUser.AvatarUrl,
Organization: orgStr,
IsBot: isBot,
}
return []interface{}{
domainUser,
Expand Down