You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/05/15 12:17:50 UTC
(incubator-devlake) branch dev-multi-env created (now 614d2faf0)
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a change to branch dev-multi-env
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
at 614d2faf0 feat(githubgraphql): add commit_sha field
This branch includes the following new commits:
new 614d2faf0 feat(githubgraphql): add commit_sha field
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-devlake) 01/01: feat(githubgraphql): add commit_sha field
Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch dev-multi-env
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 614d2faf02651030ea529e2e9d6439fef109724b
Author: d4x1 <15...@qq.com>
AuthorDate: Wed May 15 20:17:39 2024 +0800
feat(githubgraphql): add commit_sha field
---
.../core/models/domainlayer/devops/cicd_release.go | 4 +-
.../20240515_add_commit_sha_to_cicd_release.go | 49 ++++++++++++++++++++++
backend/core/models/migrationscripts/register.go | 1 +
.../20240515_add_release_commit_sha.go | 46 ++++++++++++++++++++
.../github/models/migrationscripts/register.go | 1 +
backend/plugins/github/models/release.go | 1 +
backend/plugins/github/tasks/release_convertor.go | 1 +
.../github_graphql/tasks/release_collector.go | 37 +++++++++-------
.../github_graphql/tasks/release_extractor.go | 1 +
9 files changed, 124 insertions(+), 17 deletions(-)
diff --git a/backend/core/models/domainlayer/devops/cicd_release.go b/backend/core/models/domainlayer/devops/cicd_release.go
index f9ed74012..7a8b62061 100644
--- a/backend/core/models/domainlayer/devops/cicd_release.go
+++ b/backend/core/models/domainlayer/devops/cicd_release.go
@@ -42,8 +42,8 @@ type CicdRelease struct {
RepoId string `gorm:"type:varchar(255)"`
//RepoUrl string `gorm:"index;not null"`
- TagName string `json:"tagName"`
- //CommitSha string `gorm:"primaryKey;type:varchar(255)"`
+ TagName string `json:"tagName"`
+ CommitSha string `gorm:"uniqueIndex;type:varchar(255)"`
//CommitMsg string
//RefName string `gorm:"type:varchar(255)"`
}
diff --git a/backend/core/models/migrationscripts/20240515_add_commit_sha_to_cicd_release.go b/backend/core/models/migrationscripts/20240515_add_commit_sha_to_cicd_release.go
new file mode 100644
index 000000000..58afad5d2
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240515_add_commit_sha_to_cicd_release.go
@@ -0,0 +1,49 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*addCommitShaToCicdRelease)(nil)
+
+type cicdRelease20240515 struct {
+ CommitSha string
+}
+
+func (cicdRelease20240515) TableName() string {
+ return "cicd_releases"
+}
+
+type addCommitShaToCicdRelease struct{}
+
+func (*addCommitShaToCicdRelease) Up(basicRes context.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(basicRes, &cicdRelease20240515{})
+}
+
+func (*addCommitShaToCicdRelease) Version() uint64 {
+ return 20240515194901
+}
+
+func (*addCommitShaToCicdRelease) Name() string {
+ return "add commit_sha to cicd_releases"
+}
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index ac7f66fc9..8618db1aa 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -114,5 +114,6 @@ func All() []plugin.MigrationScript {
new(addDisplayTitleAndUrl),
new(addSubtaskStates),
new(addCicdRelease),
+ new(addCommitShaToCicdRelease),
}
}
diff --git a/backend/plugins/github/models/migrationscripts/20240515_add_release_commit_sha.go b/backend/plugins/github/models/migrationscripts/20240515_add_release_commit_sha.go
new file mode 100644
index 000000000..40833eb40
--- /dev/null
+++ b/backend/plugins/github/models/migrationscripts/20240515_add_release_commit_sha.go
@@ -0,0 +1,46 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+type addReleaseCommitSha struct{}
+
+type release20240515 struct {
+ CommitSha string
+}
+
+func (release20240515) TableName() string {
+ return "_tool_github_releases"
+}
+
+func (u *addReleaseCommitSha) Up(baseRes context.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(baseRes, &release20240515{})
+}
+
+func (*addReleaseCommitSha) Version() uint64 {
+ return 20240515194858
+}
+
+func (*addReleaseCommitSha) Name() string {
+ return "add commit_sha to _tool_github_releases"
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go b/backend/plugins/github/models/migrationscripts/register.go
index 89ebfa429..496f54544 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/register.go
@@ -49,5 +49,6 @@ func All() []plugin.MigrationScript {
new(modifyIssueTypeLength),
new(addWorkflowDisplayTitle),
new(addReleaseTable),
+ new(addReleaseCommitSha),
}
}
diff --git a/backend/plugins/github/models/release.go b/backend/plugins/github/models/release.go
index d71383182..1e4ae1688 100644
--- a/backend/plugins/github/models/release.go
+++ b/backend/plugins/github/models/release.go
@@ -42,6 +42,7 @@ type GithubRelease struct {
ResourcePath string `json:"resourcePath"`
TagName string `json:"tagName"`
UpdatedAt time.Time `json:"updatedAt"`
+ CommitSha string `json:"commit_sha"`
URL string `json:"url"`
}
diff --git a/backend/plugins/github/tasks/release_convertor.go b/backend/plugins/github/tasks/release_convertor.go
index bcf4914ac..1a1389093 100644
--- a/backend/plugins/github/tasks/release_convertor.go
+++ b/backend/plugins/github/tasks/release_convertor.go
@@ -83,6 +83,7 @@ func ConvertRelease(taskCtx plugin.SubTaskContext) errors.Error {
IsLatest: githubRelease.IsLatest,
IsPrerelease: githubRelease.IsPrerelease,
TagName: githubRelease.TagName,
+ CommitSha: githubRelease.CommitSha,
AuthorID: githubRelease.AuthorID,
diff --git a/backend/plugins/github_graphql/tasks/release_collector.go b/backend/plugins/github_graphql/tasks/release_collector.go
index e80c13887..4b71626d0 100644
--- a/backend/plugins/github_graphql/tasks/release_collector.go
+++ b/backend/plugins/github_graphql/tasks/release_collector.go
@@ -48,22 +48,29 @@ type GraphqlQueryReleaseAuthor struct {
ID string `graphql:"id"`
}
+type GraphqlQueryReleaseTagCommit struct {
+ ID string `graphql:"id"`
+ Oid string `graphql:"oid"`
+ AbbreviatedOid string `graphql:"abbreviatedOid"`
+}
+
type GraphqlQueryRelease struct {
- Author GraphqlQueryReleaseAuthor `graphql:"author"`
- DatabaseID int `graphql:"databaseId"`
- Id string `graphql:"id"`
- CreatedAt time.Time `graphql:"createdAt"`
- Description string `graphql:"description"`
- DescriptionHTML string `graphql:"descriptionHTML"`
- IsDraft bool `graphql:"isDraft"`
- IsLatest bool `graphql:"isLatest"`
- IsPrerelease bool `graphql:"isPrerelease"`
- Name string `graphql:"name"`
- PublishedAt time.Time `graphql:"publishedAt"`
- ResourcePath string `graphql:"resourcePath"`
- TagName string `graphql:"tagName"`
- UpdatedAt time.Time `graphql:"updatedAt"`
- URL string `graphql:"url"`
+ Author GraphqlQueryReleaseAuthor `graphql:"author"`
+ DatabaseID int `graphql:"databaseId"`
+ Id string `graphql:"id"`
+ CreatedAt time.Time `graphql:"createdAt"`
+ Description string `graphql:"description"`
+ DescriptionHTML string `graphql:"descriptionHTML"`
+ IsDraft bool `graphql:"isDraft"`
+ IsLatest bool `graphql:"isLatest"`
+ IsPrerelease bool `graphql:"isPrerelease"`
+ Name string `graphql:"name"`
+ PublishedAt time.Time `graphql:"publishedAt"`
+ ResourcePath string `graphql:"resourcePath"`
+ TagName string `graphql:"tagName"`
+ TagCommit GraphqlQueryReleaseTagCommit `graphql:"tagCommit"`
+ UpdatedAt time.Time `graphql:"updatedAt"`
+ URL string `graphql:"url"`
}
var CollectReleaseMeta = plugin.SubTaskMeta{
diff --git a/backend/plugins/github_graphql/tasks/release_extractor.go b/backend/plugins/github_graphql/tasks/release_extractor.go
index 4d019dcc8..ef98a2803 100644
--- a/backend/plugins/github_graphql/tasks/release_extractor.go
+++ b/backend/plugins/github_graphql/tasks/release_extractor.go
@@ -97,6 +97,7 @@ func convertGitHubRelease(release *GraphqlQueryRelease, connectionId uint64, git
TagName: release.TagName,
UpdatedAt: release.UpdatedAt,
URL: release.URL,
+ CommitSha: release.TagCommit.Oid,
}
if release.Author.Name != nil {
ret.AuthorName = *release.Author.Name