Skip to content

Commit 104eecc

Browse files
authored
Merge branch 'go-gitea:main' into main
2 parents e11a339 + 9a071a5 commit 104eecc

File tree

32 files changed

+945
-466
lines changed

32 files changed

+945
-466
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,8 @@ LEVEL = Info
24392439
;DEFAULT_GIT_TREES_PER_PAGE = 1000
24402440
;; Default max size of a blob returned by the blobs API (default is 10MiB)
24412441
;DEFAULT_MAX_BLOB_SIZE = 10485760
2442+
;; Default max combined size of all blobs returned by the files API (default is 100MiB)
2443+
;DEFAULT_MAX_RESPONSE_SIZE = 104857600
24422444

24432445
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24442446
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

models/issues/issue_lock.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import (
1212

1313
// IssueLockOptions defines options for locking and/or unlocking an issue/PR
1414
type IssueLockOptions struct {
15-
Doer *user_model.User
16-
Issue *Issue
15+
Doer *user_model.User
16+
Issue *Issue
17+
18+
// Reason is the doer-provided comment message for the locked issue
19+
// GitHub doesn't support changing the "reasons" by config file, so GitHub has pre-defined "reason" enum values.
20+
// Gitea is not like GitHub, it allows site admin to define customized "reasons" in the config file.
21+
// So the API caller might not know what kind of "reasons" are valid, and the customized reasons are not translatable.
22+
// To make things clear and simple: doer have the chance to use any reason they like, we do not do validation.
1723
Reason string
1824
}
1925

modules/git/repo_object.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,3 @@ func (repo *Repository) hashObject(reader io.Reader, save bool) (string, error)
8585
}
8686
return strings.TrimSpace(stdout.String()), nil
8787
}
88-
89-
// GetRefType gets the type of the ref based on the string
90-
func (repo *Repository) GetRefType(ref string) ObjectType {
91-
if repo.IsTagExist(ref) {
92-
return ObjectTag
93-
} else if repo.IsBranchExist(ref) {
94-
return ObjectBranch
95-
} else if repo.IsCommitExist(ref) {
96-
return ObjectCommit
97-
} else if _, err := repo.GetBlob(ref); err == nil {
98-
return ObjectBlob
99-
}
100-
return ObjectType("invalid")
101-
}

modules/setting/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ var API = struct {
1818
DefaultPagingNum int
1919
DefaultGitTreesPerPage int
2020
DefaultMaxBlobSize int64
21+
DefaultMaxResponseSize int64
2122
}{
2223
EnableSwagger: true,
2324
SwaggerURL: "",
2425
MaxResponseItems: 50,
2526
DefaultPagingNum: 30,
2627
DefaultGitTreesPerPage: 1000,
2728
DefaultMaxBlobSize: 10485760,
29+
DefaultMaxResponseSize: 104857600,
2830
}
2931

3032
func loadAPIFrom(rootCfg ConfigProvider) {

modules/structs/git_blob.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package structs
55

66
// GitBlobResponse represents a git blob
77
type GitBlobResponse struct {
8-
Content string `json:"content"`
9-
Encoding string `json:"encoding"`
10-
URL string `json:"url"`
11-
SHA string `json:"sha"`
12-
Size int64 `json:"size"`
8+
Content *string `json:"content"`
9+
Encoding *string `json:"encoding"`
10+
URL string `json:"url"`
11+
SHA string `json:"sha"`
12+
Size int64 `json:"size"`
1313
}

modules/structs/issue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,8 @@ type IssueMeta struct {
266266
Owner string `json:"owner"`
267267
Name string `json:"repo"`
268268
}
269+
270+
// LockIssueOption options to lock an issue
271+
type LockIssueOption struct {
272+
Reason string `json:"lock_reason"`
273+
}

modules/structs/repo_file.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ type FileDeleteResponse struct {
176176
Commit *FileCommitResponse `json:"commit"`
177177
Verification *PayloadCommitVerification `json:"verification"`
178178
}
179+
180+
// GetFilesOptions options for retrieving metadate and content of multiple files
181+
type GetFilesOptions struct {
182+
Files []string `json:"files" binding:"Required"`
183+
}

modules/structs/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type GeneralAPISettings struct {
2626
DefaultPagingNum int `json:"default_paging_num"`
2727
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
2828
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
29+
DefaultMaxResponseSize int64 `json:"default_max_response_size"`
2930
}
3031

3132
// GeneralAttachmentSettings contains global Attachment settings exposed by API

options/locale/locale_en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,6 @@ issues.pin_comment = "pinned this %s"
16811681
issues.unpin_comment = "unpinned this %s"
16821682
issues.lock = Lock conversation
16831683
issues.unlock = Unlock conversation
1684-
issues.lock.unknown_reason = Cannot lock an issue with an unknown reason.
16851684
issues.lock_duplicate = An issue cannot be locked twice.
16861685
issues.unlock_error = Cannot unlock an issue that is not locked.
16871686
issues.lock_with_reason = "locked as <strong>%s</strong> and limited conversation to collaborators %s"

routers/api/v1/api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,14 +1389,17 @@ func Routes() *web.Router {
13891389
m.Post("/diffpatch", reqRepoWriter(unit.TypeCode), reqToken(), bind(api.ApplyDiffPatchFileOptions{}), mustNotBeArchived, repo.ApplyDiffPatch)
13901390
m.Group("/contents", func() {
13911391
m.Get("", repo.GetContentsList)
1392-
m.Post("", reqToken(), bind(api.ChangeFilesOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.ChangeFiles)
13931392
m.Get("/*", repo.GetContents)
1393+
m.Post("", reqToken(), bind(api.ChangeFilesOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.ChangeFiles)
13941394
m.Group("/*", func() {
13951395
m.Post("", bind(api.CreateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.CreateFile)
13961396
m.Put("", bind(api.UpdateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.UpdateFile)
13971397
m.Delete("", bind(api.DeleteFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.DeleteFile)
13981398
}, reqToken())
1399-
}, reqRepoReader(unit.TypeCode))
1399+
}, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
1400+
m.Combo("/file-contents", reqRepoReader(unit.TypeCode), context.ReferencesGitRepo()).
1401+
Get(repo.GetFileContentsGet).
1402+
Post(bind(api.GetFilesOptions{}), repo.GetFileContentsPost) // POST method requires "write" permission, so we also support "GET" method above
14001403
m.Get("/signing-key.gpg", misc.SigningKey)
14011404
m.Group("/topics", func() {
14021405
m.Combo("").Get(repo.ListTopics).
@@ -1530,6 +1533,11 @@ func Routes() *web.Router {
15301533
Delete(reqToken(), reqAdmin(), repo.UnpinIssue)
15311534
m.Patch("/{position}", reqToken(), reqAdmin(), repo.MoveIssuePin)
15321535
})
1536+
m.Group("/lock", func() {
1537+
m.Combo("").
1538+
Put(bind(api.LockIssueOption{}), repo.LockIssue).
1539+
Delete(repo.UnlockIssue)
1540+
}, reqToken(), reqAdmin())
15331541
})
15341542
}, mustEnableIssuesOrPulls)
15351543
m.Group("/labels", func() {

0 commit comments

Comments
 (0)