Skip to content

Commit a69004c

Browse files
committed
Merge branch 'main' into lunny/commit_status_webhook
2 parents 9c24434 + 7cf7a49 commit a69004c

File tree

4 files changed

+95
-9
lines changed

4 files changed

+95
-9
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ enterred_invalid_repo_name = The repository name you entered is incorrect.
584584
enterred_invalid_org_name = The organization name you entered is incorrect.
585585
enterred_invalid_owner_name = The new owner name is not valid.
586586
enterred_invalid_password = The password you entered is incorrect.
587+
unset_password = The login user has not set the password.
588+
unsupported_login_type = The login type is not supported to delete account.
587589
user_not_exist = The user does not exist.
588590
team_not_exist = The team does not exist.
589591
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.

routers/web/user/setting/account.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"code.gitea.io/gitea/modules/timeutil"
2020
"code.gitea.io/gitea/modules/web"
2121
"code.gitea.io/gitea/services/auth"
22+
"code.gitea.io/gitea/services/auth/source/db"
23+
"code.gitea.io/gitea/services/auth/source/smtp"
2224
"code.gitea.io/gitea/services/context"
2325
"code.gitea.io/gitea/services/forms"
2426
"code.gitea.io/gitea/services/mailer"
@@ -242,11 +244,24 @@ func DeleteAccount(ctx *context.Context) {
242244
ctx.Data["PageIsSettingsAccount"] = true
243245

244246
if _, _, err := auth.UserSignIn(ctx, ctx.Doer.Name, ctx.FormString("password")); err != nil {
245-
if user_model.IsErrUserNotExist(err) {
247+
switch {
248+
case user_model.IsErrUserNotExist(err):
249+
loadAccountData(ctx)
250+
251+
ctx.RenderWithErr(ctx.Tr("form.user_not_exist"), tplSettingsAccount, nil)
252+
case errors.Is(err, smtp.ErrUnsupportedLoginType):
253+
loadAccountData(ctx)
254+
255+
ctx.RenderWithErr(ctx.Tr("form.unsupported_login_type"), tplSettingsAccount, nil)
256+
case errors.As(err, &db.ErrUserPasswordNotSet{}):
257+
loadAccountData(ctx)
258+
259+
ctx.RenderWithErr(ctx.Tr("form.unset_password"), tplSettingsAccount, nil)
260+
case errors.As(err, &db.ErrUserPasswordInvalid{}):
246261
loadAccountData(ctx)
247262

248263
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
249-
} else {
264+
default:
250265
ctx.ServerError("UserSignIn", err)
251266
}
252267
return

services/pull/commit_status.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,30 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
3535
}
3636
}
3737

38-
for _, commitStatus := range commitStatuses {
38+
for _, gp := range requiredContextsGlob {
3939
var targetStatus structs.CommitStatusState
40-
for _, gp := range requiredContextsGlob {
40+
for _, commitStatus := range commitStatuses {
4141
if gp.Match(commitStatus.Context) {
4242
targetStatus = commitStatus.State
4343
matchedCount++
4444
break
4545
}
4646
}
4747

48-
if targetStatus != "" && targetStatus.NoBetterThan(returnedStatus) {
48+
// If required rule not match any action, then it is pending
49+
if targetStatus == "" {
50+
if structs.CommitStatusPending.NoBetterThan(returnedStatus) {
51+
returnedStatus = structs.CommitStatusPending
52+
}
53+
break
54+
}
55+
56+
if targetStatus.NoBetterThan(returnedStatus) {
4957
returnedStatus = targetStatus
5058
}
5159
}
5260
}
5361

54-
if matchedCount != len(requiredContexts) {
55-
return structs.CommitStatusPending
56-
}
57-
5862
if matchedCount == 0 {
5963
status := git_model.CalcCommitStatus(commitStatuses)
6064
if status != nil {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 The Gitea Authors.
2+
// All rights reserved.
3+
// SPDX-License-Identifier: MIT
4+
5+
package pull
6+
7+
import (
8+
"testing"
9+
10+
git_model "code.gitea.io/gitea/models/git"
11+
"code.gitea.io/gitea/modules/structs"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestMergeRequiredContextsCommitStatus(t *testing.T) {
17+
testCases := [][]*git_model.CommitStatus{
18+
{
19+
{Context: "Build 1", State: structs.CommitStatusSuccess},
20+
{Context: "Build 2", State: structs.CommitStatusSuccess},
21+
{Context: "Build 3", State: structs.CommitStatusSuccess},
22+
},
23+
{
24+
{Context: "Build 1", State: structs.CommitStatusSuccess},
25+
{Context: "Build 2", State: structs.CommitStatusSuccess},
26+
{Context: "Build 2t", State: structs.CommitStatusPending},
27+
},
28+
{
29+
{Context: "Build 1", State: structs.CommitStatusSuccess},
30+
{Context: "Build 2", State: structs.CommitStatusSuccess},
31+
{Context: "Build 2t", State: structs.CommitStatusFailure},
32+
},
33+
{
34+
{Context: "Build 1", State: structs.CommitStatusSuccess},
35+
{Context: "Build 2", State: structs.CommitStatusSuccess},
36+
{Context: "Build 2t", State: structs.CommitStatusSuccess},
37+
},
38+
{
39+
{Context: "Build 1", State: structs.CommitStatusSuccess},
40+
{Context: "Build 2", State: structs.CommitStatusSuccess},
41+
{Context: "Build 2t", State: structs.CommitStatusSuccess},
42+
},
43+
}
44+
testCasesRequiredContexts := [][]string{
45+
{"Build*"},
46+
{"Build*", "Build 2t*"},
47+
{"Build*", "Build 2t*"},
48+
{"Build*", "Build 2t*", "Build 3*"},
49+
{"Build*", "Build *", "Build 2t*", "Build 1*"},
50+
}
51+
52+
testCasesExpected := []structs.CommitStatusState{
53+
structs.CommitStatusSuccess,
54+
structs.CommitStatusPending,
55+
structs.CommitStatusFailure,
56+
structs.CommitStatusPending,
57+
structs.CommitStatusSuccess,
58+
}
59+
60+
for i, commitStatuses := range testCases {
61+
if MergeRequiredContextsCommitStatus(commitStatuses, testCasesRequiredContexts[i]) != testCasesExpected[i] {
62+
assert.Fail(t, "Test case failed", "Test case %d failed", i+1)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)