Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f77c40e

Browse files
authored
Merge branch 'main' into lunny/refactor_diff_funcs
2 parents 0749bb5 + 22c4599 commit f77c40e

File tree

222 files changed

+1710
-1064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+1710
-1064
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ linters:
1919
- revive
2020
- staticcheck
2121
- stylecheck
22+
- tenv
23+
- testifylint
2224
- typecheck
2325
- unconvert
2426
- unused
@@ -34,6 +36,10 @@ output:
3436
show-stats: true
3537

3638
linters-settings:
39+
testifylint:
40+
disable:
41+
- go-require
42+
- require-error
3743
stylecheck:
3844
checks: ["all", "-ST1005", "-ST1003"]
3945
nakedret:

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Wim <[email protected]> (@42wim)
4646
Jason Song <[email protected]> (@wolfogre)
4747
Yarden Shoham <[email protected]> (@yardenshoham)
4848
Yu Tian <[email protected]> (@Zettat123)
49-
Eddie Yang <[email protected]> (@yp05327)
5049
Dong Ge <[email protected]> (@sillyguodong)
5150
Xinyi Gong <[email protected]> (@HesterG)
5251
wxiaoguang <[email protected]> (@wxiaoguang)

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ XGO_VERSION := go-1.23.x
2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/[email protected]
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
@@ -377,12 +377,12 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
377377
.PHONY: lint-js
378378
lint-js: node_modules
379379
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
380-
# npx vue-tsc
380+
npx vue-tsc
381381

382382
.PHONY: lint-js-fix
383383
lint-js-fix: node_modules
384384
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
385-
# npx vue-tsc
385+
npx vue-tsc
386386

387387
.PHONY: lint-css
388388
lint-css: node_modules
@@ -451,10 +451,6 @@ lint-templates: .venv node_modules
451451
lint-yaml: .venv
452452
@poetry run yamllint .
453453

454-
.PHONY: tsc
455-
tsc:
456-
npx vue-tsc
457-
458454
.PHONY: watch
459455
watch:
460456
@bash tools/watch.sh

custom/conf/app.example.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,13 @@ LEVEL = Info
10401040
;; Don't allow download source archive files from UI
10411041
;DISABLE_DOWNLOAD_SOURCE_ARCHIVES = false
10421042

1043-
;; Allow fork repositories without maximum number limit
1043+
;; Allow to fork repositories without maximum number limit
10441044
;ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT = true
10451045

1046+
;; Allow to fork repositories into the same owner (user or organization)
1047+
;; This feature is experimental, not fully tested, and may be changed in the future
1048+
;ALLOW_FORK_INTO_SAME_OWNER = false
1049+
10461050
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10471051
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10481052
;[repository.editor]

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require (
4848
github.com/ethantkoenig/rupture v1.0.1
4949
github.com/felixge/fgprof v0.9.5
5050
github.com/fsnotify/fsnotify v1.7.0
51-
github.com/gliderlabs/ssh v0.3.7
51+
github.com/gliderlabs/ssh v0.3.8
5252
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
5353
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73
5454
github.com/go-chi/chi/v5 v5.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
293293
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
294294
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 h1:mtDjlmloH7ytdblogrMz1/8Hqua1y8B4ID+bh3rvod0=
295295
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1/go.mod h1:fenKRzpXDjNpsIBhuhUzvjCKlDjKam0boRAenTE0Q6A=
296-
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
297-
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
296+
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
297+
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
298298
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
299299
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
300300
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c h1:82lzmsy5Nr6JA6HcLRVxGfbdSoWfW45C6jnY3zFS7Ks=

models/actions/run_job.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
137137
if err != nil {
138138
return 0, err
139139
}
140-
run.Status = aggregateJobStatus(jobs)
140+
run.Status = AggregateJobStatus(jobs)
141141
if run.Started.IsZero() && run.Status.IsRunning() {
142142
run.Started = timeutil.TimeStampNow()
143143
}
@@ -152,29 +152,35 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
152152
return affected, nil
153153
}
154154

