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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 = (*addAdditionsDeletionsToMr)(nil)

type mrAdditionsDeletions struct {
Additions int
Deletions int
}

func (mrAdditionsDeletions) TableName() string {
return "_tool_gitlab_merge_requests"
}

type addAdditionsDeletionsToMr struct{}

func (*addAdditionsDeletionsToMr) Up(basicRes context.BasicRes) errors.Error {
return errors.Convert(basicRes.GetDal().AutoMigrate(&mrAdditionsDeletions{}))
}

func (*addAdditionsDeletionsToMr) Version() uint64 {
return 20260615000001
}

func (*addAdditionsDeletionsToMr) Name() string {
return "gitlab: add additions and deletions to merge requests"
}
1 change: 1 addition & 0 deletions backend/plugins/gitlab/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ func All() []plugin.MigrationScript {
new(changeIssueComponentType),
new(addIsChildToPipelines240906),
new(addPrSizeExcludedFileExtensions),
new(addAdditionsDeletionsToMr),
}
}
2 changes: 2 additions & 0 deletions backend/plugins/gitlab/models/mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type GitlabMergeRequest struct {
AuthorUsername string `gorm:"type:varchar(255)"`
AuthorUserId int
Component string `gorm:"type:varchar(255)"`
Additions int `gorm:"comment:Lines added in this MR diff only"`
Deletions int `gorm:"comment:Lines deleted in this MR diff only"`
common.NoPKModel
}

Expand Down
1 change: 1 addition & 0 deletions backend/plugins/gitlab/tasks/mr_detail_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func CollectApiMergeRequestDetails(taskCtx plugin.SubTaskContext) errors.Error {
Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
query := url.Values{}
query.Set("with_stats", "true")
query.Set("include_diff_stats", "true")
return query, nil
},
ResponseParser: GetOneRawMessageFromResponse,
Expand Down
9 changes: 9 additions & 0 deletions backend/plugins/gitlab/tasks/mr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ type MergeRequestRes struct {
Assignees []Assignee
FirstCommentTime common.Iso8601Time
Labels []string `json:"labels"`
DiffStats struct {

Additions int `json:"additions"`

Deletions int `json:"deletions"`

} `json:"diff_stats"`
}

type Reviewer struct {
Expand Down Expand Up @@ -245,6 +252,8 @@ func convertMergeRequest(mr *MergeRequestRes) (*models.GitlabMergeRequest, error
MergedByUsername: mr.MergedBy.Username,
AuthorUsername: mr.Author.Username,
AuthorUserId: mr.Author.Id,
Additions: mr.DiffStats.Additions,
Deletions: mr.DiffStats.Deletions,
}
return gitlabMergeRequest, nil
}
Expand Down