Skip to content

Commit aac4a5e

Browse files
committed
Merge branch 'master' into issue_15373
2 parents 205043c + c4d70a0 commit aac4a5e

File tree

185 files changed

+5757
-2079
lines changed

Some content is hidden

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

185 files changed

+5757
-2079
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require (
5252
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
5353
github.com/golang-jwt/jwt v3.2.2+incompatible
5454
github.com/golang/snappy v0.0.4 // indirect
55-
github.com/google/go-github/v32 v32.1.0
55+
github.com/google/go-github/v37 v37.0.0
5656
github.com/google/go-querystring v1.1.0 // indirect
5757
github.com/google/uuid v1.2.0
5858
github.com/gorilla/context v1.1.1
@@ -124,7 +124,7 @@ require (
124124
go.uber.org/atomic v1.8.0 // indirect
125125
go.uber.org/multierr v1.7.0 // indirect
126126
go.uber.org/zap v1.18.1 // indirect
127-
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
127+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
128128
golang.org/x/net v0.0.0-20210716203947-853a461950ff
129129
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
130130
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c

go.sum

+4-3
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
529529
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
530530
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
531531
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
532-
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
533-
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
532+
github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM=
533+
github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
534534
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
535535
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
536536
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
@@ -1145,8 +1145,9 @@ golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWP
11451145
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
11461146
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
11471147
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
1148-
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
11491148
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
1149+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
1150+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
11501151
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
11511152
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
11521153
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=

modules/context/context.go

-36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"code.gitea.io/gitea/modules/setting"
2929
"code.gitea.io/gitea/modules/templates"
3030
"code.gitea.io/gitea/modules/translation"
31-
"code.gitea.io/gitea/modules/util"
3231
"code.gitea.io/gitea/modules/web/middleware"
3332
"code.gitea.io/gitea/services/auth"
3433

@@ -287,41 +286,6 @@ func (ctx *Context) Header() http.Header {
287286
return ctx.Resp.Header()
288287
}
289288

290-
// Form returns request form as string with default
291-
func (ctx *Context) Form(key string, defaults ...string) string {
292-
return (*Forms)(ctx.Req).MustString(key, defaults...)
293-
}
294-
295-
// FormTrim returns request form as string with default and trimmed spaces
296-
func (ctx *Context) FormTrim(key string, defaults ...string) string {
297-
return (*Forms)(ctx.Req).MustTrimmed(key, defaults...)
298-
}
299-
300-
// FormStrings returns request form as strings with default
301-
func (ctx *Context) FormStrings(key string, defaults ...[]string) []string {
302-
return (*Forms)(ctx.Req).MustStrings(key, defaults...)
303-
}
304-
305-
// FormInt returns request form as int with default
306-
func (ctx *Context) FormInt(key string, defaults ...int) int {
307-
return (*Forms)(ctx.Req).MustInt(key, defaults...)
308-
}
309-
310-
// FormInt64 returns request form as int64 with default
311-
func (ctx *Context) FormInt64(key string, defaults ...int64) int64 {
312-
return (*Forms)(ctx.Req).MustInt64(key, defaults...)
313-
}
314-
315-
// FormBool returns request form as bool with default
316-
func (ctx *Context) FormBool(key string, defaults ...bool) bool {
317-
return (*Forms)(ctx.Req).MustBool(key, defaults...)
318-
}
319-
320-
// FormOptionalBool returns request form as OptionalBool with default
321-
func (ctx *Context) FormOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
322-
return (*Forms)(ctx.Req).MustOptionalBool(key, defaults...)
323-
}
324-
325289
// HandleText handles HTTP status code
326290
func (ctx *Context) HandleText(status int, title string) {
327291
if (status/100 == 4) || (status/100 == 5) {

modules/context/form.go

+27-204
Original file line numberDiff line numberDiff line change
@@ -5,237 +5,60 @@
55
package context
66

77
import (
8-
"errors"
9-
"net/http"
10-
"net/url"
118
"strconv"
129
"strings"
13-
"text/template"
1410

15-
"code.gitea.io/gitea/modules/log"
1611
"code.gitea.io/gitea/modules/util"
1712
)
1813

19-
// Forms a new enhancement of http.Request
20-
type Forms http.Request
21-
22-
// Values returns http.Request values
23-
func (f *Forms) Values() url.Values {
24-
return (*http.Request)(f).Form
25-
}
26-
27-
// String returns request form as string
28-
func (f *Forms) String(key string) (string, error) {
29-
return (*http.Request)(f).FormValue(key), nil
30-
}
31-
32-
// Trimmed returns request form as string with trimed spaces left and right
33-
func (f *Forms) Trimmed(key string) (string, error) {
34-
return strings.TrimSpace((*http.Request)(f).FormValue(key)), nil
14+
// FormString returns the first value matching the provided key in the form as a string
15+
func (ctx *Context) FormString(key string) string {
16+
return ctx.Req.FormValue(key)
3517
}
3618

37-
// Strings returns request form as strings
38-
func (f *Forms) Strings(key string) ([]string, error) {
39-
if (*http.Request)(f).Form == nil {
40-
if err := (*http.Request)(f).ParseMultipartForm(32 << 20); err != nil {
41-
return nil, err
19+
// FormStrings returns a string slice for the provided key from the form
20+
func (ctx *Context) FormStrings(key string) []string {
21+
if ctx.Req.Form == nil {
22+
if err := ctx.Req.ParseMultipartForm(32 << 20); err != nil {
23+
return nil
4224
}
4325
}
44-
if v, ok := (*http.Request)(f).Form[key]; ok {
45-
return v, nil
46-
}
47-
return nil, errors.New("not exist")
48-
}
49-
50-
// Escape returns request form as escaped string
51-
func (f *Forms) Escape(key string) (string, error) {
52-
return template.HTMLEscapeString((*http.Request)(f).FormValue(key)), nil
53-
}
54-
55-
// Int returns request form as int
56-
func (f *Forms) Int(key string) (int, error) {
57-
return strconv.Atoi((*http.Request)(f).FormValue(key))
58-
}
59-
60-
// Int32 returns request form as int32
61-
func (f *Forms) Int32(key string) (int32, error) {
62-
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 32)
63-
return int32(v), err
64-
}
65-
66-
// Int64 returns request form as int64
67-
func (f *Forms) Int64(key string) (int64, error) {
68-
return strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 64)
69-
}
70-
71-
// Uint returns request form as uint
72-
func (f *Forms) Uint(key string) (uint, error) {
73-
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
74-
return uint(v), err
75-
}
76-
77-
// Uint32 returns request form as uint32
78-
func (f *Forms) Uint32(key string) (uint32, error) {
79-
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 32)
80-
return uint32(v), err
81-
}
82-
83-
// Uint64 returns request form as uint64
84-
func (f *Forms) Uint64(key string) (uint64, error) {
85-
return strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
86-
}
87-
88-
// Bool returns request form as bool
89-
func (f *Forms) Bool(key string) (bool, error) {
90-
return strconv.ParseBool((*http.Request)(f).FormValue(key))
91-
}
92-
93-
// Float32 returns request form as float32
94-
func (f *Forms) Float32(key string) (float32, error) {
95-
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
96-
return float32(v), err
97-
}
98-
99-
// Float64 returns request form as float64
100-
func (f *Forms) Float64(key string) (float64, error) {
101-
return strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
102-
}
103-
104-
// MustString returns request form as string with default
105-
func (f *Forms) MustString(key string, defaults ...string) string {
106-
if v := (*http.Request)(f).FormValue(key); len(v) > 0 {
26+
if v, ok := ctx.Req.Form[key]; ok {
10727
return v
10828
}
109-
if len(defaults) > 0 {
110-
return defaults[0]
111-
}
112-
return ""
29+
return nil
11330
}
11431

115-
// MustTrimmed returns request form as string with default
116-
func (f *Forms) MustTrimmed(key string, defaults ...string) string {
117-
return strings.TrimSpace(f.MustString(key, defaults...))
32+
// FormTrim returns the first value for the provided key in the form as a space trimmed string
33+
func (ctx *Context) FormTrim(key string) string {
34+
return strings.TrimSpace(ctx.Req.FormValue(key))
11835
}
11936

120-
// MustStrings returns request form as strings with default
121-
func (f *Forms) MustStrings(key string, defaults ...[]string) []string {
122-
if (*http.Request)(f).Form == nil {
123-
if err := (*http.Request)(f).ParseMultipartForm(32 << 20); err != nil {
124-
log.Error("ParseMultipartForm: %v", err)
125-
return []string{}
126-
}
127-
}
128-
129-
if v, ok := (*http.Request)(f).Form[key]; ok {
130-
return v
131-
}
132-
if len(defaults) > 0 {
133-
return defaults[0]
134-
}
135-
return []string{}
136-
}
137-
138-
// MustEscape returns request form as escaped string with default
139-
func (f *Forms) MustEscape(key string, defaults ...string) string {
140-
if v := (*http.Request)(f).FormValue(key); len(v) > 0 {
141-
return template.HTMLEscapeString(v)
142-
}
143-
if len(defaults) > 0 {
144-
return defaults[0]
145-
}
146-
return ""
147-
}
148-
149-
// MustInt returns request form as int with default
150-
func (f *Forms) MustInt(key string, defaults ...int) int {
151-
v, err := strconv.Atoi((*http.Request)(f).FormValue(key))
152-
if len(defaults) > 0 && err != nil {
153-
return defaults[0]
154-
}
155-
return v
156-
}
157-
158-
// MustInt32 returns request form as int32 with default
159-
func (f *Forms) MustInt32(key string, defaults ...int32) int32 {
160-
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 32)
161-
if len(defaults) > 0 && err != nil {
162-
return defaults[0]
163-
}
164-
return int32(v)
165-
}
166-
167-
// MustInt64 returns request form as int64 with default
168-
func (f *Forms) MustInt64(key string, defaults ...int64) int64 {
169-
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 64)
170-
if len(defaults) > 0 && err != nil {
171-
return defaults[0]
172-
}
37+
// FormInt returns the first value for the provided key in the form as an int
38+
func (ctx *Context) FormInt(key string) int {
39+
v, _ := strconv.Atoi(ctx.Req.FormValue(key))
17340
return v
17441
}
17542

176-
// MustUint returns request form as uint with default
177-
func (f *Forms) MustUint(key string, defaults ...uint) uint {
178-
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
179-
if len(defaults) > 0 && err != nil {
180-
return defaults[0]
181-
}
182-
return uint(v)
183-
}
184-
185-
// MustUint32 returns request form as uint32 with default
186-
func (f *Forms) MustUint32(key string, defaults ...uint32) uint32 {
187-
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 32)
188-
if len(defaults) > 0 && err != nil {
189-
return defaults[0]
190-
}
191-
return uint32(v)
192-
}
193-
194-
// MustUint64 returns request form as uint64 with default
195-
func (f *Forms) MustUint64(key string, defaults ...uint64) uint64 {
196-
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
197-
if len(defaults) > 0 && err != nil {
198-
return defaults[0]
199-
}
200-
return v
201-
}
202-
203-
// MustFloat32 returns request form as float32 with default
204-
func (f *Forms) MustFloat32(key string, defaults ...float32) float32 {
205-
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 32)
206-
if len(defaults) > 0 && err != nil {
207-
return defaults[0]
208-
}
209-
return float32(v)
210-
}
211-
212-
// MustFloat64 returns request form as float64 with default
213-
func (f *Forms) MustFloat64(key string, defaults ...float64) float64 {
214-
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
215-
if len(defaults) > 0 && err != nil {
216-
return defaults[0]
217-
}
43+
// FormInt64 returns the first value for the provided key in the form as an int64
44+
func (ctx *Context) FormInt64(key string) int64 {
45+
v, _ := strconv.ParseInt(ctx.Req.FormValue(key), 10, 64)
21846
return v
21947
}
22048

221-
// MustBool returns request form as bool with default
222-
func (f *Forms) MustBool(key string, defaults ...bool) bool {
223-
v, err := strconv.ParseBool((*http.Request)(f).FormValue(key))
224-
if len(defaults) > 0 && err != nil {
225-
return defaults[0]
226-
}
49+
// FormBool returns true if the value for the provided key in the form is "1" or "true"
50+
func (ctx *Context) FormBool(key string) bool {
51+
v, _ := strconv.ParseBool(ctx.Req.FormValue(key))
22752
return v
22853
}
22954

230-
// MustOptionalBool returns request form as OptionalBool with default
231-
func (f *Forms) MustOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
232-
value := (*http.Request)(f).FormValue(key)
55+
// FormOptionalBool returns an OptionalBoolTrue or OptionalBoolFalse if the value
56+
// for the provided key exists in the form else it returns OptionalBoolNone
57+
func (ctx *Context) FormOptionalBool(key string) util.OptionalBool {
58+
value := ctx.Req.FormValue(key)
23359
if len(value) == 0 {
23460
return util.OptionalBoolNone
23561
}
236-
v, err := strconv.ParseBool((*http.Request)(f).FormValue(key))
237-
if len(defaults) > 0 && err != nil {
238-
return defaults[0]
239-
}
62+
v, _ := strconv.ParseBool(ctx.Req.FormValue(key))
24063
return util.OptionalBoolOf(v)
24164
}

modules/context/repo.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
346346

347347
// Check access.
348348
if ctx.Repo.Permission.AccessMode == models.AccessModeNone {
349-
if ctx.Form("go-get") == "1" {
349+
if ctx.FormString("go-get") == "1" {
350350
EarlyResponseForGoGetMeta(ctx)
351351
return
352352
}
@@ -415,7 +415,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
415415
owner, err = models.GetUserByName(userName)
416416
if err != nil {
417417
if models.IsErrUserNotExist(err) {
418-
if ctx.Form("go-get") == "1" {
418+
if ctx.FormString("go-get") == "1" {
419419
EarlyResponseForGoGetMeta(ctx)
420420
return
421421
}
@@ -437,7 +437,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
437437
if err == nil {
438438
RedirectToRepo(ctx, redirectRepoID)
439439
} else if models.IsErrRepoRedirectNotExist(err) {
440-
if ctx.Form("go-get") == "1" {
440+
if ctx.FormString("go-get") == "1" {
441441
EarlyResponseForGoGetMeta(ctx)
442442
return
443443
}
@@ -618,7 +618,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
618618
}
619619
}
620620

621-
if ctx.Form("go-get") == "1" {
621+
if ctx.FormString("go-get") == "1" {
622622
ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
623623
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", "branch", ctx.Repo.BranchName)
624624
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"

modules/migrations/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package migrations
88
import (
99
"errors"
1010

11-
"github.com/google/go-github/v32/github"
11+
"github.com/google/go-github/v37/github"
1212
)
1313

1414
var (

0 commit comments

Comments
 (0)