This is an automated email from the ASF dual-hosted git repository.
mappjzc pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 9d49a9f36 Fix gitlab commit sha (#5501)
9d49a9f36 is described below
commit 9d49a9f36d1bfbc43ad317b21e39bf8ab3a55e6c
Author: Marco-De-Stefani <[email protected]>
AuthorDate: Sun Jun 25 17:04:03 2023 +0200
Fix gitlab commit sha (#5501)
* fix: correctly retrieving of MR SHA
* correct name of the GitLab field
* resolving PR comments - refactor & fix e2e tests
---------
Co-authored-by: marco.destefani <[email protected]>
---
.../e2e/snapshot_tables/_tool_gitlab_merge_requests.csv | 4 ++--
backend/plugins/gitlab/models/mr.go | 2 ++
backend/plugins/gitlab/tasks/mr_convertor.go | 12 +++++++++++-
backend/plugins/gitlab/tasks/mr_extractor.go | 4 ++++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git
a/backend/plugins/gitlab/e2e/snapshot_tables/_tool_gitlab_merge_requests.csv
b/backend/plugins/gitlab/e2e/snapshot_tables/_tool_gitlab_merge_requests.csv
index c218b8c48..23b131914 100644
--- a/backend/plugins/gitlab/e2e/snapshot_tables/_tool_gitlab_merge_requests.csv
+++ b/backend/plugins/gitlab/e2e/snapshot_tables/_tool_gitlab_merge_requests.csv
@@ -8,11 +8,11 @@
connection_id,gitlab_id,iid,project_id,source_project_id,target_project_id,state
1,55146787,9,12345678,15706315,12345678,opened,Issue 3: Transformed model for
query
performance,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/9,14,0,0,issue_3,master,,,2020-04-08T20:09:08.130+00:00,2020-06-29T15:47:04.785+00:00,,,,,nehiljain,783199,,,0
1,58311001,10,12345678,12345678,12345678,merged,Update version in
readme,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/10,0,0,0,emilie-master-patch-23079,master,66c0f1de49a0c876b8f93e8e0dce3327e766f59d,2020-05-11T17:09:20.603+00:00,2020-05-11T17:09:12.265+00:00,2020-05-11T17:09:20.565+00:00,,,emilie,,emilie,2295562,,,0
1,62519057,11,12345678,19569570,12345678,opened,Clustering metering
models,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/11,0,0,0,clustering-metering,master,,,2020-06-24T12:34:04.792+00:00,2020-06-24T12:35:01.115+00:00,,,,,jainnehil,842680,,,0
-1,65505080,12,12345678,12345678,12345678,merged,"Resolve ""Upgrade package for
dbt
0.17""",https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/12,0,0,0,11-upgrade-package-for-dbt-0-17,master,9bfc136eb90802c2ce59956c34dde01bb3de0d50,2020-07-24T21:13:35.321+00:00,2020-07-24T17:47:08.238+00:00,2020-07-24T21:13:34.907+00:00,,,tayloramurphy,"Closes
#11
+1,65505080,12,12345678,12345678,12345678,merged,"Resolve ""Upgrade package for
dbt
0.17""",https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/12,0,0,0,11-upgrade-package-for-dbt-0-17,master,9bfc136eb90802c2ce59956c34dde01bb3de0d50,2020-07-24T21:13:35.321+00:00,2020-07-24T17:47:08.238+00:00,2020-07-24T21:13:34.907+00:00,,,tayloramurphy,"Closes
#11
* Upgrades to 0.17.0 format
* Formatting changes to be in line with GitLab SQL Style
Guide",tayloramurphy,1942272,,,0
-1,68978485,13,12345678,15706315,12345678,closed,Include more snowflake qrt
columns,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/13,0,0,0,include_more_snowflake_qrt_columns,master,,,2020-08-27T20:17:01.825+00:00,2020-08-27T20:20:08.131+00:00,2020-08-27T20:20:08.150+00:00,,,,aianus,2478227,,,0
+1,68978485,13,12345678,15706315,12345678,closed,Include more snowflake qrt
columns,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/13,0,0,0,include_more_snowflake_qrt_columns,master,1cfe7c21c8726d8fda037d7ad26a16faacfe65b4,,2020-08-27T20:17:01.825+00:00,2020-08-27T20:20:08.131+00:00,2020-08-27T20:20:08.150+00:00,,,,aianus,2478227,,,0
1,89243644,14,12345678,24539973,12345678,merged,Update README.md to use the
newest version as an
example,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/14,0,0,0,ThomasLaPiana-master-patch-93997,master,21840a7eadb58babe8aeae2960da851a3ed00ddc,2021-02-19T20:13:05.969+00:00,2021-02-19T20:12:14.302+00:00,2021-02-19T20:13:05.913+00:00,,,tayloramurphy,Update
README.md to use the newest version as an example. The old version doesn't
work with the current version of dbt,ThomasLa [...]
1,110817220,16,12345678,28584714,12345678,merged,Update packages.yml to point
to dbt-labs instead of
fishtown,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/16,5,0,0,GJMcClintock-master-patch-24867,master,6f45b467c478df1c67d19cf6d4cbb8e05a710662,2021-08-12T06:12:54.329+00:00,2021-08-03T15:02:54.955+00:00,2021-10-04T16:23:41.057+00:00,,,vedprakash2021,With
the company name change the old repo is deprecated.,GJMcClintock,9439881,,,0
1,111383524,17,12345678,0,12345678,closed,The package name changed ->
https://hub.getdbt.com/dbt-labs/dbt_utils/latest/,https://gitlab.com/gitlab-data/snowflake_spend/-/merge_requests/17,1,0,0,swiffer-master-patch-77533,master,,,2021-08-07T06:50:25.458+00:00,2021-08-07T06:51:14.916+00:00,2021-08-07T06:51:14.933+00:00,,,,swiffer,156402,,,0
diff --git a/backend/plugins/gitlab/models/mr.go
b/backend/plugins/gitlab/models/mr.go
index e56b07bc3..6ac3c9b76 100644
--- a/backend/plugins/gitlab/models/mr.go
+++ b/backend/plugins/gitlab/models/mr.go
@@ -39,6 +39,8 @@ type GitlabMergeRequest struct {
SourceBranch string `gorm:"type:varchar(255)"`
TargetBranch string `gorm:"type:varchar(255)"`
MergeCommitSha string `gorm:"type:varchar(255)"`
+ SquashCommitSha string `gorm:"type:varchar(255)"`
+ DiffHeadSha string `gorm:"type:varchar(255)"`
MergedAt *time.Time
GitlabCreatedAt time.Time
GitlabUpdatedAt *time.Time
diff --git a/backend/plugins/gitlab/tasks/mr_convertor.go
b/backend/plugins/gitlab/tasks/mr_convertor.go
index 89aa2c9ba..53f5ea436 100644
--- a/backend/plugins/gitlab/tasks/mr_convertor.go
+++ b/backend/plugins/gitlab/tasks/mr_convertor.go
@@ -86,7 +86,7 @@ func ConvertApiMergeRequests(taskCtx plugin.SubTaskContext)
errors.Error {
CreatedDate: gitlabMr.GitlabCreatedAt,
MergedDate: gitlabMr.MergedAt,
ClosedDate: gitlabMr.ClosedAt,
- MergeCommitSha: gitlabMr.MergeCommitSha,
+ MergeCommitSha:
retrieveMrSha(gitlabMr.MergeCommitSha, gitlabMr.SquashCommitSha,
gitlabMr.DiffHeadSha),
HeadRef: gitlabMr.SourceBranch,
BaseRef: gitlabMr.TargetBranch,
Component: gitlabMr.Component,
@@ -113,3 +113,13 @@ func ConvertApiMergeRequests(taskCtx
plugin.SubTaskContext) errors.Error {
return converter.Execute()
}
+
+func retrieveMrSha(mergeCommitSha string, squashCommitSha string, sha string)
string {
+ if mergeCommitSha != "" {
+ return mergeCommitSha
+ }
+ if squashCommitSha != "" {
+ return squashCommitSha
+ }
+ return sha
+}
diff --git a/backend/plugins/gitlab/tasks/mr_extractor.go
b/backend/plugins/gitlab/tasks/mr_extractor.go
index 8fe0ae8d2..f9574c11a 100644
--- a/backend/plugins/gitlab/tasks/mr_extractor.go
+++ b/backend/plugins/gitlab/tasks/mr_extractor.go
@@ -51,6 +51,8 @@ type MergeRequestRes struct {
MergedAt *api.Iso8601Time `json:"merged_at"`
ClosedAt *api.Iso8601Time `json:"closed_at"`
MergeCommitSha string `json:"merge_commit_sha"`
+ SquashCommitSha string `json:"squash_commit_sha"`
+ DiffHeadSha string `json:"sha"`
MergedBy struct {
Username string `json:"username"`
} `json:"merged_by"`
@@ -197,6 +199,8 @@ func convertMergeRequest(mr *MergeRequestRes)
(*models.GitlabMergeRequest, error
SourceBranch: mr.SourceBranch,
TargetBranch: mr.TargetBranch,
MergeCommitSha: mr.MergeCommitSha,
+ SquashCommitSha: mr.SquashCommitSha,
+ DiffHeadSha: mr.DiffHeadSha,
MergedAt: api.Iso8601TimeToTime(mr.MergedAt),
GitlabCreatedAt: mr.GitlabCreatedAt.ToTime(),
GitlabUpdatedAt: api.Iso8601TimeToTime(mr.GitlabUpdatedAt),