format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
This commit is contained in:
parent
1d98d205f5
commit
54e9ee37a7
423 changed files with 1585 additions and 1758 deletions
|
@ -26,7 +26,6 @@ func TestKeygen(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, regexp.MustCompile("^-----BEGIN RSA PRIVATE KEY-----.*"), priv)
|
||||
assert.Regexp(t, regexp.MustCompile("^-----BEGIN PUBLIC KEY-----.*"), pub)
|
||||
|
||||
}
|
||||
|
||||
func TestSignUsingKeys(t *testing.T) {
|
||||
|
|
|
@ -12,8 +12,7 @@ import (
|
|||
)
|
||||
|
||||
// DBStore can be used to store app state items in local filesystem
|
||||
type DBStore struct {
|
||||
}
|
||||
type DBStore struct{}
|
||||
|
||||
// Get reads the state item
|
||||
func (f *DBStore) Get(item StateItem) error {
|
||||
|
|
|
@ -14,9 +14,11 @@ type testDiscoveredInfo struct{}
|
|||
func (s *testDiscoveredInfo) ClaimedID() string {
|
||||
return "claimedID"
|
||||
}
|
||||
|
||||
func (s *testDiscoveredInfo) OpEndpoint() string {
|
||||
return "opEndpoint"
|
||||
}
|
||||
|
||||
func (s *testDiscoveredInfo) OpLocalID() string {
|
||||
return "opLocalID"
|
||||
}
|
||||
|
@ -25,7 +27,7 @@ func TestTimedDiscoveryCache(t *testing.T) {
|
|||
dc := newTimedDiscoveryCache(1 * time.Second)
|
||||
|
||||
// Put some initial values
|
||||
dc.Put("foo", &testDiscoveredInfo{}) //openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})
|
||||
dc.Put("foo", &testDiscoveredInfo{}) // openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})
|
||||
|
||||
// Make sure we can retrieve them
|
||||
if di := dc.Get("foo"); di == nil {
|
||||
|
|
|
@ -17,8 +17,10 @@ import (
|
|||
// If you have multiple servers for example, you may need to share at
|
||||
// least
|
||||
// the nonceStore between them.
|
||||
var nonceStore = openid.NewSimpleNonceStore()
|
||||
var discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
|
||||
var (
|
||||
nonceStore = openid.NewSimpleNonceStore()
|
||||
discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
|
||||
)
|
||||
|
||||
// Verify handles response from OpenID provider
|
||||
func Verify(fullURL string) (id string, err error) {
|
||||
|
|
|
@ -27,7 +27,6 @@ func Auth(serviceName, userName, passwd string) (string, error) {
|
|||
}
|
||||
return "", errors.New("Unrecognized PAM message style")
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ import (
|
|||
"github.com/duo-labs/webauthn/webauthn"
|
||||
)
|
||||
|
||||
//WebAuthn represents the global WebAuthn instance
|
||||
// WebAuthn represents the global WebAuthn instance
|
||||
var WebAuthn *webauthn.WebAuthn
|
||||
|
||||
//Init initializes the WebAuthn instance from the config.
|
||||
// Init initializes the WebAuthn instance from the config.
|
||||
func Init() {
|
||||
gob.Register(&webauthn.SessionData{})
|
||||
|
||||
|
@ -42,14 +42,14 @@ func Init() {
|
|||
// User represents an implementation of webauthn.User based on User model
|
||||
type User user_model.User
|
||||
|
||||
//WebAuthnID implements the webauthn.User interface
|
||||
// WebAuthnID implements the webauthn.User interface
|
||||
func (u *User) WebAuthnID() []byte {
|
||||
id := make([]byte, 8)
|
||||
binary.PutVarint(id, u.ID)
|
||||
return id
|
||||
}
|
||||
|
||||
//WebAuthnName implements the webauthn.User interface
|
||||
// WebAuthnName implements the webauthn.User interface
|
||||
func (u *User) WebAuthnName() string {
|
||||
if u.LoginName == "" {
|
||||
return u.Name
|
||||
|
@ -57,17 +57,17 @@ func (u *User) WebAuthnName() string {
|
|||
return u.LoginName
|
||||
}
|
||||
|
||||
//WebAuthnDisplayName implements the webauthn.User interface
|
||||
// WebAuthnDisplayName implements the webauthn.User interface
|
||||
func (u *User) WebAuthnDisplayName() string {
|
||||
return (*user_model.User)(u).DisplayName()
|
||||
}
|
||||
|
||||
//WebAuthnIcon implements the webauthn.User interface
|
||||
// WebAuthnIcon implements the webauthn.User interface
|
||||
func (u *User) WebAuthnIcon() string {
|
||||
return (*user_model.User)(u).AvatarLink()
|
||||
}
|
||||
|
||||
//WebAuthnCredentials implementns the webauthn.User interface
|
||||
// WebAuthnCredentials implementns the webauthn.User interface
|
||||
func (u *User) WebAuthnCredentials() []webauthn.Credential {
|
||||
dbCreds, err := auth.GetWebAuthnCredentialsByUID(u.ID)
|
||||
if err != nil {
|
||||
|
|
|
@ -61,6 +61,7 @@ func Test_PrepareWithInvalidImage(t *testing.T) {
|
|||
_, err := Prepare([]byte{})
|
||||
assert.EqualError(t, err, "DecodeConfig: image: unknown format")
|
||||
}
|
||||
|
||||
func Test_PrepareWithInvalidImageSize(t *testing.T) {
|
||||
setting.Avatar.MaxWidth = 5
|
||||
setting.Avatar.MaxHeight = 5
|
||||
|
|
|
@ -152,7 +152,7 @@ func PrettyNumber(v int64) string {
|
|||
func Subtract(left, right interface{}) interface{} {
|
||||
var rleft, rright int64
|
||||
var fleft, fright float64
|
||||
var isInt = true
|
||||
isInt := true
|
||||
switch v := left.(type) {
|
||||
case int:
|
||||
rleft = int64(v)
|
||||
|
|
4
modules/cache/cache.go
vendored
4
modules/cache/cache.go
vendored
|
@ -16,9 +16,7 @@ import (
|
|||
_ "gitea.com/go-chi/cache/memcache" // memcache plugin for cache
|
||||
)
|
||||
|
||||
var (
|
||||
conn mc.Cache
|
||||
)
|
||||
var conn mc.Cache
|
||||
|
||||
func newCache(cacheConfig setting.Cache) (mc.Cache, error) {
|
||||
return mc.NewCacher(mc.Options{
|
||||
|
|
1
modules/cache/cache_test.go
vendored
1
modules/cache/cache_test.go
vendored
|
@ -113,6 +113,7 @@ func TestGetInt(t *testing.T) {
|
|||
|
||||
// TODO: uncommented code works in IDE but not with go test
|
||||
}
|
||||
|
||||
func TestGetInt64(t *testing.T) {
|
||||
createTestCache()
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}
|
|||
|
||||
// ToUTF8WithFallbackReader detects the encoding of content and coverts to UTF-8 reader if possible
|
||||
func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
|
||||
var buf = make([]byte, 2048)
|
||||
buf := make([]byte, 2048)
|
||||
n, err := util.ReadAtMost(rd, buf)
|
||||
if err != nil {
|
||||
return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
|
||||
|
|
|
@ -56,36 +56,48 @@ func TestToUTF8WithErr(t *testing.T) {
|
|||
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
|
||||
|
||||
// "áéíóú"
|
||||
res, err = ToUTF8WithErr([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
|
||||
0xc3, 0xba})
|
||||
res, err = ToUTF8WithErr([]byte{
|
||||
0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
|
||||
0xc3, 0xba,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
|
||||
|
||||
res, err = ToUTF8WithErr([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e})
|
||||
res, err = ToUTF8WithErr([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
stringMustStartWith(t, "Hola,", res)
|
||||
stringMustEndWith(t, "AAA.", res)
|
||||
|
||||
res, err = ToUTF8WithErr([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e})
|
||||
res, err = ToUTF8WithErr([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
stringMustStartWith(t, "Hola,", res)
|
||||
stringMustEndWith(t, "AAA.", res)
|
||||
|
||||
res, err = ToUTF8WithErr([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e})
|
||||
res, err = ToUTF8WithErr([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
stringMustStartWith(t, "Hola,", res)
|
||||
stringMustEndWith(t, "AAA.", res)
|
||||
|
||||
// Japanese (Shift-JIS)
|
||||
// 日属秘ぞしちゅ。
|
||||
res, err = ToUTF8WithErr([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
|
||||
0xBF, 0x82, 0xE3, 0x81, 0x42})
|
||||
res, err = ToUTF8WithErr([]byte{
|
||||
0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
|
||||
0xBF, 0x82, 0xE3, 0x81, 0x42,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte{0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82},
|
||||
assert.Equal(t, []byte{
|
||||
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
|
||||
},
|
||||
[]byte(res))
|
||||
|
||||
res, err = ToUTF8WithErr([]byte{0x00, 0x00, 0x00, 0x00})
|
||||
|
@ -108,10 +120,14 @@ func TestToUTF8WithFallback(t *testing.T) {
|
|||
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
|
||||
|
||||
// "Hola, así cómo ños"
|
||||
res = ToUTF8WithFallback([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73})
|
||||
assert.Equal(t, []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63,
|
||||
0xC3, 0xB3, 0x6D, 0x6F, 0x20, 0xC3, 0xB1, 0x6F, 0x73}, res)
|
||||
res = ToUTF8WithFallback([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73,
|
||||
})
|
||||
assert.Equal(t, []byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63,
|
||||
0xC3, 0xB3, 0x6D, 0x6F, 0x20, 0xC3, 0xB1, 0x6F, 0x73,
|
||||
}, res)
|
||||
|
||||
// "Hola, así cómo "
|
||||
minmatch := []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63, 0xC3, 0xB3, 0x6D, 0x6F, 0x20}
|
||||
|
@ -127,8 +143,10 @@ func TestToUTF8WithFallback(t *testing.T) {
|
|||
// Japanese (Shift-JIS)
|
||||
// "日属秘ぞしちゅ。"
|
||||
res = ToUTF8WithFallback([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42})
|
||||
assert.Equal(t, []byte{0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82}, res)
|
||||
assert.Equal(t, []byte{
|
||||
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
|
||||
}, res)
|
||||
|
||||
res = ToUTF8WithFallback([]byte{0x00, 0x00, 0x00, 0x00})
|
||||
assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, res)
|
||||
|
@ -148,21 +166,29 @@ func TestToUTF8(t *testing.T) {
|
|||
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
|
||||
|
||||
// BOM + "áéíóú"
|
||||
res = ToUTF8(string([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
|
||||
0xc3, 0xba}))
|
||||
res = ToUTF8(string([]byte{
|
||||
0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
|
||||
0xc3, 0xba,
|
||||
}))
|
||||
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
|
||||
|
||||
// Latin1
|
||||
// Hola, así cómo ños
|
||||
res = ToUTF8(string([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73}))
|
||||
assert.Equal(t, []byte{0x48, 0x6f, 0x6c, 0x61, 0x2c, 0x20, 0x61, 0x73, 0xc3, 0xad, 0x20, 0x63,
|
||||
0xc3, 0xb3, 0x6d, 0x6f, 0x20, 0xc3, 0xb1, 0x6f, 0x73}, []byte(res))
|
||||
res = ToUTF8(string([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73,
|
||||
}))
|
||||
assert.Equal(t, []byte{
|
||||
0x48, 0x6f, 0x6c, 0x61, 0x2c, 0x20, 0x61, 0x73, 0xc3, 0xad, 0x20, 0x63,
|
||||
0xc3, 0xb3, 0x6d, 0x6f, 0x20, 0xc3, 0xb1, 0x6f, 0x73,
|
||||
}, []byte(res))
|
||||
|
||||
// Latin1
|
||||
// Hola, así cómo \x07ños
|
||||
res = ToUTF8(string([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73}))
|
||||
res = ToUTF8(string([]byte{
|
||||
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
|
||||
0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73,
|
||||
}))
|
||||
// Hola,
|
||||
bytesMustStartWith(t, []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C}, []byte(res))
|
||||
|
||||
|
@ -173,10 +199,14 @@ func TestToUTF8(t *testing.T) {
|
|||
|
||||
// Japanese (Shift-JIS)
|
||||
// 日属秘ぞしちゅ。
|
||||
res = ToUTF8(string([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
|
||||
0xBF, 0x82, 0xE3, 0x81, 0x42}))
|
||||
assert.Equal(t, []byte{0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82},
|
||||
res = ToUTF8(string([]byte{
|
||||
0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
|
||||
0xBF, 0x82, 0xE3, 0x81, 0x42,
|
||||
}))
|
||||
assert.Equal(t, []byte{
|
||||
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
|
||||
},
|
||||
[]byte(res))
|
||||
|
||||
res = ToUTF8("\x00\x00\x00\x00")
|
||||
|
@ -216,8 +246,10 @@ func TestToUTF8DropErrors(t *testing.T) {
|
|||
// Japanese (Shift-JIS)
|
||||
// "日属秘ぞしちゅ。"
|
||||
res = ToUTF8DropErrors([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42})
|
||||
assert.Equal(t, []byte{0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82}, res)
|
||||
assert.Equal(t, []byte{
|
||||
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
|
||||
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
|
||||
}, res)
|
||||
|
||||
res = ToUTF8DropErrors([]byte{0x00, 0x00, 0x00, 0x00})
|
||||
assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, res)
|
||||
|
|
|
@ -56,29 +56,29 @@ type APIInvalidTopicsError struct {
|
|||
InvalidTopics []string `json:"invalidTopics"`
|
||||
}
|
||||
|
||||
//APIEmpty is an empty response
|
||||
// APIEmpty is an empty response
|
||||
// swagger:response empty
|
||||
type APIEmpty struct{}
|
||||
|
||||
//APIForbiddenError is a forbidden error response
|
||||
// APIForbiddenError is a forbidden error response
|
||||
// swagger:response forbidden
|
||||
type APIForbiddenError struct {
|
||||
APIError
|
||||
}
|
||||
|
||||
//APINotFound is a not found empty response
|
||||
// APINotFound is a not found empty response
|
||||
// swagger:response notFound
|
||||
type APINotFound struct{}
|
||||
|
||||
//APIConflict is a conflict empty response
|
||||
// APIConflict is a conflict empty response
|
||||
// swagger:response conflict
|
||||
type APIConflict struct{}
|
||||
|
||||
//APIRedirect is a redirect response
|
||||
// APIRedirect is a redirect response
|
||||
// swagger:response redirect
|
||||
type APIRedirect struct{}
|
||||
|
||||
//APIString is a string response
|
||||
// APIString is a string response
|
||||
// swagger:response string
|
||||
type APIString string
|
||||
|
||||
|
@ -269,13 +269,12 @@ func APIAuth(authMethod auth_service.Method) func(*APIContext) {
|
|||
|
||||
// APIContexter returns apicontext as middleware
|
||||
func APIContexter() func(http.Handler) http.Handler {
|
||||
var csrfOpts = getCsrfOpts()
|
||||
csrfOpts := getCsrfOpts()
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
var locale = middleware.Locale(w, req)
|
||||
var ctx = APIContext{
|
||||
locale := middleware.Locale(w, req)
|
||||
ctx := APIContext{
|
||||
Context: &Context{
|
||||
Resp: NewResponse(w),
|
||||
Data: map[string]interface{}{},
|
||||
|
@ -354,7 +353,7 @@ func ReferencesGitRepo(allowEmpty bool) func(ctx *APIContext) (cancel context.Ca
|
|||
// NotFound handles 404s for APIContext
|
||||
// String will replace message, errors will be added to a slice
|
||||
func (ctx *APIContext) NotFound(objs ...interface{}) {
|
||||
var message = ctx.Tr("error.not_found")
|
||||
message := ctx.Tr("error.not_found")
|
||||
var errors []string
|
||||
for _, obj := range objs {
|
||||
// Ignore nil
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
|
||||
func TestGenAPILinks(t *testing.T) {
|
||||
setting.AppURL = "http://localhost:3000/"
|
||||
var kases = map[string][]string{
|
||||
kases := map[string][]string{
|
||||
"api/v1/repos/jerrykan/example-repo/issues?state=all": {
|
||||
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=2&state=all>; rel="next"`,
|
||||
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=5&state=all>; rel="last"`,
|
||||
|
|
|
@ -13,8 +13,10 @@ import (
|
|||
"gitea.com/go-chi/captcha"
|
||||
)
|
||||
|
||||
var imageCaptchaOnce sync.Once
|
||||
var cpt *captcha.Captcha
|
||||
var (
|
||||
imageCaptchaOnce sync.Once
|
||||
cpt *captcha.Captcha
|
||||
)
|
||||
|
||||
// GetImageCaptcha returns global image captcha
|
||||
func GetImageCaptcha() *captcha.Captcha {
|
||||
|
|
|
@ -362,7 +362,7 @@ func (ctx *Context) ServeStream(rd io.Reader, name string) {
|
|||
|
||||
// Error returned an error to web browser
|
||||
func (ctx *Context) Error(status int, contents ...string) {
|
||||
var v = http.StatusText(status)
|
||||
v := http.StatusText(status)
|
||||
if len(contents) > 0 {
|
||||
v = contents[0]
|
||||
}
|
||||
|
@ -606,16 +606,16 @@ func Auth(authMethod auth.Method) func(*Context) {
|
|||
|
||||
// Contexter initializes a classic context for a request.
|
||||
func Contexter() func(next http.Handler) http.Handler {
|
||||
var rnd = templates.HTMLRenderer()
|
||||
var csrfOpts = getCsrfOpts()
|
||||
rnd := templates.HTMLRenderer()
|
||||
csrfOpts := getCsrfOpts()
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
var locale = middleware.Locale(resp, req)
|
||||
var startTime = time.Now()
|
||||
var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")
|
||||
locale := middleware.Locale(resp, req)
|
||||
startTime := time.Now()
|
||||
link := setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")
|
||||
|
||||
var ctx = Context{
|
||||
ctx := Context{
|
||||
Resp: NewResponse(resp),
|
||||
Cache: mc.GetCache(),
|
||||
Locale: locale,
|
||||
|
|
|
@ -57,9 +57,9 @@ type csrf struct {
|
|||
Form string
|
||||
// Cookie name value for setting and getting csrf token.
|
||||
Cookie string
|
||||
//Cookie domain
|
||||
// Cookie domain
|
||||
CookieDomain string
|
||||
//Cookie path
|
||||
// Cookie path
|
||||
CookiePath string
|
||||
// Cookie HttpOnly flag value used for the csrf token.
|
||||
CookieHTTPOnly bool
|
||||
|
|
|
@ -44,9 +44,7 @@ func (ctx *PrivateContext) Err() error {
|
|||
return ctx.Req.Context().Err()
|
||||
}
|
||||
|
||||
var (
|
||||
privateContextKey interface{} = "default_private_context"
|
||||
)
|
||||
var privateContextKey interface{} = "default_private_context"
|
||||
|
||||
// WithPrivateContext set up private context in request
|
||||
func WithPrivateContext(req *http.Request, ctx *PrivateContext) *http.Request {
|
||||
|
|
|
@ -111,7 +111,6 @@ type CanCommitToBranchResults struct {
|
|||
// and branch is not protected for push
|
||||
func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) {
|
||||
protectedBranch, err := models.GetProtectedBranchBy(r.Repository.ID, r.BranchName)
|
||||
|
||||
if err != nil {
|
||||
return CanCommitToBranchResults{}, err
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ type ResponseWriter interface {
|
|||
Size() int
|
||||
}
|
||||
|
||||
var (
|
||||
_ ResponseWriter = &Response{}
|
||||
)
|
||||
var _ ResponseWriter = &Response{}
|
||||
|
||||
// Response represents a response
|
||||
type Response struct {
|
||||
|
|
|
@ -22,12 +22,12 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
|
|||
URL: n.APIURL(),
|
||||
}
|
||||
|
||||
//since user only get notifications when he has access to use minimal access mode
|
||||
// since user only get notifications when he has access to use minimal access mode
|
||||
if n.Repository != nil {
|
||||
result.Repository = ToRepo(n.Repository, perm.AccessModeRead)
|
||||
}
|
||||
|
||||
//handle Subject
|
||||
// handle Subject
|
||||
switch n.Source {
|
||||
case models.NotificationSourceIssue:
|
||||
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectIssue}
|
||||
|
@ -83,7 +83,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
|
|||
|
||||
// ToNotifications convert list of Notification to api.NotificationThread list
|
||||
func ToNotifications(nl models.NotificationList) []*api.NotificationThread {
|
||||
var result = make([]*api.NotificationThread, 0, len(nl))
|
||||
result := make([]*api.NotificationThread, 0, len(nl))
|
||||
for _, n := range nl {
|
||||
result = append(result, ToNotificationThread(n))
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPullRequest_APIFormat(t *testing.T) {
|
||||
//with HeadRepo
|
||||
// with HeadRepo
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
|
@ -34,7 +34,7 @@ func TestPullRequest_APIFormat(t *testing.T) {
|
|||
Repository: ToRepo(headRepo, perm.AccessModeRead),
|
||||
}, apiPullRequest.Head)
|
||||
|
||||
//withOut HeadRepo
|
||||
// withOut HeadRepo
|
||||
pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
assert.NoError(t, pr.LoadIssue())
|
||||
assert.NoError(t, pr.LoadAttributes())
|
||||
|
|
|
@ -40,7 +40,7 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
|
|||
}
|
||||
}
|
||||
|
||||
//check enabled/disabled units
|
||||
// check enabled/disabled units
|
||||
hasIssues := false
|
||||
var externalTracker *api.ExternalTracker
|
||||
var internalTracker *api.InternalTracker
|
||||
|
|
|
@ -33,7 +33,6 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus {
|
|||
|
||||
// ToCombinedStatus converts List of CommitStatus to a CombinedStatus
|
||||
func ToCombinedStatus(statuses []*models.CommitStatus, repo *api.Repository) *api.CombinedStatus {
|
||||
|
||||
if len(statuses) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -17,8 +17,10 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
const maxLines = 10
|
||||
const guessSampleSize = 1e4 // 10k
|
||||
const (
|
||||
maxLines = 10
|
||||
guessSampleSize = 1e4 // 10k
|
||||
)
|
||||
|
||||
// CreateReader creates a csv.Reader with the given delimiter.
|
||||
func CreateReader(input io.Reader, delimiter rune) *stdcsv.Reader {
|
||||
|
@ -35,7 +37,7 @@ func CreateReader(input io.Reader, delimiter rune) *stdcsv.Reader {
|
|||
// CreateReaderAndDetermineDelimiter tries to guess the field delimiter from the content and creates a csv.Reader.
|
||||
// Reads at most guessSampleSize bytes.
|
||||
func CreateReaderAndDetermineDelimiter(ctx *markup.RenderContext, rd io.Reader) (*stdcsv.Reader, error) {
|
||||
var data = make([]byte, guessSampleSize)
|
||||
data := make([]byte, guessSampleSize)
|
||||
size, err := util.ReadAtMost(rd, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -31,7 +31,7 @@ func decodeSlashes(t *testing.T, s string) string {
|
|||
}
|
||||
|
||||
func TestCreateReaderAndDetermineDelimiter(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
csv string
|
||||
expectedRows [][]string
|
||||
expectedDelimiter rune
|
||||
|
@ -135,7 +135,7 @@ func TestDetermineDelimiterReadAllError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDetermineDelimiter(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
csv string
|
||||
filename string
|
||||
expectedDelimiter rune
|
||||
|
@ -236,7 +236,7 @@ John Doe john@doe.com This,note,had,a,lot,of,commas,to,test,delimiters`,
|
|||
}
|
||||
|
||||
func TestRemoveQuotedString(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
text string
|
||||
expectedText string
|
||||
}{
|
||||
|
@ -301,7 +301,7 @@ abc | |123
|
|||
}
|
||||
|
||||
func TestGuessDelimiter(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
csv string
|
||||
expectedDelimiter rune
|
||||
}{
|
||||
|
@ -456,7 +456,7 @@ jkl`,
|
|||
}
|
||||
|
||||
func TestGuessFromBeforeAfterQuotes(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
csv string
|
||||
expectedDelimiter rune
|
||||
}{
|
||||
|
@ -562,7 +562,7 @@ func (l mockLocale) TrN(_cnt interface{}, key1, _keyN string, _args ...interface
|
|||
}
|
||||
|
||||
func TestFormatError(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
err error
|
||||
expectedMessage string
|
||||
expectsError bool
|
||||
|
|
|
@ -296,7 +296,6 @@ func fixBrokenRepoUnits16961(ctx context.Context, logger log.Logger, autofix boo
|
|||
return repo_model.UpdateRepoUnit(repoUnit)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Critical("Unable to iterate across repounits to fix the broken units: Error %v", err)
|
||||
return err
|
||||
|
|
|
@ -119,7 +119,6 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
|
|||
logger.Info("Enabled push options for %d repositories.", numRepos)
|
||||
} else {
|
||||
logger.Info("Checked %d repositories, %d need updates.", numRepos, numNeedUpdate)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -27,7 +27,7 @@ func checkConfigurationFile(logger log.Logger, autofix bool, fileOpts configurat
|
|||
fi, err := os.Stat(fileOpts.Path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) && autofix && fileOpts.IsDirectory {
|
||||
if err := os.MkdirAll(fileOpts.Path, 0777); err != nil {
|
||||
if err := os.MkdirAll(fileOpts.Path, 0o777); err != nil {
|
||||
logger.Error(" Directory does not exist and could not be created. ERROR: %v", err)
|
||||
return fmt.Errorf("Configuration directory: \"%q\" does not exist and could not be created. ERROR: %v", fileOpts.Path, err)
|
||||
}
|
||||
|
|
|
@ -44,9 +44,7 @@ var (
|
|||
)
|
||||
|
||||
func loadMap() {
|
||||
|
||||
once.Do(func() {
|
||||
|
||||
// initialize
|
||||
codeMap = make(map[string]int, len(GemojiData))
|
||||
aliasMap = make(map[string]int, len(GemojiData))
|
||||
|
@ -87,7 +85,6 @@ func loadMap() {
|
|||
codeReplacer = strings.NewReplacer(codePairs...)
|
||||
aliasReplacer = strings.NewReplacer(aliasPairs...)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// FromCode retrieves the emoji data based on the provided unicode code (ie,
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
)
|
||||
|
||||
func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
|
||||
|
||||
maxLoops := 1000
|
||||
|
||||
// 'git --version' does not block so it must be finished before the timeout triggered.
|
||||
|
@ -27,7 +26,6 @@ func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
|
||||
|
||||
maxLoops := 1000
|
||||
|
||||
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
|
||||
|
|
|
@ -36,7 +36,7 @@ type Commit struct {
|
|||
// CommitGPGSignature represents a git commit signature part.
|
||||
type CommitGPGSignature struct {
|
||||
Signature string
|
||||
Payload string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data
|
||||
Payload string // TODO check if can be reconstruct from the rest of commit information to not have duplicate data
|
||||
}
|
||||
|
||||
// Message returns the commit message. Same as retrieving CommitMessage directly.
|
||||
|
|
|
@ -158,7 +158,7 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
|
|||
|
||||
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*object.Commit, []string, error) {
|
||||
var unHitEntryPaths []string
|
||||
var results = make(map[string]*object.Commit)
|
||||
results := make(map[string]*object.Commit)
|
||||
for _, p := range paths {
|
||||
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
|
||||
if err != nil {
|
||||
|
|
|
@ -104,7 +104,7 @@ func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string
|
|||
defer cancel()
|
||||
|
||||
var unHitEntryPaths []string
|
||||
var results = make(map[string]*Commit)
|
||||
results := make(map[string]*Commit)
|
||||
for _, p := range paths {
|
||||
lastCommit, err := cache.Get(commitID, path.Join(treePath, p), wr, rd)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,8 +16,10 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const testReposDir = "tests/repos/"
|
||||
const benchmarkReposDir = "benchmark/repos/"
|
||||
const (
|
||||
testReposDir = "tests/repos/"
|
||||
benchmarkReposDir = "benchmark/repos/"
|
||||
)
|
||||
|
||||
func cloneRepo(url, dir, name string) (string, error) {
|
||||
repoDir := filepath.Join(dir, name)
|
||||
|
|
|
@ -234,5 +234,4 @@ func TestParseCommitFileStatus(t *testing.T) {
|
|||
assert.Equal(t, kase.removed, fileStatus.Removed)
|
||||
assert.Equal(t, kase.modified, fileStatus.Modified)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -112,8 +112,8 @@ func SetExecutablePath(path string) error {
|
|||
|
||||
// VersionInfo returns git version information
|
||||
func VersionInfo() string {
|
||||
var format = "Git Version: %s"
|
||||
var args = []interface{}{gitVersion.Original()}
|
||||
format := "Git Version: %s"
|
||||
args := []interface{}{gitVersion.Original()}
|
||||
// Since git wire protocol has been released from git v2.18
|
||||
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
|
||||
format += ", Wire Protocol %s Enabled"
|
||||
|
|
|
@ -23,10 +23,8 @@ var hookNames = []string{
|
|||
"post-receive",
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrNotValidHook error when a git hook is not valid
|
||||
ErrNotValidHook = errors.New("not a valid Git hook")
|
||||
)
|
||||
// ErrNotValidHook error when a git hook is not valid
|
||||
var ErrNotValidHook = errors.New("not a valid Git hook")
|
||||
|
||||
// IsValidHookName returns true if given name is a valid Git hook.
|
||||
func IsValidHookName(name string) bool {
|
||||
|
@ -142,5 +140,5 @@ func SetUpdateHook(repoPath, content string) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(hookPath, []byte(content), 0777)
|
||||
return os.WriteFile(hookPath, []byte(content), 0o777)
|
||||
}
|
||||
|
|
|
@ -64,7 +64,6 @@ func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
|
|||
|
||||
// CacheCommit will cache the commit from the gitRepository
|
||||
func (c *LastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error {
|
||||
|
||||
commitNodeIndex, _ := commit.repo.CommitNodeIndex()
|
||||
|
||||
index, err := commitNodeIndex.Get(commit.ID)
|
||||
|
|
|
@ -16,8 +16,8 @@ var once sync.Once
|
|||
// CheckLFSVersion will check lfs version, if not satisfied, then disable it.
|
||||
func CheckLFSVersion() {
|
||||
if setting.LFS.StartServer {
|
||||
//Disable LFS client hooks if installed for the current OS user
|
||||
//Needs at least git v2.1.2
|
||||
// Disable LFS client hooks if installed for the current OS user
|
||||
// Needs at least git v2.1.2
|
||||
|
||||
err := LoadGitVersion()
|
||||
if err != nil {
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
)
|
||||
|
||||
func TestParseTreeEntries(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
Input string
|
||||
Expected []*TreeEntry
|
||||
|
|
|
@ -146,7 +146,7 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
|
|||
opts.Timeout = -1
|
||||
}
|
||||
|
||||
var envs = os.Environ()
|
||||
envs := os.Environ()
|
||||
u, err := url.Parse(from)
|
||||
if err == nil && (strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https")) {
|
||||
if proxy.Match(u.Host) {
|
||||
|
@ -154,7 +154,7 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
|
|||
}
|
||||
}
|
||||
|
||||
var stderr = new(bytes.Buffer)
|
||||
stderr := new(bytes.Buffer)
|
||||
if err = cmd.RunWithContext(&RunContext{
|
||||
Timeout: opts.Timeout,
|
||||
Env: envs,
|
||||
|
|
|
@ -87,7 +87,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
|
|||
return nil, fmt.Errorf("wrong number of fields in return from check-attr")
|
||||
}
|
||||
|
||||
var name2attribute2info = make(map[string]map[string]string)
|
||||
name2attribute2info := make(map[string]map[string]string)
|
||||
|
||||
for i := 0; i < (len(fields) / 3); i++ {
|
||||
filename := string(fields[3*i])
|
||||
|
|
|
@ -45,7 +45,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
|
|||
assert.Fail(t, "took too long to read an attribute from the list")
|
||||
}
|
||||
|
||||
//Write a partial attribute
|
||||
// Write a partial attribute
|
||||
_, err = wr.Write([]byte("incomplete-file"))
|
||||
assert.NoError(t, err)
|
||||
_, err = wr.Write([]byte("name\x00"))
|
||||
|
@ -133,7 +133,7 @@ func Test_lineSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
|
|||
assert.Fail(t, "took too long to read an attribute from the list")
|
||||
}
|
||||
|
||||
//Write a partial attribute
|
||||
// Write a partial attribute
|
||||
_, err = wr.Write([]byte("incomplete-file"))
|
||||
assert.NoError(t, err)
|
||||
_, err = wr.Write([]byte("name: "))
|
||||
|
|
|
@ -88,7 +88,6 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
|||
func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) ([]*Commit, error) {
|
||||
stdout, err := NewCommandContext(repo.Ctx, "log", id.String(), "--skip="+strconv.Itoa((page-1)*pageSize),
|
||||
"--max-count="+strconv.Itoa(pageSize), prettyLogFormat).RunInDirBytes(repo.Path)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -90,9 +90,9 @@ func TestRepository_CommitsBetweenIDs(t *testing.T) {
|
|||
NewID string
|
||||
ExpectedCommits int
|
||||
}{
|
||||
{"fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "78a445db1eac62fe15e624e1137965969addf344", 1}, //com1 -> com2
|
||||
{"78a445db1eac62fe15e624e1137965969addf344", "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", 0}, //reset HEAD~, com2 -> com1
|
||||
{"78a445db1eac62fe15e624e1137965969addf344", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", 1}, //com2 -> com2_new
|
||||
{"fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "78a445db1eac62fe15e624e1137965969addf344", 1}, // com1 -> com2
|
||||
{"78a445db1eac62fe15e624e1137965969addf344", "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", 0}, // reset HEAD~, com2 -> com1
|
||||
{"78a445db1eac62fe15e624e1137965969addf344", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", 1}, // com2 -> com2_new
|
||||
}
|
||||
for i, c := range cases {
|
||||
commits, err := bareRepo1.CommitsBetweenIDs(c.NewID, c.OldID)
|
||||
|
|
|
@ -4,5 +4,7 @@
|
|||
|
||||
package git
|
||||
|
||||
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
|
||||
const bigFileSize int64 = 1024 * 1024 // 1 MiB
|
||||
const (
|
||||
fileSizeLimit int64 = 16 * 1024 // 16 KiB
|
||||
bigFileSize int64 = 1024 * 1024 // 1 MiB
|
||||
)
|
||||
|
|
|
@ -46,7 +46,6 @@ func (repo *Repository) hashObject(reader io.Reader) (string, error) {
|
|||
stdout := new(bytes.Buffer)
|
||||
stderr := new(bytes.Buffer)
|
||||
err := cmd.RunInDirFullPipeline(repo.Path, stdout, stderr, reader)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
|
|||
tagNames = util.PaginateSlice(tagNames, page, pageSize).([]string)
|
||||
}
|
||||
|
||||
var tags = make([]*Tag, 0, len(tagNames))
|
||||
tags := make([]*Tag, 0, len(tagNames))
|
||||
for _, tagName := range tagNames {
|
||||
tagName = strings.TrimSpace(tagName)
|
||||
if len(tagName) == 0 {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetRefURL(t *testing.T) {
|
||||
var kases = []struct {
|
||||
kases := []struct {
|
||||
refURL string
|
||||
prefixURL string
|
||||
parentPath string
|
||||
|
|
|
@ -10,8 +10,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const beginpgp = "\n-----BEGIN PGP SIGNATURE-----\n"
|
||||
const endpgp = "\n-----END PGP SIGNATURE-----"
|
||||
const (
|
||||
beginpgp = "\n-----BEGIN PGP SIGNATURE-----\n"
|
||||
endpgp = "\n-----END PGP SIGNATURE-----"
|
||||
)
|
||||
|
||||
// Tag represents a Git tag.
|
||||
type Tag struct {
|
||||
|
|
|
@ -22,7 +22,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
|
|||
if len(relpath) == 0 {
|
||||
return &TreeEntry{
|
||||
ID: t.ID,
|
||||
//Type: ObjectTree,
|
||||
// Type: ObjectTree,
|
||||
gogitTreeEntry: &object.TreeEntry{
|
||||
Name: "",
|
||||
Mode: filemode.Dir,
|
||||
|
|
|
@ -13,15 +13,15 @@ type EntryMode int
|
|||
// one of these.
|
||||
const (
|
||||
// EntryModeBlob
|
||||
EntryModeBlob EntryMode = 0100644
|
||||
EntryModeBlob EntryMode = 0o100644
|
||||
// EntryModeExec
|
||||
EntryModeExec EntryMode = 0100755
|
||||
EntryModeExec EntryMode = 0o100755
|
||||
// EntryModeSymlink
|
||||
EntryModeSymlink EntryMode = 0120000
|
||||
EntryModeSymlink EntryMode = 0o120000
|
||||
// EntryModeCommit
|
||||
EntryModeCommit EntryMode = 0160000
|
||||
EntryModeCommit EntryMode = 0o160000
|
||||
// EntryModeTree
|
||||
EntryModeTree EntryMode = 0040000
|
||||
EntryModeTree EntryMode = 0o040000
|
||||
)
|
||||
|
||||
// String converts an EntryMode to a string
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
)
|
||||
|
||||
func BenchmarkGetCommitGraph(b *testing.B) {
|
||||
|
||||
currentRepo, err := git.OpenRepository(".")
|
||||
if err != nil || currentRepo == nil {
|
||||
b.Error("Could not open repository")
|
||||
|
@ -255,7 +254,6 @@ func TestCommitStringParsing(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
t.Run(test.testName, func(t *testing.T) {
|
||||
testString := fmt.Sprintf("%s%s", dataFirstPart, test.commitMessage)
|
||||
idx := strings.Index(testString, "DATA:")
|
||||
|
|
|
@ -144,7 +144,6 @@ func (parser *Parser) releaseUnusedColors() {
|
|||
|
||||
// ParseGlyphs parses the provided glyphs and sets the internal state
|
||||
func (parser *Parser) ParseGlyphs(glyphs []byte) {
|
||||
|
||||
// Clean state for parsing this row
|
||||
parser.glyphs, parser.oldGlyphs = parser.oldGlyphs, parser.glyphs
|
||||
parser.glyphs = parser.glyphs[0:0]
|
||||
|
|
|
@ -190,6 +190,7 @@ func (g *Manager) RunAtHammer(hammer func()) {
|
|||
hammer()
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Manager) doShutdown() {
|
||||
if !g.setStateTransition(stateRunning, stateShuttingDown) {
|
||||
return
|
||||
|
|
|
@ -83,7 +83,7 @@ func Code(fileName, language, code string) string {
|
|||
|
||||
if lexer == nil {
|
||||
if val, ok := highlightMapping[filepath.Ext(fileName)]; ok {
|
||||
//use mapped value to find lexer
|
||||
// use mapped value to find lexer
|
||||
lexer = lexers.Get(val)
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func File(numLines int, fileName, language string, code []byte) []string {
|
|||
m := make([]string, 0, numLines)
|
||||
for _, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) {
|
||||
content := string(v)
|
||||
//need to keep lines that are only \n so copy/paste works properly in browser
|
||||
// need to keep lines that are only \n so copy/paste works properly in browser
|
||||
if content == "" {
|
||||
content = "\n"
|
||||
} else if content == `</span><span class="w">` {
|
||||
|
@ -220,7 +220,7 @@ func plainText(code string, numLines int) []string {
|
|||
m := make([]string, 0, numLines)
|
||||
for _, v := range strings.SplitN(string(code), "\n", numLines) {
|
||||
content := string(v)
|
||||
//need to keep lines that are only \n so copy/paste works properly in browser
|
||||
// need to keep lines that are only \n so copy/paste works properly in browser
|
||||
if content == "" {
|
||||
content = "\n"
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type mockFileInfo struct {
|
||||
}
|
||||
type mockFileInfo struct{}
|
||||
|
||||
func (m mockFileInfo) Name() string { return "gitea.test" }
|
||||
func (m mockFileInfo) Size() int64 { return int64(10) }
|
||||
|
|
|
@ -38,8 +38,10 @@ import (
|
|||
"github.com/go-enry/go-enry/v2"
|
||||
)
|
||||
|
||||
const unicodeNormalizeName = "unicodeNormalize"
|
||||
const maxBatchSize = 16
|
||||
const (
|
||||
unicodeNormalizeName = "unicodeNormalize"
|
||||
maxBatchSize = 16
|
||||
)
|
||||
|
||||
// numericEqualityQuery a numeric equality query for the given value and field
|
||||
func numericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
|
||||
|
@ -158,9 +160,7 @@ func createBleveIndexer(path string, latestVersion int) (bleve.Index, error) {
|
|||
return indexer, nil
|
||||
}
|
||||
|
||||
var (
|
||||
_ Indexer = &BleveIndexer{}
|
||||
)
|
||||
var _ Indexer = &BleveIndexer{}
|
||||
|
||||
// BleveIndexer represents a bleve indexer implementation
|
||||
type BleveIndexer struct {
|
||||
|
@ -337,7 +337,7 @@ func (b *BleveIndexer) Search(repoIDs []int64, language, keyword string, page, p
|
|||
}
|
||||
|
||||
if len(repoIDs) > 0 {
|
||||
var repoQueries = make([]query.Query, 0, len(repoIDs))
|
||||
repoQueries := make([]query.Query, 0, len(repoIDs))
|
||||
for _, repoID := range repoIDs {
|
||||
repoQueries = append(repoQueries, numericEqualityQuery(repoID, "RepoID"))
|
||||
}
|
||||
|
|
|
@ -35,9 +35,7 @@ const (
|
|||
esMultiMatchTypePhrasePrefix = "phrase_prefix"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Indexer = &ElasticSearchIndexer{}
|
||||
)
|
||||
var _ Indexer = &ElasticSearchIndexer{}
|
||||
|
||||
// ElasticSearchIndexer implements Indexer interface
|
||||
type ElasticSearchIndexer struct {
|
||||
|
@ -131,7 +129,7 @@ func (b *ElasticSearchIndexer) init() (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
if !exists {
|
||||
var mapping = defaultMapping
|
||||
mapping := defaultMapping
|
||||
|
||||
createIndex, err := b.client.CreateIndex(b.realIndexerName()).BodyString(mapping).Do(ctx)
|
||||
if err != nil {
|
||||
|
@ -327,7 +325,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
|
|||
}
|
||||
|
||||
repoID, fileName := parseIndexerID(hit.Id)
|
||||
var res = make(map[string]interface{})
|
||||
res := make(map[string]interface{})
|
||||
if err := json.Unmarshal(hit.Source, &res); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
|
@ -378,7 +376,7 @@ func (b *ElasticSearchIndexer) Search(repoIDs []int64, language, keyword string,
|
|||
query := elastic.NewBoolQuery()
|
||||
query = query.Must(kwQuery)
|
||||
if len(repoIDs) > 0 {
|
||||
var repoStrs = make([]interface{}, 0, len(repoIDs))
|
||||
repoStrs := make([]interface{}, 0, len(repoIDs))
|
||||
for _, repoID := range repoIDs {
|
||||
repoStrs = append(repoStrs, repoID)
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var idxCount = 0
|
||||
idxCount := 0
|
||||
updates := make([]fileUpdate, len(entries))
|
||||
for _, entry := range entries {
|
||||
if isIndexable(entry) {
|
||||
|
|
|
@ -78,9 +78,7 @@ type IndexerData struct {
|
|||
RepoID int64
|
||||
}
|
||||
|
||||
var (
|
||||
indexerQueue queue.UniqueQueue
|
||||
)
|
||||
var indexerQueue queue.UniqueQueue
|
||||
|
||||
func index(ctx context.Context, indexer Indexer, repoID int64) error {
|
||||
repo, err := repo_model.GetRepositoryByID(repoID)
|
||||
|
|
|
@ -25,45 +25,43 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
|
|||
var repoID int64 = 1
|
||||
err := index(git.DefaultContext, indexer, repoID)
|
||||
assert.NoError(t, err)
|
||||
var (
|
||||
keywords = []struct {
|
||||
RepoIDs []int64
|
||||
Keyword string
|
||||
IDs []int64
|
||||
Langs int
|
||||
}{
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "Description",
|
||||
IDs: []int64{repoID},
|
||||
Langs: 1,
|
||||
},
|
||||
{
|
||||
RepoIDs: []int64{2},
|
||||
Keyword: "Description",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "repo1",
|
||||
IDs: []int64{repoID},
|
||||
Langs: 1,
|
||||
},
|
||||
{
|
||||
RepoIDs: []int64{2},
|
||||
Keyword: "repo1",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "non-exist",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
}
|
||||
)
|
||||
keywords := []struct {
|
||||
RepoIDs []int64
|
||||
Keyword string
|
||||
IDs []int64
|
||||
Langs int
|
||||
}{
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "Description",
|
||||
IDs: []int64{repoID},
|
||||
Langs: 1,
|
||||
},
|
||||
{
|
||||
RepoIDs: []int64{2},
|
||||
Keyword: "Description",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "repo1",
|
||||
IDs: []int64{repoID},
|
||||
Langs: 1,
|
||||
},
|
||||
{
|
||||
RepoIDs: []int64{2},
|
||||
Keyword: "repo1",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
{
|
||||
RepoIDs: nil,
|
||||
Keyword: "non-exist",
|
||||
IDs: []int64{},
|
||||
Langs: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, kw := range keywords {
|
||||
t.Run(kw.Keyword, func(t *testing.T) {
|
||||
|
@ -72,7 +70,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
|
|||
assert.EqualValues(t, len(kw.IDs), total)
|
||||
assert.Len(t, langs, kw.Langs)
|
||||
|
||||
var ids = make([]int64, 0, len(res))
|
||||
ids := make([]int64, 0, len(res))
|
||||
for _, hit := range res {
|
||||
ids = append(ids, hit.RepoID)
|
||||
assert.EqualValues(t, "# repo1\n\nDescription for repo1", hit.Content)
|
||||
|
|
|
@ -12,9 +12,7 @@ import (
|
|||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
)
|
||||
|
||||
var (
|
||||
indexer = newWrappedIndexer()
|
||||
)
|
||||
var indexer = newWrappedIndexer()
|
||||
|
||||
// ErrWrappedIndexerClosed is the error returned if the indexer was closed before it was ready
|
||||
var ErrWrappedIndexerClosed = fmt.Errorf("Indexer closed before ready")
|
||||
|
@ -80,7 +78,6 @@ func (w *wrappedIndexer) Search(repoIDs []int64, language, keyword string, page,
|
|||
return 0, nil, nil, err
|
||||
}
|
||||
return indexer.Search(repoIDs, language, keyword, page, pageSize, isMatch)
|
||||
|
||||
}
|
||||
|
||||
func (w *wrappedIndexer) Close() {
|
||||
|
|
|
@ -156,9 +156,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
|
|||
return index, nil
|
||||
}
|
||||
|
||||
var (
|
||||
_ Indexer = &BleveIndexer{}
|
||||
)
|
||||
var _ Indexer = &BleveIndexer{}
|
||||
|
||||
// BleveIndexer implements Indexer interface
|
||||
type BleveIndexer struct {
|
||||
|
@ -256,7 +254,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var ret = SearchResult{
|
||||
ret := SearchResult{
|
||||
Hits: make([]Match, 0, len(result.Hits)),
|
||||
}
|
||||
for _, hit := range result.Hits {
|
||||
|
|
|
@ -53,43 +53,41 @@ func TestBleveIndexAndSearch(t *testing.T) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var (
|
||||
keywords = []struct {
|
||||
Keyword string
|
||||
IDs []int64
|
||||
}{
|
||||
{
|
||||
Keyword: "search",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "test1",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "test2",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "support",
|
||||
IDs: []int64{1, 2},
|
||||
},
|
||||
{
|
||||
Keyword: "chinese",
|
||||
IDs: []int64{1, 2},
|
||||
},
|
||||
{
|
||||
Keyword: "help",
|
||||
IDs: []int64{},
|
||||
},
|
||||
}
|
||||
)
|
||||
keywords := []struct {
|
||||
Keyword string
|
||||
IDs []int64
|
||||
}{
|
||||
{
|
||||
Keyword: "search",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "test1",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "test2",
|
||||
IDs: []int64{1},
|
||||
},
|
||||
{
|
||||
Keyword: "support",
|
||||
IDs: []int64{1, 2},
|
||||
},
|
||||
{
|
||||
Keyword: "chinese",
|
||||
IDs: []int64{1, 2},
|
||||
},
|
||||
{
|
||||
Keyword: "help",
|
||||
IDs: []int64{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, kw := range keywords {
|
||||
res, err := indexer.Search(kw.Keyword, []int64{2}, 10, 0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var ids = make([]int64, 0, len(res.Hits))
|
||||
ids := make([]int64, 0, len(res.Hits))
|
||||
for _, hit := range res.Hits {
|
||||
ids = append(ids, hit.ID)
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ package issues
|
|||
import "code.gitea.io/gitea/models"
|
||||
|
||||
// DBIndexer implements Indexer interface to use database's like search
|
||||
type DBIndexer struct {
|
||||
}
|
||||
type DBIndexer struct{}
|
||||
|
||||
// Init dummy function
|
||||
func (db *DBIndexer) Init() (bool, error) {
|
||||
|
@ -35,7 +34,7 @@ func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*Sear
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result = SearchResult{
|
||||
result := SearchResult{
|
||||
Total: total,
|
||||
Hits: make([]Match, 0, limit),
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@ import (
|
|||
"github.com/olivere/elastic/v7"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Indexer = &ElasticSearchIndexer{}
|
||||
)
|
||||
var _ Indexer = &ElasticSearchIndexer{}
|
||||
|
||||
// ElasticSearchIndexer implements Indexer interface
|
||||
type ElasticSearchIndexer struct {
|
||||
|
@ -102,7 +100,7 @@ func (b *ElasticSearchIndexer) Init() (bool, error) {
|
|||
}
|
||||
|
||||
if !exists {
|
||||
var mapping = defaultMapping
|
||||
mapping := defaultMapping
|
||||
|
||||
createIndex, err := b.client.CreateIndex(b.indexerName).BodyString(mapping).Do(ctx)
|
||||
if err != nil {
|
||||
|
@ -195,7 +193,7 @@ func (b *ElasticSearchIndexer) Search(keyword string, repoIDs []int64, limit, st
|
|||
query := elastic.NewBoolQuery()
|
||||
query = query.Must(kwQuery)
|
||||
if len(repoIDs) > 0 {
|
||||
var repoStrs = make([]interface{}, 0, len(repoIDs))
|
||||
repoStrs := make([]interface{}, 0, len(repoIDs))
|
||||
for _, repoID := range repoIDs {
|
||||
repoStrs = append(repoStrs, repoID)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ func TestBleveSearchIssues(t *testing.T) {
|
|||
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{1}, ids)
|
||||
|
||||
}
|
||||
|
||||
func TestDBSearchIssues(t *testing.T) {
|
||||
|
|
|
@ -15,8 +15,7 @@ import (
|
|||
)
|
||||
|
||||
// DBIndexer implements Indexer interface to use database's like search
|
||||
type DBIndexer struct {
|
||||
}
|
||||
type DBIndexer struct{}
|
||||
|
||||
// Index repository status function
|
||||
func (db *DBIndexer) Index(id int64) error {
|
||||
|
|
|
@ -18,7 +18,7 @@ func str2url(raw string) *url.URL {
|
|||
|
||||
func TestDetermineEndpoint(t *testing.T) {
|
||||
// Test cases
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
cloneurl string
|
||||
lfsurl string
|
||||
expected *url.URL
|
||||
|
|
|
@ -23,8 +23,7 @@ func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
return f(req), nil
|
||||
}
|
||||
|
||||
type DummyTransferAdapter struct {
|
||||
}
|
||||
type DummyTransferAdapter struct{}
|
||||
|
||||
func (a *DummyTransferAdapter) Name() string {
|
||||
return "dummy"
|
||||
|
@ -172,7 +171,7 @@ func TestHTTPClientDownload(t *testing.T) {
|
|||
})}
|
||||
dummy := &DummyTransferAdapter{}
|
||||
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
endpoint string
|
||||
expectederror string
|
||||
}{
|
||||
|
@ -279,7 +278,7 @@ func TestHTTPClientUpload(t *testing.T) {
|
|||
})}
|
||||
dummy := &DummyTransferAdapter{}
|
||||
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
endpoint string
|
||||
expectederror string
|
||||
}{
|
||||
|
|
|
@ -51,7 +51,6 @@ func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan c
|
|||
return nil
|
||||
})
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
|
@ -169,10 +169,12 @@ var levelToColor = map[Level][]byte{
|
|||
NONE: ColorBytes(Reset),
|
||||
}
|
||||
|
||||
var resetBytes = ColorBytes(Reset)
|
||||
var fgCyanBytes = ColorBytes(FgCyan)
|
||||
var fgGreenBytes = ColorBytes(FgGreen)
|
||||
var fgBoldBytes = ColorBytes(Bold)
|
||||
var (
|
||||
resetBytes = ColorBytes(Reset)
|
||||
fgCyanBytes = ColorBytes(FgCyan)
|
||||
fgGreenBytes = ColorBytes(FgGreen)
|
||||
fgBoldBytes = ColorBytes(Bold)
|
||||
)
|
||||
|
||||
type protectedANSIWriterMode int
|
||||
|
||||
|
@ -335,7 +337,6 @@ func NewColoredValuePointer(value *interface{}, color ...ColorAttribute) *Colore
|
|||
resetBytes: &resetBytes,
|
||||
Value: value,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// NewColoredValueBytes creates a value from the provided value with color bytes
|
||||
|
|
|
@ -135,7 +135,7 @@ func TestConnLoggerFailConnect(t *testing.T) {
|
|||
|
||||
date := time.Date(2019, time.January, 13, 22, 3, 30, 15, location)
|
||||
|
||||
//dateString := date.UTC().Format("2006/01/02 15:04:05")
|
||||
// dateString := date.UTC().Format("2006/01/02 15:04:05")
|
||||
|
||||
event := Event{
|
||||
level: INFO,
|
||||
|
@ -224,7 +224,6 @@ func TestConnLoggerClose(t *testing.T) {
|
|||
err := logger.LogEvent(&event)
|
||||
assert.NoError(t, err)
|
||||
logger.Close()
|
||||
|
||||
}()
|
||||
wg.Wait()
|
||||
logger.Flush()
|
||||
|
|
|
@ -76,7 +76,7 @@ func (mw *MuxWriter) SetFd(fd *os.File) {
|
|||
func NewFileLogger() LoggerProvider {
|
||||
log := &FileLogger{
|
||||
Filename: "",
|
||||
Maxsize: 1 << 28, //256 MB
|
||||
Maxsize: 1 << 28, // 256 MB
|
||||
Daily: true,
|
||||
Maxdays: 7,
|
||||
Rotate: true,
|
||||
|
@ -137,7 +137,7 @@ func (log *FileLogger) docheck(size int) {
|
|||
|
||||
func (log *FileLogger) createLogFile() (*os.File, error) {
|
||||
// Open the log file
|
||||
return os.OpenFile(log.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660)
|
||||
return os.OpenFile(log.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o660)
|
||||
}
|
||||
|
||||
func (log *FileLogger) initFd() error {
|
||||
|
@ -202,7 +202,7 @@ func compressOldLogFile(fname string, compressionLevel int) error {
|
|||
}
|
||||
defer reader.Close()
|
||||
buffer := bufio.NewReader(reader)
|
||||
fw, err := os.OpenFile(fname+".gz", os.O_WRONLY|os.O_CREATE, 0660)
|
||||
fw, err := os.OpenFile(fname+".gz", os.O_WRONLY|os.O_CREATE, 0o660)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -234,7 +234,6 @@ func (log *FileLogger) deleteOldLog() {
|
|||
|
||||
if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*log.Maxdays) {
|
||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(log.Filename)) {
|
||||
|
||||
if err := util.Remove(path); err != nil {
|
||||
returnErr = fmt.Errorf("Failed to remove %s: %v", path, err)
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ func TestFileLoggerFails(t *testing.T) {
|
|||
prefix := "TestPrefix "
|
||||
level := INFO
|
||||
flags := LstdFlags | LUTC | Lfuncname
|
||||
//filename := filepath.Join(tmpDir, "test.log")
|
||||
// filename := filepath.Join(tmpDir, "test.log")
|
||||
|
||||
fileLogger := NewFileLogger()
|
||||
//realFileLogger, ok := fileLogger.(*FileLogger)
|
||||
//assert.True(t, ok)
|
||||
// realFileLogger, ok := fileLogger.(*FileLogger)
|
||||
// assert.True(t, ok)
|
||||
|
||||
// Fail if there is bad json
|
||||
err = fileLogger.Init("{")
|
||||
|
@ -44,7 +44,6 @@ func TestFileLoggerFails(t *testing.T) {
|
|||
// Fail if the file isn't a filename
|
||||
err = fileLogger.Init(fmt.Sprintf("{\"prefix\":\"%s\",\"level\":\"%s\",\"flags\":%d,\"filename\":\"%s\"}", prefix, level.String(), flags, filepath.ToSlash(tmpDir)))
|
||||
assert.Error(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestFileLogger(t *testing.T) {
|
||||
|
@ -125,7 +124,7 @@ func TestFileLogger(t *testing.T) {
|
|||
assert.Equal(t, expected, string(logData))
|
||||
|
||||
for num := 2; num <= 999; num++ {
|
||||
file, err := os.OpenFile(filename+fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), num), os.O_RDONLY|os.O_CREATE, 0666)
|
||||
file, err := os.OpenFile(filename+fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), num), os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
assert.NoError(t, err)
|
||||
file.Close()
|
||||
}
|
||||
|
@ -202,7 +201,7 @@ func TestCompressFileLogger(t *testing.T) {
|
|||
fileLogger.Flush()
|
||||
|
||||
for num := 2; num <= 999; num++ {
|
||||
file, err := os.OpenFile(filename+fmt.Sprintf(".%s.%03d.gz", time.Now().Format("2006-01-02"), num), os.O_RDONLY|os.O_CREATE, 0666)
|
||||
file, err := os.OpenFile(filename+fmt.Sprintf(".%s.%03d.gz", time.Now().Format("2006-01-02"), num), os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
assert.NoError(t, err)
|
||||
file.Close()
|
||||
}
|
||||
|
@ -217,9 +216,9 @@ func TestCompressOldFile(t *testing.T) {
|
|||
fname := filepath.Join(tmpDir, "test")
|
||||
nonGzip := filepath.Join(tmpDir, "test-nonGzip")
|
||||
|
||||
f, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY, 0660)
|
||||
f, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY, 0o660)
|
||||
assert.NoError(t, err)
|
||||
ng, err := os.OpenFile(nonGzip, os.O_CREATE|os.O_WRONLY, 0660)
|
||||
ng, err := os.OpenFile(nonGzip, os.O_CREATE|os.O_WRONLY, 0o660)
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 999; i++ {
|
||||
|
|
|
@ -136,7 +136,6 @@ func TestNewLogggerRecreate(t *testing.T) {
|
|||
|
||||
// We should be able to redelete without a problem
|
||||
go DelLogger("console")
|
||||
|
||||
}
|
||||
|
||||
func TestNewNamedLogger(t *testing.T) {
|
||||
|
|
|
@ -65,7 +65,6 @@ func (l *LevelLoggerLogger) IsTrace() bool {
|
|||
// Debug records debug log
|
||||
func (l *LevelLoggerLogger) Debug(format string, v ...interface{}) {
|
||||
l.Log(1, DEBUG, format, v...)
|
||||
|
||||
}
|
||||
|
||||
// IsDebug returns true if the logger is DEBUG
|
||||
|
|
|
@ -11,9 +11,7 @@ import (
|
|||
"runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
unknown = []byte("???")
|
||||
)
|
||||
var unknown = []byte("???")
|
||||
|
||||
// Stack will skip back the provided number of frames and return a stack trace with source code.
|
||||
// Although we could just use debug.Stack(), this routine will return the source code and
|
||||
|
|
|
@ -189,7 +189,7 @@ func (logger *WriterLogger) createMsg(buf *[]byte, event *Event) {
|
|||
*buf = append(*buf, ' ')
|
||||
}
|
||||
|
||||
var msg = []byte(event.msg)
|
||||
msg := []byte(event.msg)
|
||||
if len(msg) > 0 && msg[len(msg)-1] == '\n' {
|
||||
msg = msg[:len(msg)-1]
|
||||
}
|
||||
|
|
|
@ -178,8 +178,7 @@ func NewFootnoteList() *FootnoteList {
|
|||
|
||||
var footnoteListKey = parser.NewContextKey()
|
||||
|
||||
type footnoteBlockParser struct {
|
||||
}
|
||||
type footnoteBlockParser struct{}
|
||||
|
||||
var defaultFootnoteBlockParser = &footnoteBlockParser{}
|
||||
|
||||
|
@ -265,8 +264,7 @@ func (b *footnoteBlockParser) CanAcceptIndentedLine() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
type footnoteParser struct {
|
||||
}
|
||||
type footnoteParser struct{}
|
||||
|
||||
var defaultFootnoteParser = &footnoteParser{}
|
||||
|
||||
|
@ -337,8 +335,7 @@ func (s *footnoteParser) Parse(parent ast.Node, block text.Reader, pc parser.Con
|
|||
return NewFootnoteLink(index, name)
|
||||
}
|
||||
|
||||
type footnoteASTTransformer struct {
|
||||
}
|
||||
type footnoteASTTransformer struct{}
|
||||
|
||||
var defaultFootnoteASTTransformer = &footnoteASTTransformer{}
|
||||
|
||||
|
@ -357,7 +354,7 @@ func (a *footnoteASTTransformer) Transform(node *ast.Document, reader text.Reade
|
|||
}
|
||||
pc.Set(footnoteListKey, nil)
|
||||
for footnote := list.FirstChild(); footnote != nil; {
|
||||
var container ast.Node = footnote
|
||||
container := footnote
|
||||
next := footnote.NextSibling()
|
||||
if fc := container.LastChild(); fc != nil && ast.IsParagraph(fc) {
|
||||
container = fc
|
||||
|
|
|
@ -8,12 +8,10 @@ import (
|
|||
"mvdan.cc/xurls/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// NOTE: All below regex matching do not perform any extra validation.
|
||||
// Thus a link is produced even if the linked entity does not exist.
|
||||
// While fast, this is also incorrect and lead to false positives.
|
||||
// TODO: fix invalid linking issue
|
||||
// NOTE: All below regex matching do not perform any extra validation.
|
||||
// Thus a link is produced even if the linked entity does not exist.
|
||||
// While fast, this is also incorrect and lead to false positives.
|
||||
// TODO: fix invalid linking issue
|
||||
|
||||
// LinkRegex is a regexp matching a valid link
|
||||
LinkRegex, _ = xurls.StrictMatchingScheme("https?://")
|
||||
)
|
||||
// LinkRegex is a regexp matching a valid link
|
||||
var LinkRegex, _ = xurls.StrictMatchingScheme("https?://")
|
||||
|
|
|
@ -20,8 +20,7 @@ import (
|
|||
|
||||
var wwwURLRegxp = regexp.MustCompile(`^www\.[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}((?:/|[#?])[-a-zA-Z0-9@:%_\+.~#!?&//=\(\);,'">\^{}\[\]` + "`" + `]*)?`)
|
||||
|
||||
type linkifyParser struct {
|
||||
}
|
||||
type linkifyParser struct{}
|
||||
|
||||
var defaultLinkifyParser = &linkifyParser{}
|
||||
|
||||
|
@ -36,10 +35,12 @@ func (s *linkifyParser) Trigger() []byte {
|
|||
return []byte{' ', '*', '_', '~', '('}
|
||||
}
|
||||
|
||||
var protoHTTP = []byte("http:")
|
||||
var protoHTTPS = []byte("https:")
|
||||
var protoFTP = []byte("ftp:")
|
||||
var domainWWW = []byte("www.")
|
||||
var (
|
||||
protoHTTP = []byte("http:")
|
||||
protoHTTPS = []byte("https:")
|
||||
protoFTP = []byte("ftp:")
|
||||
domainWWW = []byte("www.")
|
||||
)
|
||||
|
||||
func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node {
|
||||
if pc.IsInLinkLabel() {
|
||||
|
@ -58,7 +59,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
|
|||
|
||||
var m []int
|
||||
var protocol []byte
|
||||
var typ ast.AutoLinkType = ast.AutoLinkURL
|
||||
typ := ast.AutoLinkURL
|
||||
if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) {
|
||||
m = LinkRegex.FindSubmatchIndex(line)
|
||||
}
|
||||
|
@ -139,8 +140,7 @@ func (s *linkifyParser) CloseBlock(parent ast.Node, pc parser.Context) {
|
|||
// nothing to do
|
||||
}
|
||||
|
||||
type linkify struct {
|
||||
}
|
||||
type linkify struct{}
|
||||
|
||||
// Linkify is an extension that allow you to parse text that seems like a URL.
|
||||
var Linkify = &linkify{}
|
||||
|
|
|
@ -22,8 +22,7 @@ func init() {
|
|||
}
|
||||
|
||||
// Renderer implements markup.Renderer for csv files
|
||||
type Renderer struct {
|
||||
}
|
||||
type Renderer struct{}
|
||||
|
||||
// Name implements markup.Renderer
|
||||
func (Renderer) Name() string {
|
||||
|
@ -83,7 +82,7 @@ func writeField(w io.Writer, element, class, field string) error {
|
|||
|
||||
// Render implements markup.Renderer
|
||||
func (Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
|
||||
var tmpBlock = bufio.NewWriter(output)
|
||||
tmpBlock := bufio.NewWriter(output)
|
||||
|
||||
// FIXME: don't read all to memory
|
||||
rawBytes, err := io.ReadAll(input)
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
func TestRenderCSV(t *testing.T) {
|
||||
var render Renderer
|
||||
var kases = map[string]string{
|
||||
kases := map[string]string{
|
||||
"a": "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>a</th></tr></table>",
|
||||
"1,2": "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>1</th><th>2</th></tr></table>",
|
||||
"1;2\n3;4": "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>1</th><th>2</th></tr><tr><td class=\"line-num\">2</td><td>3</td><td>4</td></tr></table>",
|
||||
|
|
|
@ -202,7 +202,7 @@ func RenderCommitMessage(
|
|||
ctx *RenderContext,
|
||||
content string,
|
||||
) (string, error) {
|
||||
var procs = commitMessageProcessors
|
||||
procs := commitMessageProcessors
|
||||
if ctx.DefaultLink != "" {
|
||||
// we don't have to fear data races, because being
|
||||
// commitMessageProcessors of fixed len and cap, every time we append
|
||||
|
@ -238,7 +238,7 @@ func RenderCommitMessageSubject(
|
|||
ctx *RenderContext,
|
||||
content string,
|
||||
) (string, error) {
|
||||
var procs = commitMessageSubjectProcessors
|
||||
procs := commitMessageSubjectProcessors
|
||||
if ctx.DefaultLink != "" {
|
||||
// we don't have to fear data races, because being
|
||||
// commitMessageSubjectProcessors of fixed len and cap, every time we
|
||||
|
@ -291,8 +291,10 @@ func RenderEmoji(
|
|||
return renderProcessString(&RenderContext{}, emojiProcessors, content)
|
||||
}
|
||||
|
||||
var tagCleaner = regexp.MustCompile(`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))`)
|
||||
var nulCleaner = strings.NewReplacer("\000", "")
|
||||
var (
|
||||
tagCleaner = regexp.MustCompile(`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))`)
|
||||
nulCleaner = strings.NewReplacer("\000", "")
|
||||
)
|
||||
|
||||
func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output io.Writer) error {
|
||||
defer ctx.Cancel()
|
||||
|
|
|
@ -15,9 +15,11 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const TestAppURL = "http://localhost:3000/"
|
||||
const TestOrgRepo = "gogits/gogs"
|
||||
const TestRepoURL = TestAppURL + TestOrgRepo + "/"
|
||||
const (
|
||||
TestAppURL = "http://localhost:3000/"
|
||||
TestOrgRepo = "gogits/gogs"
|
||||
TestRepoURL = TestAppURL + TestOrgRepo + "/"
|
||||
)
|
||||
|
||||
// alphanumLink an HTML link to an alphanumeric-style issue
|
||||
func alphanumIssueLink(baseURL, class, name string) string {
|
||||
|
|
|
@ -38,17 +38,17 @@ func TestRender_Commits(t *testing.T) {
|
|||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
|
||||
}
|
||||
|
||||
var sha = "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
var repo = TestRepoURL
|
||||
var commit = util.URLJoin(repo, "commit", sha)
|
||||
var tree = util.URLJoin(repo, "tree", sha, "src")
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
repo := TestRepoURL
|
||||
commit := util.URLJoin(repo, "commit", sha)
|
||||
tree := util.URLJoin(repo, "tree", sha, "src")
|
||||
|
||||
var file = util.URLJoin(repo, "commit", sha, "example.txt")
|
||||
var fileWithExtra = file + ":"
|
||||
var fileWithHash = file + "#L2"
|
||||
var fileWithHasExtra = file + "#L2:"
|
||||
var commitCompare = util.URLJoin(repo, "compare", sha+"..."+sha)
|
||||
var commitCompareWithHash = commitCompare + "#L2"
|
||||
file := util.URLJoin(repo, "commit", sha, "example.txt")
|
||||
fileWithExtra := file + ":"
|
||||
fileWithHash := file + "#L2"
|
||||
fileWithHasExtra := file + "#L2:"
|
||||
commitCompare := util.URLJoin(repo, "compare", sha+"..."+sha)
|
||||
commitCompareWithHash := commitCompare + "#L2"
|
||||
|
||||
test(sha, `<p><a href="`+commit+`" rel="nofollow"><code>65f1bf27bc</code></a></p>`)
|
||||
test(sha[:7], `<p><a href="`+commit[:len(commit)-(40-7)]+`" rel="nofollow"><code>65f1bf2</code></a></p>`)
|
||||
|
@ -102,8 +102,8 @@ func TestRender_CrossReferences(t *testing.T) {
|
|||
func TestMisc_IsSameDomain(t *testing.T) {
|
||||
setting.AppURL = TestAppURL
|
||||
|
||||
var sha = "b6dd6210eaebc915fd5be5579c58cce4da2e2579"
|
||||
var commit = util.URLJoin(TestRepoURL, "commit", sha)
|
||||
sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579"
|
||||
commit := util.URLJoin(TestRepoURL, "commit", sha)
|
||||
|
||||
assert.True(t, IsSameDomain(commit))
|
||||
assert.False(t, IsSameDomain("http://google.com/ncr"))
|
||||
|
@ -291,7 +291,7 @@ func TestRender_emoji(t *testing.T) {
|
|||
`<p><span class="emoji" aria-label="`+emoji.GemojiData[i].Description+`">`+emoji.GemojiData[i].Emoji+`</span></p>`)
|
||||
}
|
||||
|
||||
//Text that should be turned into or recognized as emoji
|
||||
// Text that should be turned into or recognized as emoji
|
||||
test(
|
||||
":gitea:",
|
||||
`<p><span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span></p>`)
|
||||
|
@ -472,7 +472,7 @@ func TestRender_RelativeImages(t *testing.T) {
|
|||
func Test_ParseClusterFuzz(t *testing.T) {
|
||||
setting.AppURL = TestAppURL
|
||||
|
||||
var localMetas = map[string]string{
|
||||
localMetas := map[string]string{
|
||||
"user": "go-gitea",
|
||||
"repo": "gitea",
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
|
|||
func TestIssue16020(t *testing.T) {
|
||||
setting.AppURL = TestAppURL
|
||||
|
||||
var localMetas = map[string]string{
|
||||
localMetas := map[string]string{
|
||||
"user": "go-gitea",
|
||||
"repo": "gitea",
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
|
|||
metaData := meta.GetItems(pc)
|
||||
firstChild := node.FirstChild()
|
||||
createTOC := false
|
||||
var toc = []Header{}
|
||||
toc := []Header{}
|
||||
rc := &RenderConfig{
|
||||
Meta: "table",
|
||||
Icon: "table",
|
||||
|
|
|
@ -28,12 +28,16 @@ import (
|
|||
"github.com/yuin/goldmark/util"
|
||||
)
|
||||
|
||||
var converter goldmark.Markdown
|
||||
var once = sync.Once{}
|
||||
var (
|
||||
converter goldmark.Markdown
|
||||
once = sync.Once{}
|
||||
)
|
||||
|
||||
var urlPrefixKey = parser.NewContextKey()
|
||||
var isWikiKey = parser.NewContextKey()
|
||||
var renderMetasKey = parser.NewContextKey()
|
||||
var (
|
||||
urlPrefixKey = parser.NewContextKey()
|
||||
isWikiKey = parser.NewContextKey()
|
||||
renderMetasKey = parser.NewContextKey()
|
||||
)
|
||||
|
||||
type limitWriter struct {
|
||||
w io.Writer
|
||||
|
@ -134,7 +138,6 @@ func actualRender(ctx *markup.RenderContext, input io.Reader, output io.Writer)
|
|||
util.Prioritized(NewHTMLRenderer(), 10),
|
||||
),
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
lw := &limitWriter{
|
||||
|
@ -190,10 +193,8 @@ func render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error
|
|||
return actualRender(ctx, input, output)
|
||||
}
|
||||
|
||||
var (
|
||||
// MarkupName describes markup's name
|
||||
MarkupName = "markdown"
|
||||
)
|
||||
// MarkupName describes markup's name
|
||||
var MarkupName = "markdown"
|
||||
|
||||
func init() {
|
||||
markup.RegisterRenderer(Renderer{})
|
||||
|
|
|
@ -18,9 +18,11 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const AppURL = "http://localhost:3000/"
|
||||
const Repo = "gogits/gogs"
|
||||
const AppSubURL = AppURL + Repo + "/"
|
||||
const (
|
||||
AppURL = "http://localhost:3000/"
|
||||
Repo = "gogits/gogs"
|
||||
AppSubURL = AppURL + Repo + "/"
|
||||
)
|
||||
|
||||
// these values should match the Repo const above
|
||||
var localMetas = map[string]string{
|
||||
|
@ -120,7 +122,6 @@ func TestRender_Images(t *testing.T) {
|
|||
test(
|
||||
"[]("+href+")",
|
||||
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
|
||||
|
||||
}
|
||||
|
||||
func testAnswers(baseURLContent, baseURLImages string) []string {
|
||||
|
|
|
@ -147,8 +147,10 @@ func StripMarkdown(rawBytes []byte) (string, []string) {
|
|||
return string(buf), links
|
||||
}
|
||||
|
||||
var stripParser parser.Parser
|
||||
var once = sync.Once{}
|
||||
var (
|
||||
stripParser parser.Parser
|
||||
once = sync.Once{}
|
||||
)
|
||||
|
||||
// StripMarkdownBytes parses markdown content by removing all markup and code blocks
|
||||
// in order to extract links and other references
|
||||
|
|
|
@ -52,7 +52,8 @@ A HIDDEN ` + "`" + `GHOST` + "`" + ` IN THIS LINE.
|
|||
},
|
||||
[]string{
|
||||
"link",
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
"Simply closes: #29 yes",
|
||||
[]string{
|
||||
|
|
|
@ -27,8 +27,7 @@ func init() {
|
|||
}
|
||||
|
||||
// Renderer implements markup.Renderer for orgmode
|
||||
type Renderer struct {
|
||||
}
|
||||
type Renderer struct{}
|
||||
|
||||
// Name implements markup.Renderer
|
||||
func (Renderer) Name() string {
|
||||
|
|
|
@ -15,9 +15,11 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const AppURL = "http://localhost:3000/"
|
||||
const Repo = "gogits/gogs"
|
||||
const AppSubURL = AppURL + Repo + "/"
|
||||
const (
|
||||
AppURL = "http://localhost:3000/"
|
||||
Repo = "gogits/gogs"
|
||||
AppSubURL = AppURL + Repo + "/"
|
||||
)
|
||||
|
||||
func TestRender_StandardLinks(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
|
|
|
@ -86,7 +86,8 @@ func createDefaultPolicy() *bluemonday.Policy {
|
|||
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
|
||||
|
||||
// Allow generally safe attributes
|
||||
generalSafeAttrs := []string{"abbr", "accept", "accept-charset",
|
||||
generalSafeAttrs := []string{
|
||||
"abbr", "accept", "accept-charset",
|
||||
"accesskey", "action", "align", "alt",
|
||||
"aria-describedby", "aria-hidden", "aria-label", "aria-labelledby",
|
||||
"axis", "border", "cellpadding", "cellspacing", "char",
|
||||
|
|
|
@ -59,5 +59,4 @@ func TestSanitizeNonEscape(t *testing.T) {
|
|||
if strings.Contains(string(output), "<script>") {
|
||||
t.Errorf("un-escaped <script> in output: %q", output)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ type Collector struct {
|
|||
|
||||
// NewCollector returns a new Collector with all prometheus.Desc initialized
|
||||
func NewCollector() Collector {
|
||||
|
||||
return Collector{
|
||||
Accesses: prometheus.NewDesc(
|
||||
namespace+"accesses",
|
||||
|
|
|
@ -10,12 +10,9 @@ import (
|
|||
)
|
||||
|
||||
// NullDownloader implements a blank downloader
|
||||
type NullDownloader struct {
|
||||
}
|
||||
type NullDownloader struct{}
|
||||
|
||||
var (
|
||||
_ Downloader = &NullDownloader{}
|
||||
)
|
||||
var _ Downloader = &NullDownloader{}
|
||||
|
||||
// SetContext set context
|
||||
func (n NullDownloader) SetContext(_ context.Context) {}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue