Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior#37465
Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior#37465silverwind merged 13 commits intogo-gitea:mainfrom
Conversation
Adds a new `DEFAULT_PR_TITLE_SOURCE` option under `[repository.pull-request]` with three values: - `first-commit` (default): uses the oldest commit summary, current behavior since v1.26 - `branch-name`: uses branch name for multi-commit PRs, restoring pre-v1.26 behavior - `branch-name-transform`: like branch-name but replaces hyphens/underscores with spaces and capitalizes the first letter, closer to GitHub behavior
…rm, rename setting to DEFAULT_TITLE_SOURCE
|
I tested the
GitHub's full algorithm (derived empirically)
A reference Go implementation: func humanizeBranchName(s string) string {
var b strings.Builder
runes := []rune(s)
for i, r := range runes {
if i > 0 && unicode.IsUpper(r) && unicode.IsLower(runes[i-1]) {
b.WriteByte(' ')
}
if r == '-' || r == '_' {
b.WriteByte(' ')
} else {
b.WriteRune(unicode.ToLower(r))
}
}
out := strings.TrimLeft(b.String(), " ")
if out == "" {
return out
}
outRunes := []rune(out)
outRunes[0] = unicode.ToUpper(outRunes[0])
return string(outRunes)
}Written with the help of Claude Opus 4.7 |
Do we still want to keep this behavior of left-trim but not right-trim? Look like a Github bug for me |
Yeah, unequal trimming seems like bug, I'll push a fixup for this. |
…tants - collapse the four-pass humanize into a single rune walk - symmetric Trim so "trailing-" no longer leaves a trailing space (was a GitHub quirk we copied — not desirable) - introduce setting.RepoPRTitleSourceFirstCommit/Auto consts to match the existing RepoCreatingPrivate/Public pattern, and use them in callers - shrink the app.example.ini comment to one line - drop test cases not verified against the original GitHub reference Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
Shouldn't this be a per repository/org setting, rather or in addition to the global one? |
Well, a longstanding problem. It needs a flexible configuration system. However, either some people can't make a right design or implementation, or some people don't have time or interests. |
|
Any such settings would benefit from a config chain like global -> org/user -> repo, but it needs a proper designed inheritance system. Having this global setting now won't hurt a future design. @0xGREG could you file a pr against https://gitea.com/gitea/docs for the docs update please? |
|
Fixed more cases:
|
|
Created PR for the docs https://gitea.com/gitea/docs/pulls/391 |
|
@0xGREG please fix the merge conflicts. 🍵 |
done |
| ctx.Data["Username"] = ci.HeadRepo.OwnerName | ||
| ctx.Data["Reponame"] = ci.HeadRepo.Name |
There was a problem hiding this comment.
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)
* main: Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) Fix scheduled action panic with null event payload (go-gitea#37459) Fix attachment Content-Security-Policy (go-gitea#37455) [skip ci] Updated translations via Crowdin Rename CurrentRefPath to CurrentRefSubURL (go-gitea#37453) Clean up org pages layout (go-gitea#37445) Fix script error alert (go-gitea#37458) Fix inconsistent disabled styling on logged-out repo header buttons (go-gitea#37406) Add API endpoint to reply to pull request review comments (go-gitea#36683) Add CurrentURL template variable back (go-gitea#37444)
Adds a new
DEFAULT_TITLE_SOURCEoption under[repository.pull-request]with three values:first-commit(default): uses the oldest commit summary, current behavior since v1.26auto: normalizes branch name as title for multi-commit PRs (just like GitHub), use commit summary for single-commit PRsCloses #37463