Skip to content

Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior#37465

Merged
silverwind merged 13 commits intogo-gitea:mainfrom
0xGREG:feature/default-pr-title-source
Apr 28, 2026
Merged

Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior#37465
silverwind merged 13 commits intogo-gitea:mainfrom
0xGREG:feature/default-pr-title-source

Conversation

@0xGREG
Copy link
Copy Markdown
Contributor

@0xGREG 0xGREG commented Apr 28, 2026

Adds a new DEFAULT_TITLE_SOURCE option under [repository.pull-request] with three values:

  • first-commit (default): uses the oldest commit summary, current behavior since v1.26
  • auto: normalizes branch name as title for multi-commit PRs (just like GitHub), use commit summary for single-commit PRs

Closes #37463

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
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 28, 2026
@github-actions github-actions Bot added the docs-update-needed The document needs to be updated synchronously label Apr 28, 2026
Comment thread custom/conf/app.example.ini Outdated
Comment thread custom/conf/app.example.ini Outdated
Comment thread routers/web/repo/compare.go Outdated
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 28, 2026

I tested the auto transformation against GitHub's web UI by creating ~20 branches in a test repo and reading the title placeholder GitHub renders on the compare page. The current implementation deviates from real GitHub behavior in several cases:

Branch GitHub This PR
fix/the-bug Fix/the bug Fix/the bug
Already-Capitalized Already capitalized Already Capitalized
ALL-CAPS-BRANCH All caps branch ALL CAPS BRANCH
MixedCase-Name Mixed case name MixedCase Name
fooBar-baz Foo bar baz fooBar baz
foo/BAR Foo/bar foo/BAR
_leading-underscore Leading underscore <space>leading underscore
CamelCase Camel case CamelCase
foo--double-dash Foo<sp><sp>double dash Foo<sp><sp>double dash
123-fix 123 fix 123 fix

GitHub's full algorithm (derived empirically)

  1. Split camelCase/PascalCase: insert a space before any uppercase letter that follows a lowercase letter (fooBarfoo Bar, MixedCaseMixed Case).
  2. Replace - and _ with single spaces — every occurrence, consecutive separators are not collapsed (foo--barfoo bar).
  3. Lowercase the entire string.
  4. Left-trim whitespace (so a leading _/- is dropped, not turned into a leading space). Trailing separators are not trimmed (trailing-Trailing<space>).
  5. Capitalize the first letter that remains.
  6. Slashes, dots, digits, emoji, CJK chars are preserved as-is.

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

@lautriva
Copy link
Copy Markdown

  1. Left-trim whitespace (so a leading _/- is dropped, not turned into a leading space). Trailing separators are not trimmed (trailing-Trailing<space>)

Do we still want to keep this behavior of left-trim but not right-trim?

Look like a Github bug for me

@silverwind
Copy link
Copy Markdown
Member

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>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 28, 2026
@TheFox0x7
Copy link
Copy Markdown
Contributor

Shouldn't this be a per repository/org setting, rather or in addition to the global one?

@wxiaoguang
Copy link
Copy Markdown
Contributor

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.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 28, 2026

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?

@wxiaoguang
Copy link
Copy Markdown
Contributor

Fixed more cases:

  • {"FixHTMLBug", "Fix html bug"}
  • {"foo--double-dash", "Foo double dash"},

Comment thread custom/conf/app.example.ini
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 28, 2026
@wxiaoguang wxiaoguang changed the title Add DEFAULT_PR_TITLE_SOURCE setting for pull request title default behavior Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior Apr 28, 2026
@0xGREG
Copy link
Copy Markdown
Contributor Author

0xGREG commented Apr 28, 2026

Created PR for the docs https://gitea.com/gitea/docs/pulls/391

@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 28, 2026
@lunny lunny added this to the 1.27.0 milestone Apr 28, 2026
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 28, 2026
@GiteaBot
Copy link
Copy Markdown
Collaborator

@0xGREG please fix the merge conflicts. 🍵

@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 28, 2026
@bircni
Copy link
Copy Markdown
Member

bircni commented Apr 28, 2026

@0xGREG please fix the merge conflicts. 🍵

done

@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 28, 2026
@silverwind silverwind enabled auto-merge (squash) April 28, 2026 21:15
@silverwind silverwind merged commit 0ba862c into go-gitea:main Apr 28, 2026
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 28, 2026
Comment on lines +529 to +530
ctx.Data["Username"] = ci.HeadRepo.OwnerName
ctx.Data["Reponame"] = ci.HeadRepo.Name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> Refactor compare diff/pull page (1) #37481

zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 29, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-update-needed The document needs to be updated synchronously lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configuration option for PR title default source (branch name vs first commit message)

8 participants