Skip to content

Commit 7d59180

Browse files
authored
Merge branch 'main' into viewed-files
2 parents 243b824 + f034ee6 commit 7d59180

File tree

155 files changed

+747
-435
lines changed

Some content is hidden

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

155 files changed

+747
-435
lines changed

build.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build vendor
6-
// +build vendor
76

87
package main
98

build/code-batch-process.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/generate-bindata.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/generate-emoji.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// license that can be found in the LICENSE file.
55

66
//go:build ignore
7-
// +build ignore
87

98
package main
109

build/generate-gitignores.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build ignore
2-
// +build ignore
32

43
package main
54

build/generate-licenses.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build ignore
2-
// +build ignore
32

43
package main
54

build/gitea-format-imports.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/gocovmerge.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// merges them into one profile
88

99
//go:build ignore
10-
// +build ignore
1110

1211
package main
1312

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func runCreateUser(c *cli.Context) error {
556556

557557
// If this is the first user being created.
558558
// Take it as the admin and don't force a password update.
559-
if n := user_model.CountUsers(); n == 0 {
559+
if n := user_model.CountUsers(nil); n == 0 {
560560
changePassword = false
561561
}
562562

cmd/embedded.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build bindata
6-
// +build bindata
76

87
package cmd
98

cmd/embedded_stub.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !bindata
6-
// +build !bindata
76

87
package cmd
98

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,9 @@ PATH =
22402240
;;
22412241
;; Enable/Disable federation capabilities
22422242
; ENABLED = true
2243+
;;
2244+
;; Enable/Disable user statistics for nodeinfo if federation is enabled
2245+
; SHARE_USER_STATISTICS = true
22432246

22442247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22452248
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
10851085
## Federation (`federation`)
10861086

10871087
- `ENABLED`: **true**: Enable/Disable federation capabilities
1088+
- `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled
10881089

10891090
## Packages (`packages`)
10901091

docs/content/doc/installation/from-binary.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Of note, configuring `GITEA_WORK_DIR` will tell Gitea where to base its working
5050

5151
### Prepare environment
5252

53-
Check that Git is installed on the server. If it is not, install it first.
53+
Check that Git is installed on the server. If it is not, install it first. Gitea requires Git version >= 2.0.
54+
5455
```sh
5556
git --version
5657
```

docs/content/doc/installation/on-kubernetes.en-us.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,47 @@ helm install gitea gitea-charts/gitea
2525
```
2626

2727
If you would like to customize your install, which includes kubernetes ingress, please refer to the complete [Gitea helm chart configuration details](https://gitea.com/gitea/helm-chart/)
28+
29+
## Health check endpoint
30+
31+
Gitea comes with a health check endpoint `/api/healthz`, you can configure it in kubernetes like this:
32+
33+
```yaml
34+
livenessProbe:
35+
httpGet:
36+
path: /api/healthz
37+
port: http
38+
initialDelaySeconds: 200
39+
timeoutSeconds: 5
40+
periodSeconds: 10
41+
successThreshold: 1
42+
failureThreshold: 10
43+
```
44+
45+
a successful health check response will respond with http code `200`, here's example:
46+
47+
```
48+
HTTP/1.1 200 OK
49+
50+
51+
{
52+
"status": "pass",
53+
"description": "Gitea: Git with a cup of tea",
54+
"checks": {
55+
"cache:ping": [
56+
{
57+
"status": "pass",
58+
"time": "2022-02-19T09:16:08Z"
59+
}
60+
],
61+
"database:ping": [
62+
{
63+
"status": "pass",
64+
"time": "2022-02-19T09:16:08Z"
65+
}
66+
]
67+
}
68+
}
69+
```
70+
71+
for more information, please reference to kubernetes documentation [Define a liveness HTTP request](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-http-request)

docs/content/doc/installation/on-kubernetes.zh-tw.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,47 @@ helm install gitea gitea-charts/gitea
2525
```
2626

2727
若您想自訂安裝(包括使用 kubernetes ingress),請前往完整的 [Gitea helm chart configuration details](https://gitea.com/gitea/helm-chart/)
28+
29+
##運行狀況檢查終端節點
30+
31+
Gitea 附帶了一個運行狀況檢查端點 `/api/healthz`,你可以像這樣在 kubernetes 中配置它:
32+
33+
```yaml
34+
livenessProbe:
35+
httpGet:
36+
path: /api/healthz
37+
port: http
38+
initialDelaySeconds: 200
39+
timeoutSeconds: 5
40+
periodSeconds: 10
41+
successThreshold: 1
42+
failureThreshold: 10
43+
```
44+
45+
成功的運行狀況檢查回應將使用 HTTP 代碼 `200` 進行回應,下面是示例:
46+
47+
```
48+
HTTP/1.1 200 OK
49+
50+
51+
{
52+
"status": "pass",
53+
"description": "Gitea: Git with a cup of tea",
54+
"checks": {
55+
"cache:ping": [
56+
{
57+
"status": "pass",
58+
"time": "2022-02-19T09:16:08Z"
59+
}
60+
],
61+
"database:ping": [
62+
{
63+
"status": "pass",
64+
"time": "2022-02-19T09:16:08Z"
65+
}
66+
]
67+
}
68+
}
69+
```
70+
71+
有關更多信息,請參考kubernetes文檔[定義一個存活態 HTTP請求接口](https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)

integrations/api_nodeinfo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func TestNodeinfo(t *testing.T) {
2626
resp := MakeRequest(t, req, http.StatusOK)
2727
var nodeinfo api.NodeInfo
2828
DecodeJSON(t, resp, &nodeinfo)
29+
assert.True(t, nodeinfo.OpenRegistrations)
2930
assert.Equal(t, "gitea", nodeinfo.Software.Name)
31+
assert.Equal(t, 23, nodeinfo.Usage.Users.Total)
32+
assert.Equal(t, 15, nodeinfo.Usage.LocalPosts)
33+
assert.Equal(t, 2, nodeinfo.Usage.LocalComments)
3034
})
3135
}

integrations/pull_merge_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ func TestCantMergeConflict(t *testing.T) {
243243
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
244244
assert.NoError(t, err)
245245

246-
err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT")
246+
err = pull.Merge(pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT")
247247
assert.Error(t, err, "Merge should return an error due to conflict")
248248
assert.True(t, models.IsErrMergeConflicts(err), "Merge error is not a conflict error")
249249

250-
err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT")
250+
err = pull.Merge(pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT")
251251
assert.Error(t, err, "Merge should return an error due to conflict")
252252
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
253253
gitRepo.Close()
@@ -342,7 +342,7 @@ func TestCantMergeUnrelated(t *testing.T) {
342342
BaseBranch: "base",
343343
}).(*models.PullRequest)
344344

345-
err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED")
345+
err = pull.Merge(pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED")
346346
assert.Error(t, err, "Merge should return an error due to unrelated")
347347
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
348348
gitRepo.Close()

models/auth/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func deleteOAuth2Application(sess db.Engine, id, userid int64) error {
245245
"oauth2_authorization_code.grant_id = oauth2_grant.id AND oauth2_grant.application_id = ?", id).Find(&codes); err != nil {
246246
return err
247247
}
248-
codeIDs := make([]int64, 0)
248+
codeIDs := make([]int64, 0, len(codes))
249249
for _, grant := range codes {
250250
codeIDs = append(codeIDs, grant.ID)
251251
}

models/branches.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
104104
}
105105

106106
// IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch
107-
func IsUserMergeWhitelisted(protectBranch *ProtectedBranch, userID int64, permissionInRepo Permission) bool {
107+
func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch, userID int64, permissionInRepo Permission) bool {
108108
if !protectBranch.EnableMergeWhitelist {
109109
// Then we need to fall back on whether the user has write permission
110110
return permissionInRepo.CanWrite(unit.TypeCode)
@@ -118,7 +118,7 @@ func IsUserMergeWhitelisted(protectBranch *ProtectedBranch, userID int64, permis
118118
return false
119119
}
120120

121-
in, err := organization.IsUserInTeams(db.DefaultContext, userID, protectBranch.MergeWhitelistTeamIDs)
121+
in, err := organization.IsUserInTeams(ctx, userID, protectBranch.MergeWhitelistTeamIDs)
122122
if err != nil {
123123
log.Error("IsUserInTeams: %v", err)
124124
return false
@@ -159,16 +159,16 @@ func isUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch,
159159
}
160160

161161
// HasEnoughApprovals returns true if pr has enough granted approvals.
162-
func (protectBranch *ProtectedBranch) HasEnoughApprovals(pr *PullRequest) bool {
162+
func (protectBranch *ProtectedBranch) HasEnoughApprovals(ctx context.Context, pr *PullRequest) bool {
163163
if protectBranch.RequiredApprovals == 0 {
164164
return true
165165
}
166-
return protectBranch.GetGrantedApprovalsCount(pr) >= protectBranch.RequiredApprovals
166+
return protectBranch.GetGrantedApprovalsCount(ctx, pr) >= protectBranch.RequiredApprovals
167167
}
168168

169169
// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
170-
func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 {
171-
sess := db.GetEngine(db.DefaultContext).Where("issue_id = ?", pr.IssueID).
170+
func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(ctx context.Context, pr *PullRequest) int64 {
171+
sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
172172
And("type = ?", ReviewTypeApprove).
173173
And("official = ?", true).
174174
And("dismissed = ?", false)
@@ -185,11 +185,11 @@ func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest)
185185
}
186186

187187
// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews
188-
func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullRequest) bool {
188+
func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(ctx context.Context, pr *PullRequest) bool {
189189
if !protectBranch.BlockOnRejectedReviews {
190190
return false
191191
}
192-
rejectExist, err := db.GetEngine(db.DefaultContext).Where("issue_id = ?", pr.IssueID).
192+
rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
193193
And("type = ?", ReviewTypeReject).
194194
And("official = ?", true).
195195
And("dismissed = ?", false).
@@ -204,11 +204,11 @@ func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullReque
204204

205205
// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer
206206
// of from official review
207-
func (protectBranch *ProtectedBranch) MergeBlockedByOfficialReviewRequests(pr *PullRequest) bool {
207+
func (protectBranch *ProtectedBranch) MergeBlockedByOfficialReviewRequests(ctx context.Context, pr *PullRequest) bool {
208208
if !protectBranch.BlockOnOfficialReviewRequests {
209209
return false
210210
}
211-
has, err := db.GetEngine(db.DefaultContext).Where("issue_id = ?", pr.IssueID).
211+
has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
212212
And("type = ?", ReviewTypeRequest).
213213
And("official = ?", true).
214214
Exist(new(Review))

models/db/context.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,22 @@ func WithContext(f func(ctx *Context) error) error {
103103
}
104104

105105
// WithTx represents executing database operations on a transaction
106-
func WithTx(f func(ctx context.Context) error) error {
106+
// you can optionally change the context to a parrent one
107+
func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error {
108+
parentCtx := DefaultContext
109+
if len(stdCtx) != 0 && stdCtx[0] != nil {
110+
// TODO: make sure parent context has no open session
111+
parentCtx = stdCtx[0]
112+
}
113+
107114
sess := x.NewSession()
108115
defer sess.Close()
109116
if err := sess.Begin(); err != nil {
110117
return err
111118
}
112119

113120
if err := f(&Context{
114-
Context: DefaultContext,
121+
Context: parentCtx,
115122
e: sess,
116123
}); err != nil {
117124
return err

models/error.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ type ErrInvalidCloneAddr struct {
296296
IsProtocolInvalid bool
297297
IsPermissionDenied bool
298298
LocalPath bool
299-
NotResolvedIP bool
300299
}
301300

302301
// IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
@@ -306,9 +305,6 @@ func IsErrInvalidCloneAddr(err error) bool {
306305
}
307306

308307
func (err *ErrInvalidCloneAddr) Error() string {
309-
if err.NotResolvedIP {
310-
return fmt.Sprintf("migration/cloning from '%s' is not allowed: unknown hostname", err.Host)
311-
}
312308
if err.IsInvalidPath {
313309
return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided path is invalid", err.Host)
314310
}

0 commit comments

Comments
 (0)