mirror of https://github.com/go-gitea/gitea
Support choose email when creating a commit via web UI (more) (#33445)
Follow #33432pull/33449/head^2
parent
b57d9f41d4
commit
5a7b42dac7
@ -0,0 +1,40 @@ |
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package repo |
||||||
|
|
||||||
|
import ( |
||||||
|
user_model "code.gitea.io/gitea/models/user" |
||||||
|
"code.gitea.io/gitea/modules/log" |
||||||
|
"code.gitea.io/gitea/modules/setting" |
||||||
|
"code.gitea.io/gitea/modules/util" |
||||||
|
"code.gitea.io/gitea/services/context" |
||||||
|
files_service "code.gitea.io/gitea/services/repository/files" |
||||||
|
) |
||||||
|
|
||||||
|
func WebGitOperationCommonData(ctx *context.Context) { |
||||||
|
// TODO: more places like "wiki page" and "merging a pull request or creating an auto merge merging task"
|
||||||
|
emails, err := user_model.GetActivatedEmailAddresses(ctx, ctx.Doer.ID) |
||||||
|
if err != nil { |
||||||
|
log.Error("WebGitOperationCommonData: GetActivatedEmailAddresses: %v", err) |
||||||
|
} |
||||||
|
if ctx.Doer.KeepEmailPrivate { |
||||||
|
emails = append([]string{ctx.Doer.GetPlaceholderEmail()}, emails...) |
||||||
|
} |
||||||
|
ctx.Data["CommitCandidateEmails"] = emails |
||||||
|
ctx.Data["CommitDefaultEmail"] = ctx.Doer.GetEmail() |
||||||
|
} |
||||||
|
|
||||||
|
func WebGitOperationGetCommitChosenEmailIdentity(ctx *context.Context, email string) (_ *files_service.IdentityOptions, valid bool) { |
||||||
|
if ctx.Data["CommitCandidateEmails"] == nil { |
||||||
|
setting.PanicInDevOrTesting("no CommitCandidateEmails in context data") |
||||||
|
} |
||||||
|
emails, _ := ctx.Data["CommitCandidateEmails"].([]string) |
||||||
|
if email == "" { |
||||||
|
return nil, true |
||||||
|
} |
||||||
|
if util.SliceContainsString(emails, email, true) { |
||||||
|
return &files_service.IdentityOptions{GitUserEmail: email}, true |
||||||
|
} |
||||||
|
return nil, false |
||||||
|
} |
@ -1 +0,0 @@ |
|||||||
ref: refs/heads/main |
|
@ -1,8 +0,0 @@ |
|||||||
[core] |
|
||||||
repositoryformatversion = 0 |
|
||||||
filemode = true |
|
||||||
bare = true |
|
||||||
ignorecase = true |
|
||||||
precomposeunicode = true |
|
||||||
[remote "origin"] |
|
||||||
url = https://try.gitea.io/me-heer/test_commit_revert.git |
|
Binary file not shown.
Binary file not shown.
@ -1,3 +0,0 @@ |
|||||||
# pack-refs with: peeled fully-peeled sorted |
|
||||||
46aa6ab2c881ae90e15d9ccfc947d1625c892ce5 refs/heads/develop |
|
||||||
deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7 refs/heads/main |
|
@ -1 +0,0 @@ |
|||||||
deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7 |
|
@ -1,37 +0,0 @@ |
|||||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package integration |
|
||||||
|
|
||||||
import ( |
|
||||||
"net/http" |
|
||||||
"testing" |
|
||||||
|
|
||||||
"code.gitea.io/gitea/tests" |
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert" |
|
||||||
) |
|
||||||
|
|
||||||
func TestRepoMergeCommitRevert(t *testing.T) { |
|
||||||
defer tests.PrepareTestEnv(t)() |
|
||||||
session := loginUser(t, "user2") |
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2/test_commit_revert/_cherrypick/deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7/main?ref=main&refType=branch&cherry-pick-type=revert") |
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK) |
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body) |
|
||||||
req = NewRequestWithValues(t, "POST", "/user2/test_commit_revert/_cherrypick/deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7/main", map[string]string{ |
|
||||||
"_csrf": htmlDoc.GetCSRF(), |
|
||||||
"last_commit": "deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7", |
|
||||||
"page_has_posted": "true", |
|
||||||
"revert": "true", |
|
||||||
"commit_summary": "reverting test commit", |
|
||||||
"commit_message": "test message", |
|
||||||
"commit_choice": "direct", |
|
||||||
"new_branch_name": "test-revert-branch-1", |
|
||||||
}) |
|
||||||
resp = session.MakeRequest(t, req, http.StatusSeeOther) |
|
||||||
|
|
||||||
// A successful revert redirects to the main branch
|
|
||||||
assert.EqualValues(t, "/user2/test_commit_revert/src/branch/main", resp.Header().Get("Location")) |
|
||||||
} |
|
Loading…
Reference in new issue