-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Use GitHub-style commit message for squash merge #35987
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2cfeb0b
github-style format
Zettat123 b3f6b8c
fix tests
wxiaoguang 4b08bbd
fix comment
Zettat123 57ffa78
fix tests
Zettat123 de6634f
fix corrupted utf8
wxiaoguang e5066a4
fix comment
wxiaoguang 3bf6396
fix utf8 handling
wxiaoguang e362d18
comment
wxiaoguang 131ebfd
Merge branch 'main' into improve-squash-message
GiteaBot 158710d
Merge branch 'improve-squash-message' of github.com:Zettat123/gitea i…
lunny 5dfea16
Merge branch 'main' into improve-squash-message
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| api "code.gitea.io/gitea/modules/structs" | ||
| "code.gitea.io/gitea/modules/test" | ||
| "code.gitea.io/gitea/modules/translation" | ||
| "code.gitea.io/gitea/modules/util" | ||
| "code.gitea.io/gitea/services/automerge" | ||
| "code.gitea.io/gitea/services/automergequeue" | ||
| pull_service "code.gitea.io/gitea/services/pull" | ||
|
|
@@ -1180,3 +1181,170 @@ func TestPullNonMergeForAdminWithBranchProtection(t *testing.T) { | |
| session.MakeRequest(t, mergeReq, http.StatusMethodNotAllowed) | ||
| }) | ||
| } | ||
|
|
||
| func TestPullSquashMessage(t *testing.T) { | ||
| onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { | ||
| user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) | ||
| user2Session := loginUser(t, user2.Name) | ||
|
|
||
| defer test.MockVariableValue(&setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages, true)() | ||
| defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 512)() | ||
|
|
||
| repo, err := repo_service.CreateRepository(t.Context(), user2, user2, repo_service.CreateRepoOptions{ | ||
| Name: "squash-message-test", | ||
| Description: "Test squash message", | ||
| AutoInit: true, | ||
| Readme: "Default", | ||
| DefaultBranch: "main", | ||
| }) | ||
| assert.NoError(t, err) | ||
|
|
||
| type commitInfo struct { | ||
| userName string | ||
| commitSummary string | ||
| commitMessage string | ||
| } | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| commitInfos []*commitInfo | ||
| expectedMessage string | ||
| }{ | ||
| { | ||
| name: "Only summaries", | ||
| commitInfos: []*commitInfo{ | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Implement the login endpoint", | ||
| }, | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Validate request body", | ||
| }, | ||
| }, | ||
| expectedMessage: `* Implement the login endpoint | ||
|
|
||
| * Validate request body | ||
|
|
||
| `, | ||
| }, | ||
| { | ||
| name: "Summaries and messages", | ||
| commitInfos: []*commitInfo{ | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Refactor user service", | ||
| commitMessage: `Implement the login endpoint. | ||
| Validate request body.`, | ||
| }, | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Add email notification service", | ||
| commitMessage: `Implements a new email notification module. | ||
|
|
||
| - Supports templating | ||
| - Supports HTML and plain text modes | ||
| - Includes retry logic`, | ||
| }, | ||
| }, | ||
| expectedMessage: `* Refactor user service | ||
|
|
||
| Implement the login endpoint. | ||
| Validate request body. | ||
|
|
||
| * Add email notification service | ||
|
|
||
| Implements a new email notification module. | ||
|
|
||
| - Supports templating | ||
| - Supports HTML and plain text modes | ||
| - Includes retry logic | ||
|
|
||
| `, | ||
| }, | ||
| { | ||
| name: "Long Message", | ||
| commitInfos: []*commitInfo{ | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Add advanced validation logic for user onboarding", | ||
| commitMessage: `This commit introduces a comprehensive validation layer for the user onboarding flow. | ||
| The primary goal is to ensure that all input data is strictly validated before being processed by downstream services. | ||
| This improves system reliability and significantly reduces runtime exceptions in the registration pipeline. | ||
|
|
||
| The validation logic includes: | ||
|
|
||
| 1. Email format checking using RFC 5322-compliant patterns. | ||
| 2. Username length and character limitation enforcement. | ||
| 3. Password strength enforcement, including: | ||
| - Minimum length checks | ||
| - Mixed character type detection | ||
| - Optional entropy-based scoring | ||
| 4. Optional phone number validation using region-specific rules. | ||
| `, | ||
wxiaoguang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| expectedMessage: `* Add advanced validation logic for user onboarding | ||
|
|
||
| This commit introduces a comprehensive validation layer for the user onboarding flow. | ||
| The primary goal is to ensure that all input data is strictly validated before being processed by downstream services. | ||
| This improves system reliability and significantly reduces runtime exceptions in the registration pipeline. | ||
|
|
||
| The validation logic includes: | ||
|
|
||
| 1. Email format checking using RFC 5322-compliant patterns. | ||
| 2. Username length and character limitation enforceme...`, | ||
| }, | ||
| { | ||
| name: "Test Co-authored-by", | ||
| commitInfos: []*commitInfo{ | ||
| { | ||
| userName: user2.Name, | ||
| commitSummary: "Implement the login endpoint", | ||
| }, | ||
| { | ||
| userName: "user4", | ||
| commitSummary: "Validate request body", | ||
| }, | ||
| }, | ||
| expectedMessage: `* Implement the login endpoint | ||
|
|
||
| * Validate request body | ||
|
|
||
| --------- | ||
|
|
||
| Co-authored-by: user4 <[email protected]> | ||
| `, | ||
| }, | ||
| } | ||
|
|
||
| for tcNum, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| branchName := "test-branch-" + strconv.Itoa(tcNum) | ||
| for infoIdx, info := range tc.commitInfos { | ||
| createFileOpts := createFileInBranchOptions{ | ||
| CommitMessage: info.commitSummary + "\n\n" + info.commitMessage, | ||
| CommitterName: info.userName, | ||
| CommitterEmail: util.Iif(info.userName != "", info.userName+"@example.com", ""), | ||
| OldBranch: util.Iif(infoIdx == 0, "main", branchName), | ||
| NewBranch: branchName, | ||
| } | ||
| testCreateFileInBranch(t, user2, repo, createFileOpts, map[string]string{"dummy-file-" + strconv.Itoa(infoIdx): "dummy content"}) | ||
| } | ||
| resp := testPullCreateDirectly(t, user2Session, createPullRequestOptions{ | ||
| BaseRepoOwner: user2.Name, | ||
| BaseRepoName: repo.Name, | ||
| BaseBranch: repo.DefaultBranch, | ||
| HeadBranch: branchName, | ||
| Title: "Pull for " + branchName, | ||
| }) | ||
| elems := strings.Split(test.RedirectURL(resp), "/") | ||
| pullIndex, err := strconv.Atoi(elems[4]) | ||
| assert.NoError(t, err) | ||
| pullRequest := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, Index: int64(pullIndex)}) | ||
| squashMergeCommitMessage := pull_service.GetSquashMergeCommitMessages(t.Context(), pullRequest) | ||
| assert.Equal(t, tc.expectedMessage, squashMergeCommitMessage) | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really a good result?
Not sure whether GitHub does so. Even if GitHub does so, I don't think GitHub was right or we need to blindly follow GitHub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't quite understand where the problem is. We add
*before every commit message and-comes from the commit message content.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
commit1:
commit2:
The current code generates:
It looks like there are 6 commits.
But ideally it should be:
Just my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, GitHub does the same thing.
Using
*in commit messages can make it difficult to distinguish between multiple messages. However, since the squash commit message is editable, I think that users can manually fix such issues if necessary.