-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior #37465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0af7a30
6904a2f
b9a8587
7fe9167
37ef7ec
45d1979
6d0fd8f
2eab180
b92a8a2
cfa7d1f
14224db
740c995
678da34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "unicode" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| git_model "code.gitea.io/gitea/models/git" | ||
|
|
@@ -349,13 +350,46 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { | |
| return &compareInfo, nil | ||
| } | ||
|
|
||
| func prepareNewPullRequestTitleContent(ci *git_service.CompareInfo, commits []*git_model.SignCommitWithStatuses) (title, content string) { | ||
| title = ci.HeadRef.ShortName() | ||
| // autoTitleFromBranchName humanizes a branch name into a PR title. | ||
| func autoTitleFromBranchName(name string) string { | ||
| var buf strings.Builder | ||
| var prevIsSpace bool | ||
| runes := []rune(name) | ||
| for i, r := range runes { | ||
| isSpace := unicode.IsSpace(r) | ||
| if r == '-' || r == '_' || isSpace { | ||
| if !prevIsSpace { | ||
| buf.WriteRune(' ') | ||
| } | ||
| prevIsSpace = true | ||
| continue | ||
| } | ||
| if !prevIsSpace && unicode.IsUpper(r) { | ||
| needSpace := i > 0 && unicode.IsLower(runes[i-1]) || i < len(runes)-1 && unicode.IsLower(runes[i+1]) | ||
| if needSpace { | ||
| buf.WriteRune(' ') | ||
| } | ||
| } | ||
| buf.WriteRune(unicode.ToLower(r)) | ||
| prevIsSpace = isSpace | ||
| } | ||
| out := strings.TrimSpace(buf.String()) | ||
| if out == "" { | ||
| return out | ||
| } | ||
| outRunes := []rune(out) | ||
| outRunes[0] = unicode.ToUpper(outRunes[0]) | ||
| return string(outRunes) | ||
| } | ||
|
|
||
| if len(commits) > 0 { | ||
| func prepareNewPullRequestTitleContent(ci *git_service.CompareInfo, commits []*git_model.SignCommitWithStatuses, defaultTitleSource string) (title, content string) { | ||
| useFirstCommitAsTitle := len(commits) == 1 || (defaultTitleSource == setting.RepoPRTitleSourceFirstCommit && len(commits) > 0) | ||
| if useFirstCommitAsTitle { | ||
| // the "commits" are from "ShowPrettyFormatLogToList", which is ordered from newest to oldest, here take the oldest one | ||
| c := commits[len(commits)-1] | ||
| title = strings.TrimSpace(c.UserCommit.Summary()) | ||
| } else { | ||
| title = autoTitleFromBranchName(ci.HeadRef.ShortName()) | ||
| } | ||
|
|
||
| if len(commits) == 1 { | ||
|
|
@@ -491,7 +525,10 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white | |
| ctx.Data["Commits"] = commits | ||
| ctx.Data["CommitCount"] = len(commits) | ||
|
|
||
| ctx.Data["title"], ctx.Data["content"] = prepareNewPullRequestTitleContent(ci, commits) | ||
| ctx.Data["title"], ctx.Data["content"] = prepareNewPullRequestTitleContent(ci, commits, setting.Repository.PullRequest.DefaultTitleSource) | ||
| ctx.Data["Username"] = ci.HeadRepo.OwnerName | ||
| ctx.Data["Reponame"] = ci.HeadRepo.Name | ||
|
Comment on lines
+529
to
+530
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I have removed them ....... They are useless template variables. Maybe need more clean up for the "compare diff" page (it is one of the most messy pages, just like "pull request view" page)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> Refactor compare diff/pull page (1) #37481 |
||
|
|
||
| setCompareContext(ctx, beforeCommit, headCommit, ci.HeadRepo.OwnerName, repo.Name) | ||
|
|
||
| return false | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.