From 80e79420690f0f8282924059bc6f198d5be27e27 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 11 Oct 2024 17:51:37 +0800 Subject: [PATCH 1/3] migrate draft status --- modules/migration/pullrequest.go | 1 + services/migrations/gitea_uploader.go | 7 ++++++- services/migrations/github.go | 1 + services/migrations/gitlab.go | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/migration/pullrequest.go b/modules/migration/pullrequest.go index 1435991bd2a8b..fbfdff0315e67 100644 --- a/modules/migration/pullrequest.go +++ b/modules/migration/pullrequest.go @@ -37,6 +37,7 @@ type PullRequest struct { ForeignIndex int64 Context DownloaderContext `yaml:"-"` EnsuredSafe bool `yaml:"ensured_safe"` + IsDraft bool `yaml:"is_draft"` } func (p *PullRequest) GetLocalIndex() int64 { return p.Number } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 4c8e036f057b3..679cc1fb036db 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -760,10 +760,15 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*issues_model pr.Updated = pr.Created } + prTitle := pr.Title + if pr.IsDraft && len(setting.Repository.PullRequest.WorkInProgressPrefixes) > 0 { + prTitle = fmt.Sprintf("%s%s", setting.Repository.PullRequest.WorkInProgressPrefixes[0], pr.Title) + } + issue := issues_model.Issue{ RepoID: g.repo.ID, Repo: g.repo, - Title: pr.Title, + Title: prTitle, Index: pr.Number, Content: pr.Content, MilestoneID: milestoneID, diff --git a/services/migrations/github.go b/services/migrations/github.go index a36b02ca8b220..604ab84b39645 100644 --- a/services/migrations/github.go +++ b/services/migrations/github.go @@ -737,6 +737,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq PatchURL: pr.GetPatchURL(), // see below for SECURITY related issues here Reactions: reactions, ForeignIndex: int64(*pr.Number), + IsDraft: pr.GetDraft(), }) // SECURITY: Ensure that the PR is safe diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go index 065b687fa6877..295bc7c29f517 100644 --- a/services/migrations/gitlab.go +++ b/services/migrations/gitlab.go @@ -722,6 +722,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque PatchURL: pr.WebURL + ".patch", ForeignIndex: int64(pr.IID), Context: gitlabIssueContext{IsMergeRequest: true}, + IsDraft: pr.Draft, }) // SECURITY: Ensure that the PR is safe From 842c77f3edee0664455b19b46574de4f5eacf2be Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 11 Oct 2024 18:01:40 +0800 Subject: [PATCH 2/3] fix --- services/migrations/gitea_uploader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 679cc1fb036db..2af1b8c1443ea 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -761,7 +761,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*issues_model } prTitle := pr.Title - if pr.IsDraft && len(setting.Repository.PullRequest.WorkInProgressPrefixes) > 0 { + if pr.IsDraft { prTitle = fmt.Sprintf("%s%s", setting.Repository.PullRequest.WorkInProgressPrefixes[0], pr.Title) } From f15a17cdc47cc6d8d313435b946f42e07fe902c0 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Sat, 12 Oct 2024 09:34:35 +0800 Subject: [PATCH 3/3] check if the title has wip prefix --- services/migrations/gitea_uploader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 2af1b8c1443ea..eb21b6534b8f4 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -761,8 +761,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*issues_model } prTitle := pr.Title - if pr.IsDraft { - prTitle = fmt.Sprintf("%s%s", setting.Repository.PullRequest.WorkInProgressPrefixes[0], pr.Title) + if pr.IsDraft && !issues_model.HasWorkInProgressPrefix(pr.Title) { + prTitle = fmt.Sprintf("%s %s", setting.Repository.PullRequest.WorkInProgressPrefixes[0], pr.Title) } issue := issues_model.Issue{