Skip to content

Commit 0fa3966

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Return `responseText` instead of string in some functions (go-gitea#28836) Fix display latest sync time for pull mirrors on the repo page (go-gitea#28841) Add testing for CalcCommitStatus (go-gitea#28823) Remove duplicated checkinit on git module (go-gitea#28824) Add missing migration (go-gitea#28827) Fix uploaded artifacts should be overwritten (go-gitea#28726)
2 parents e3ade4e + b60a7c3 commit 0fa3966

File tree

16 files changed

+247
-45
lines changed

16 files changed

+247
-45
lines changed

cmd/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ func runGenerateActionsRunnerToken(c *cli.Context) error {
5050
if extra.HasError() {
5151
return handleCliResponseExtra(extra)
5252
}
53-
_, _ = fmt.Printf("%s\n", respText)
53+
_, _ = fmt.Printf("%s\n", respText.Text)
5454
return nil
5555
}

cmd/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ func runKeys(c *cli.Context) error {
7878
if extra.Error != nil {
7979
return extra.Error
8080
}
81-
_, _ = fmt.Fprintln(c.App.Writer, strings.TrimSpace(authorizedString))
81+
_, _ = fmt.Fprintln(c.App.Writer, strings.TrimSpace(authorizedString.Text))
8282
return nil
8383
}

cmd/mailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ func runSendMail(c *cli.Context) error {
4545
if extra.HasError() {
4646
return handleCliResponseExtra(extra)
4747
}
48-
_, _ = fmt.Printf("Sent %s email(s) to all users\n", respText)
48+
_, _ = fmt.Printf("Sent %s email(s) to all users\n", respText.Text)
4949
return nil
5050
}

models/git/commit_status_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,118 @@ func TestGetCommitStatuses(t *testing.T) {
6060
assert.Equal(t, int(maxResults), 5)
6161
assert.Empty(t, statuses)
6262
}
63+
64+
func Test_CalcCommitStatus(t *testing.T) {
65+
kases := []struct {
66+
statuses []*git_model.CommitStatus
67+
expected *git_model.CommitStatus
68+
}{
69+
{
70+
statuses: []*git_model.CommitStatus{
71+
{
72+
State: structs.CommitStatusPending,
73+
},
74+
},
75+
expected: &git_model.CommitStatus{
76+
State: structs.CommitStatusPending,
77+
},
78+
},
79+
{
80+
statuses: []*git_model.CommitStatus{
81+
{
82+
State: structs.CommitStatusSuccess,
83+
},
84+
{
85+
State: structs.CommitStatusPending,
86+
},
87+
},
88+
expected: &git_model.CommitStatus{
89+
State: structs.CommitStatusPending,
90+
},
91+
},
92+
{
93+
statuses: []*git_model.CommitStatus{
94+
{
95+
State: structs.CommitStatusSuccess,
96+
},
97+
{
98+
State: structs.CommitStatusPending,
99+
},
100+
{
101+
State: structs.CommitStatusSuccess,
102+
},
103+
},
104+
expected: &git_model.CommitStatus{
105+
State: structs.CommitStatusPending,
106+
},
107+
},
108+
{
109+
statuses: []*git_model.CommitStatus{
110+
{
111+
State: structs.CommitStatusError,
112+
},
113+
{
114+
State: structs.CommitStatusPending,
115+
},
116+
{
117+
State: structs.CommitStatusSuccess,
118+
},
119+
},
120+
expected: &git_model.CommitStatus{
121+
State: structs.CommitStatusError,
122+
},
123+
},
124+
{
125+
statuses: []*git_model.CommitStatus{
126+
{
127+
State: structs.CommitStatusWarning,
128+
},
129+
{
130+
State: structs.CommitStatusPending,
131+
},
132+
{
133+
State: structs.CommitStatusSuccess,
134+
},
135+
},
136+
expected: &git_model.CommitStatus{
137+
State: structs.CommitStatusWarning,
138+
},
139+
},
140+
{
141+
statuses: []*git_model.CommitStatus{
142+
{
143+
State: structs.CommitStatusSuccess,
144+
},
145+
{
146+
State: structs.CommitStatusSuccess,
147+
},
148+
{
149+
State: structs.CommitStatusSuccess,
150+
},
151+
},
152+
expected: &git_model.CommitStatus{
153+
State: structs.CommitStatusSuccess,
154+
},
155+
},
156+
{
157+
statuses: []*git_model.CommitStatus{
158+
{
159+
State: structs.CommitStatusFailure,
160+
},
161+
{
162+
State: structs.CommitStatusError,
163+
},
164+
{
165+
State: structs.CommitStatusWarning,
166+
},
167+
},
168+
expected: &git_model.CommitStatus{
169+
State: structs.CommitStatusError,
170+
},
171+
},
172+
}
173+
174+
for _, kase := range kases {
175+
assert.Equal(t, kase.expected, git_model.CalcCommitStatus(kase.statuses))
176+
}
177+
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ var migrations = []Migration{
552552
NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID),
553553
// v283 -> v284
554554
NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser),
555+
// v284 -> v285
556+
NewMigration("Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable),
555557
}
556558

557559
// GetCurrentDBVersion returns the current db version

modules/git/git.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ func InitSimple(ctx context.Context) error {
166166
// InitFull initializes git module with version check and change global variables, sync gitconfig.
167167
// It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables.
168168
func InitFull(ctx context.Context) (err error) {
169-
if err = checkInit(); err != nil {
170-
return err
171-
}
172-
173169
if err = InitSimple(ctx); err != nil {
174170
return err
175171
}

modules/private/actions.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ type GenerateTokenRequest struct {
1414
}
1515

1616
// GenerateActionsRunnerToken calls the internal GenerateActionsRunnerToken function
17-
func GenerateActionsRunnerToken(ctx context.Context, scope string) (string, ResponseExtra) {
17+
func GenerateActionsRunnerToken(ctx context.Context, scope string) (*ResponseText, ResponseExtra) {
1818
reqURL := setting.LocalURL + "api/internal/actions/generate_actions_runner_token"
1919

2020
req := newInternalRequest(ctx, reqURL, "POST", GenerateTokenRequest{
2121
Scope: scope,
2222
})
2323

24-
resp, extra := requestJSONResp(req, &responseText{})
25-
if extra.HasError() {
26-
return "", extra
27-
}
28-
return resp.Text, extra
24+
return requestJSONResp(req, &ResponseText{})
2925
}

modules/private/hook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOp
101101
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
102102
req := newInternalRequest(ctx, reqURL, "POST", opts)
103103
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
104-
_, extra := requestJSONResp(req, &responseText{})
104+
_, extra := requestJSONResp(req, &ResponseText{})
105105
return extra
106106
}
107107

@@ -130,14 +130,14 @@ func SetDefaultBranch(ctx context.Context, ownerName, repoName, branch string) R
130130
url.PathEscape(branch),
131131
)
132132
req := newInternalRequest(ctx, reqURL, "POST")
133-
_, extra := requestJSONResp(req, &responseText{})
133+
_, extra := requestJSONResp(req, &ResponseText{})
134134
return extra
135135
}
136136

137137
// SSHLog sends ssh error log response
138138
func SSHLog(ctx context.Context, isErr bool, msg string) error {
139139
reqURL := setting.LocalURL + "api/internal/ssh/log"
140140
req := newInternalRequest(ctx, reqURL, "POST", &SSHLogOption{IsError: isErr, Message: msg})
141-
_, extra := requestJSONResp(req, &responseText{})
141+
_, extra := requestJSONResp(req, &ResponseText{})
142142
return extra.Error
143143
}

modules/private/key.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@ func UpdatePublicKeyInRepo(ctx context.Context, keyID, repoID int64) error {
1515
// Ask for running deliver hook and test pull request tasks.
1616
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update/%d", keyID, repoID)
1717
req := newInternalRequest(ctx, reqURL, "POST")
18-
_, extra := requestJSONResp(req, &responseText{})
18+
_, extra := requestJSONResp(req, &ResponseText{})
1919
return extra.Error
2020
}
2121

2222
// AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
2323
// and returns public key found.
24-
func AuthorizedPublicKeyByContent(ctx context.Context, content string) (string, ResponseExtra) {
24+
func AuthorizedPublicKeyByContent(ctx context.Context, content string) (*ResponseText, ResponseExtra) {
2525
// Ask for running deliver hook and test pull request tasks.
2626
reqURL := setting.LocalURL + "api/internal/ssh/authorized_keys"
2727
req := newInternalRequest(ctx, reqURL, "POST")
2828
req.Param("content", content)
29-
resp, extra := requestJSONResp(req, &responseText{})
30-
if extra.HasError() {
31-
return "", extra
32-
}
33-
return resp.Text, extra
29+
return requestJSONResp(req, &ResponseText{})
3430
}

modules/private/mail.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Email struct {
2020
// It accepts a list of usernames.
2121
// If DB contains these users it will send the email to them.
2222
// If to list == nil, it's supposed to send emails to every user present in DB
23-
func SendEmail(ctx context.Context, subject, message string, to []string) (string, ResponseExtra) {
23+
func SendEmail(ctx context.Context, subject, message string, to []string) (*ResponseText, ResponseExtra) {
2424
reqURL := setting.LocalURL + "api/internal/mail/send"
2525

2626
req := newInternalRequest(ctx, reqURL, "POST", Email{
@@ -29,9 +29,5 @@ func SendEmail(ctx context.Context, subject, message string, to []string) (strin
2929
To: to,
3030
})
3131

32-
resp, extra := requestJSONResp(req, &responseText{})
33-
if extra.HasError() {
34-
return "", extra
35-
}
36-
return resp.Text, extra
32+
return requestJSONResp(req, &ResponseText{})
3733
}

0 commit comments

Comments
 (0)