155-
func aggregateJobStatus(jobs []*ActionRunJob) Status {
156-
allDone := true
157-
allWaiting := true
158-
hasFailure := false
155+
func AggregateJobStatus(jobs []*ActionRunJob) Status {
156+
allSuccessOrSkipped := len(jobs) != 0
157+
allSkipped := len(jobs) != 0
158+
var hasFailure, hasCancelled, hasWaiting, hasRunning, hasBlocked bool
159159
for _, job := range jobs {
160-
if !job.Status.IsDone() {
161-
allDone = false
162-
}
163-
if job.Status != StatusWaiting && !job.Status.IsDone() {
164-
allWaiting = false
165-
}
166-
if job.Status == StatusFailure || job.Status == StatusCancelled {
167-
hasFailure = true
168-
}
160+
allSuccessOrSkipped = allSuccessOrSkipped && (job.Status == StatusSuccess || job.Status == StatusSkipped)
161+
allSkipped = allSkipped && job.Status == StatusSkipped
162+
hasFailure = hasFailure || job.Status == StatusFailure
163+
hasCancelled = hasCancelled || job.Status == StatusCancelled
164+
hasWaiting = hasWaiting || job.Status == StatusWaiting
165+
hasRunning = hasRunning || job.Status == StatusRunning
166+
hasBlocked = hasBlocked || job.Status == StatusBlocked
169167
}
170-
if allDone {
171-
if hasFailure {
172-
return StatusFailure
173-
}
168+
switch {
169+
case allSkipped:
170+
return StatusSkipped
171+
case allSuccessOrSkipped:
174172
return StatusSuccess
175-
}
176-
if allWaiting {
173+
case hasCancelled:
174+
return StatusCancelled
175+
case hasFailure:
176+
return StatusFailure
177+
case hasRunning:
178+
return StatusRunning
179+
case hasWaiting:
177180
return StatusWaiting
181+
case hasBlocked:
182+
return StatusBlocked
183+
default:
184+
return StatusUnknown // it shouldn't happen
178185
}
179-
return StatusRunning
180186
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package actions
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestAggregateJobStatus(t *testing.T) {
13+
testStatuses := func(expected Status, statuses []Status) {
14+
t.Helper()
15+
var jobs []*ActionRunJob
16+
for _, v := range statuses {
17+
jobs = append(jobs, &ActionRunJob{Status: v})
18+
}
19+
actual := AggregateJobStatus(jobs)
20+
if !assert.Equal(t, expected, actual) {
21+
var statusStrings []string
22+
for _, s := range statuses {
23+
statusStrings = append(statusStrings, s.String())
24+
}
25+
t.Errorf("AggregateJobStatus(%v) = %v, want %v", statusStrings, statusNames[actual], statusNames[expected])
26+
}
27+
}
28+
29+
cases := []struct {
30+
statuses []Status
31+
expected Status
32+
}{
33+
// unknown cases, maybe it shouldn't happen in real world
34+
{[]Status{}, StatusUnknown},
35+
{[]Status{StatusUnknown, StatusSuccess}, StatusUnknown},
36+
{[]Status{StatusUnknown, StatusSkipped}, StatusUnknown},
37+
{[]Status{StatusUnknown, StatusFailure}, StatusFailure},
38+
{[]Status{StatusUnknown, StatusCancelled}, StatusCancelled},
39+
{[]Status{StatusUnknown, StatusWaiting}, StatusWaiting},
40+
{[]Status{StatusUnknown, StatusRunning}, StatusRunning},
41+
{[]Status{StatusUnknown, StatusBlocked}, StatusBlocked},
42+
43+
// success with other status
44+
{[]Status{StatusSuccess}, StatusSuccess},
45+
{[]Status{StatusSuccess, StatusSkipped}, StatusSuccess}, // skipped doesn't affect success
46+
{[]Status{StatusSuccess, StatusFailure}, StatusFailure},
47+
{[]Status{StatusSuccess, StatusCancelled}, StatusCancelled},
48+
{[]Status{StatusSuccess, StatusWaiting}, StatusWaiting},
49+
{[]Status{StatusSuccess, StatusRunning}, StatusRunning},
50+
{[]Status{StatusSuccess, StatusBlocked}, StatusBlocked},
51+
52+
// any cancelled, then cancelled
53+
{[]Status{StatusCancelled}, StatusCancelled},
54+
{[]Status{StatusCancelled, StatusSuccess}, StatusCancelled},
55+
{[]Status{StatusCancelled, StatusSkipped}, StatusCancelled},
56+
{[]Status{StatusCancelled, StatusFailure}, StatusCancelled},
57+
{[]Status{StatusCancelled, StatusWaiting}, StatusCancelled},
58+
{[]Status{StatusCancelled, StatusRunning}, StatusCancelled},
59+
{[]Status{StatusCancelled, StatusBlocked}, StatusCancelled},
60+
61+
// failure with other status, fail fast
62+
// Should "running" win? Maybe no: old code does make "running" win, but GitHub does fail fast.
63+
{[]Status{StatusFailure}, StatusFailure},
64+
{[]Status{StatusFailure, StatusSuccess}, StatusFailure},
65+
{[]Status{StatusFailure, StatusSkipped}, StatusFailure},
66+
{[]Status{StatusFailure, StatusCancelled}, StatusCancelled},
67+
{[]Status{StatusFailure, StatusWaiting}, StatusFailure},
68+
{[]Status{StatusFailure, StatusRunning}, StatusFailure},
69+
{[]Status{StatusFailure, StatusBlocked}, StatusFailure},
70+
71+
// skipped with other status
72+
// TODO: need to clarify whether a PR with "skipped" job status is considered as "mergeable" or not.
73+
{[]Status{StatusSkipped}, StatusSkipped},
74+
{[]Status{StatusSkipped, StatusSuccess}, StatusSuccess},
75+
{[]Status{StatusSkipped, StatusFailure}, StatusFailure},
76+
{[]Status{StatusSkipped, StatusCancelled}, StatusCancelled},
77+
{[]Status{StatusSkipped, StatusWaiting}, StatusWaiting},
78+
{[]Status{StatusSkipped, StatusRunning}, StatusRunning},
79+
{[]Status{StatusSkipped, StatusBlocked}, StatusBlocked},
80+
}
81+
82+
for _, c := range cases {
83+
testStatuses(c.expected, c.statuses)
84+
}
85+
}

models/actions/runner_token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestGetLatestRunnerToken(t *testing.T) {
1717
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
1818
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
1919
assert.NoError(t, err)
20-
assert.EqualValues(t, token, expectedToken)
20+
assert.EqualValues(t, expectedToken, token)
2121
}
2222

2323
func TestNewRunnerToken(t *testing.T) {
@@ -26,7 +26,7 @@ func TestNewRunnerToken(t *testing.T) {
2626
assert.NoError(t, err)
2727
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
2828
assert.NoError(t, err)
29-
assert.EqualValues(t, token, expectedToken)
29+
assert.EqualValues(t, expectedToken, token)
3030
}
3131

3232
func TestUpdateRunnerToken(t *testing.T) {
@@ -36,5 +36,5 @@ func TestUpdateRunnerToken(t *testing.T) {
3636
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
3737
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
3838
assert.NoError(t, err)
39-
assert.EqualValues(t, token, expectedToken)
39+
assert.EqualValues(t, expectedToken, token)
4040
}

models/activities/user_heatmap_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package activities_test
55

66
import (
7-
"fmt"
87
"testing"
98
"time"
109

@@ -91,11 +90,11 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
9190
assert.NoError(t, err)
9291
assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?")
9392
assert.Equal(t, count, int64(contributions))
94-
assert.Equal(t, tc.CountResult, contributions, fmt.Sprintf("testcase '%s'", tc.desc))
93+
assert.Equal(t, tc.CountResult, contributions, "testcase '%s'", tc.desc)
9594

9695
// Test JSON rendering
9796
jsonData, err := json.Marshal(heatmap)
9897
assert.NoError(t, err)
99-
assert.Equal(t, tc.JSONResult, string(jsonData))
98+
assert.JSONEq(t, tc.JSONResult, string(jsonData))
10099
}
101100
}

0 commit comments

Comments
 (0)