You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/07/25 03:09:34 UTC

(incubator-devlake) branch add-pr-isDraft updated: feat: pr add is draft field

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch add-pr-isDraft
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/add-pr-isDraft by this push:
     new e97e7d088 feat: pr add is draft field
e97e7d088 is described below

commit e97e7d0886c1b391cbfe86d8b6ace17069ce46d7
Author: abeizn <zi...@merico.dev>
AuthorDate: Thu Jul 25 11:09:18 2024 +0800

    feat: pr add is draft field
---
 .../core/models/domainlayer/code/pull_request.go   |  1 +
 .../20240725_add_is_draft_to_pr.go                 | 52 ++++++++++++++++++++++
 backend/core/models/migrationscripts/register.go   |  1 +
 .../20240725_add_is_draft_to_pr.go                 | 52 ++++++++++++++++++++++
 .../github/models/migrationscripts/register.go     |  1 +
 backend/plugins/github/models/pr.go                |  1 +
 backend/plugins/github/tasks/pr_convertor.go       |  1 +
 .../plugins/github_graphql/tasks/pr_collector.go   |  1 +
 .../plugins/github_graphql/tasks/pr_extractor.go   |  1 +
 9 files changed, 111 insertions(+)

diff --git a/backend/core/models/domainlayer/code/pull_request.go b/backend/core/models/domainlayer/code/pull_request.go
index 591f4c2cd..6649d6508 100644
--- a/backend/core/models/domainlayer/code/pull_request.go
+++ b/backend/core/models/domainlayer/code/pull_request.go
@@ -60,6 +60,7 @@ type PullRequest struct {
 	HeadCommitSha  string `gorm:"type:varchar(40)"`
 	Additions      int
 	Deletions      int
+	IsDraft        bool
 }
 
 func (PullRequest) TableName() string {
diff --git a/backend/core/models/migrationscripts/20240725_add_is_draft_to_pr.go b/backend/core/models/migrationscripts/20240725_add_is_draft_to_pr.go
new file mode 100644
index 000000000..62552fe30
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240725_add_is_draft_to_pr.go
@@ -0,0 +1,52 @@
+/*
+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"
+)
+
+var _ plugin.MigrationScript = (*addIsDraftToPr)(nil)
+
+type pr20240725 struct {
+	IsDraft bool
+}
+
+func (pr20240725) TableName() string {
+	return "pull_requests"
+}
+
+type addIsDraftToPr struct{}
+
+func (*addIsDraftToPr) Up(basicRes context.BasicRes) errors.Error {
+	db := basicRes.GetDal()
+	if err := db.AutoMigrate(&pr20240725{}); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (*addIsDraftToPr) Version() uint64 {
+	return 20240725142101
+}
+
+func (*addIsDraftToPr) Name() string {
+	return "add is_draft to pull_requests"
+}
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index 7b5012a7c..b2df0bd08 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -127,5 +127,6 @@ func All() []plugin.MigrationScript {
 		new(renameProjectIssueMetrics),
 		new(addChangesToPr),
 		new(addMergedByToPr),
+		new(addIsDraftToPr),
 	}
 }
diff --git a/backend/plugins/github/models/migrationscripts/20240725_add_is_draft_to_pr.go b/backend/plugins/github/models/migrationscripts/20240725_add_is_draft_to_pr.go
new file mode 100644
index 000000000..2525db667
--- /dev/null
+++ b/backend/plugins/github/models/migrationscripts/20240725_add_is_draft_to_pr.go
@@ -0,0 +1,52 @@
+/*
+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"
+)
+
+var _ plugin.MigrationScript = (*addIsDraftToPr)(nil)
+
+type pr20240725 struct {
+	IsDraft bool
+}
+
+func (pr20240725) TableName() string {
+	return "_tool_github_pull_requests"
+}
+
+type addIsDraftToPr struct{}
+
+func (*addIsDraftToPr) Up(basicRes context.BasicRes) errors.Error {
+	db := basicRes.GetDal()
+	if err := db.AutoMigrate(&pr20240725{}); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (*addIsDraftToPr) Version() uint64 {
+	return 20240725142100
+}
+
+func (*addIsDraftToPr) Name() string {
+	return "add is_draft to _tool_github_pull_requests"
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go b/backend/plugins/github/models/migrationscripts/register.go
index 4a4b95069..fec8b5338 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/register.go
@@ -52,5 +52,6 @@ func All() []plugin.MigrationScript {
 		new(addReleaseCommitSha),
 		new(addMergedByToPr),
 		new(restructReviewer),
+		new(addIsDraftToPr),
 	}
 }
diff --git a/backend/plugins/github/models/pr.go b/backend/plugins/github/models/pr.go
index b8e8fa78a..fbbca1ee6 100644
--- a/backend/plugins/github/models/pr.go
+++ b/backend/plugins/github/models/pr.go
@@ -40,6 +40,7 @@ type GithubPullRequest struct {
 	Comments       int
 	Commits        int
 	ReviewComments int
+	IsDraft        bool
 	Merged         bool
 	MergedAt       *time.Time
 	Body           string
diff --git a/backend/plugins/github/tasks/pr_convertor.go b/backend/plugins/github/tasks/pr_convertor.go
index a6b31b756..eeb1caa5d 100644
--- a/backend/plugins/github/tasks/pr_convertor.go
+++ b/backend/plugins/github/tasks/pr_convertor.go
@@ -106,6 +106,7 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
 				Deletions:      pr.Deletions,
 				MergedByName:   pr.MergedByName,
 				MergedById:     accountIdGen.Generate(data.Options.ConnectionId, pr.MergedById),
+				IsDraft:        pr.IsDraft,
 			}
 			if pr.State == "open" || pr.State == "OPEN" {
 				domainPr.Status = code.OPEN
diff --git a/backend/plugins/github_graphql/tasks/pr_collector.go b/backend/plugins/github_graphql/tasks/pr_collector.go
index 9d4c2cddf..a129d3b31 100644
--- a/backend/plugins/github_graphql/tasks/pr_collector.go
+++ b/backend/plugins/github_graphql/tasks/pr_collector.go
@@ -52,6 +52,7 @@ type GraphqlQueryPr struct {
 	Number     int
 	State      string
 	Title      string
+	IsDraft    bool
 	Body       string
 	Url        string
 	Labels     struct {
diff --git a/backend/plugins/github_graphql/tasks/pr_extractor.go b/backend/plugins/github_graphql/tasks/pr_extractor.go
index 3322feb87..0b4885328 100644
--- a/backend/plugins/github_graphql/tasks/pr_extractor.go
+++ b/backend/plugins/github_graphql/tasks/pr_extractor.go
@@ -181,6 +181,7 @@ func convertGithubPullRequest(pull GraphqlQueryPr, connId uint64, repoId int) (*
 		HeadCommitSha:   pull.HeadRefOid,
 		Additions:       pull.Additions,
 		Deletions:       pull.Deletions,
+		IsDraft:         pull.IsDraft,
 	}
 	if pull.MergedBy != nil {
 		githubPull.MergedByName = pull.MergedBy.Login