Skip to content

Commit

Permalink
Merge branch 'master' into fix-13502_api_return-json-error
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath authored Nov 14, 2020
2 parents dc76957 + 3f3447a commit 3b3e089
Show file tree
Hide file tree
Showing 79 changed files with 5,068 additions and 480 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ issues:
- path: modules/log/
linters:
- errcheck
- path: routers/routes/routes.go
- path: routers/routes/macaron.go
linters:
- dupl
- path: routers/api/v1/repo/issue_subscription.go
Expand Down
16 changes: 7 additions & 9 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/routes"

"gitea.com/macaron/macaron"

context2 "github.com/gorilla/context"
"github.com/unknwon/com"
"github.com/urfave/cli"
Expand Down Expand Up @@ -135,9 +133,9 @@ func runWeb(ctx *cli.Context) error {
return err
}
}
m := routes.NewMacaron()
routes.RegisterInstallRoute(m)
err := listen(m, false)
c := routes.NewChi()
routes.RegisterInstallRoute(c)
err := listen(c, false)
select {
case <-graceful.GetManager().IsShutdown():
<-graceful.GetManager().Done()
Expand Down Expand Up @@ -168,10 +166,10 @@ func runWeb(ctx *cli.Context) error {
}
}
// Set up Macaron
m := routes.NewMacaron()
routes.RegisterRoutes(m)
c := routes.NewChi()
routes.RegisterRoutes(c)

err := listen(m, true)
err := listen(c, true)
<-graceful.GetManager().Done()
log.Info("PID: %d Gitea Web Finished", os.Getpid())
log.Close()
Expand Down Expand Up @@ -212,7 +210,7 @@ func setPort(port string) error {
return nil
}

func listen(m *macaron.Macaron, handleRedirector bool) error {
func listen(m http.Handler, handleRedirector bool) error {
listenAddr := setting.HTTPAddr
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
listenAddr = net.JoinHostPort(listenAddr, setting.HTTPPort)
Expand Down
6 changes: 3 additions & 3 deletions contrib/pr/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func runPR() {
//routers.GlobalInit()
external.RegisterParsers()
markup.Init()
m := routes.NewMacaron()
routes.RegisterRoutes(m)
c := routes.NewChi()
routes.RegisterRoutes(c)

log.Printf("[PR] Ready for testing !\n")
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")
Expand All @@ -138,7 +138,7 @@ func runPR() {
*/

//Start the server
http.ListenAndServe(":8080", context2.ClearHandler(m))
http.ListenAndServe(":8080", context2.ClearHandler(c))

log.Printf("[PR] Cleaning up ...\n")
/*
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/features/webhooks.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ if (empty($header_signature)) {
$payload_signature = hash_hmac('sha256', $payload, $secret_key, false);
// check payload signature against header signature
if ($header_signature != $payload_signature) {
if ($header_signature !== $payload_signature) {
error_log('FAILED - payload signature');
exit();
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
github.com/gliderlabs/ssh v0.3.1
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
github.com/go-chi/chi v1.5.0
github.com/go-enry/go-enry/v2 v2.5.2
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.2.0
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77 h1:ZLWiTTzTUBb0WEXUxobYI/RxULIzOoIP7pgfDd4p1cw=
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77/go.mod h1:MkKY/CB98aVE4VxO63X5vTQKUgcn+3XP15LMASe3lYs=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
Expand Down Expand Up @@ -323,6 +324,8 @@ github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 h1:gclg6gY70GLy
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us009o8=
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-chi/chi v1.5.0 h1:2ZcJZozJ+rj6BA0c19ffBUGXEKAT/aOLOtQjD46vBRA=
github.com/go-chi/chi v1.5.0/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
github.com/go-enry/go-enry/v2 v2.5.2 h1:3f3PFAO6JitWkPi1GQ5/m6Xu4gNL1U5soJ8QaYqJ0YQ=
github.com/go-enry/go-enry/v2 v2.5.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
Expand Down Expand Up @@ -655,6 +658,7 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4=
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 h1:g0fAGBisHaEQ0TRq1iBvemFRf+8AEWEmBESSiWB3Vsc=
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
Expand Down Expand Up @@ -684,6 +688,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
Expand Down Expand Up @@ -1025,6 +1030,7 @@ github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
github.com/steveyen/gtreap v0.1.0 h1:CjhzTa274PyJLJuMZwIzCO1PfC00oRa8d1Kc78bFXJM=
github.com/steveyen/gtreap v0.1.0/go.mod h1:kl/5J7XbrOmlIbYIXdRHDDE5QxHqpk0cmkT7Z4dM9/Y=
Expand Down Expand Up @@ -1069,6 +1075,7 @@ github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnl
github.com/unknwon/i18n v0.0.0-20190805065654-5c6446a380b6/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c h1:679/gJXwrsHC3RATr0YYjZvDMJPYN7W9FGSGNoLmKxM=
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae h1:ihaXiJkaca54IaCSnEXtE/uSZOmPxKZhDfVLrzZLFDs=
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae/go.mod h1:1fdkY6xxl6ExVs2QFv7R0F5IRZHKA8RahhB9fMC9RvM=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
Expand Down
8 changes: 4 additions & 4 deletions integrations/create_no_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestSessionFileCreation(t *testing.T) {
oldSessionConfig := setting.SessionConfig.ProviderConfig
defer func() {
setting.SessionConfig.ProviderConfig = oldSessionConfig
mac = routes.NewMacaron()
routes.RegisterRoutes(mac)
c = routes.NewChi()
routes.RegisterRoutes(c)
}()

var config session.Options
Expand All @@ -83,8 +83,8 @@ func TestSessionFileCreation(t *testing.T) {

setting.SessionConfig.ProviderConfig = string(newConfigBytes)

mac = routes.NewMacaron()
routes.RegisterRoutes(mac)
c = routes.NewChi()
routes.RegisterRoutes(c)

t.Run("NoSessionOnViewIssue", func(t *testing.T) {
defer PrintCurrentTest(t)()
Expand Down
2 changes: 1 addition & 1 deletion integrations/git_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
defer prepareTestEnv(t, 1)()
}
s := http.Server{
Handler: mac,
Handler: c,
}

u, err := url.Parse(setting.AppURL)
Expand Down
12 changes: 6 additions & 6 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import (
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/routes"

"gitea.com/macaron/macaron"
"github.com/PuerkitoBio/goquery"
"github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
"github.com/unknwon/com"
)

var mac *macaron.Macaron
var c chi.Router

type NilResponseRecorder struct {
httptest.ResponseRecorder
Expand All @@ -67,8 +67,8 @@ func TestMain(m *testing.M) {
defer cancel()

initIntegrationTest()
mac = routes.NewMacaron()
routes.RegisterRoutes(mac)
c = routes.NewChi()
routes.RegisterRoutes(c)

// integration test settings...
if setting.Cfg != nil {
Expand Down Expand Up @@ -404,7 +404,7 @@ const NoExpectedStatus = -1
func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
t.Helper()
recorder := httptest.NewRecorder()
mac.ServeHTTP(recorder, req)
c.ServeHTTP(recorder, req)
if expectedStatus != NoExpectedStatus {
if !assert.EqualValues(t, expectedStatus, recorder.Code,
"Request: %s %s", req.Method, req.URL.String()) {
Expand All @@ -417,7 +417,7 @@ func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.
func MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
t.Helper()
recorder := NewNilResponseRecorder()
mac.ServeHTTP(recorder, req)
c.ServeHTTP(recorder, req)
if expectedStatus != NoExpectedStatus {
if !assert.EqualValues(t, expectedStatus, recorder.Code,
"Request: %s %s", req.Method, req.URL.String()) {
Expand Down
12 changes: 12 additions & 0 deletions integrations/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package integrations

import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"

"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -233,11 +235,21 @@ func TestRefreshTokenInvalidation(t *testing.T) {
"redirect_uri": "a",
"refresh_token": parsed.RefreshToken,
})
// tip: Why this changed, because macaron will set req.Body back when consume the req but chi will not.
bs, err := ioutil.ReadAll(refreshReq.Body)
assert.NoError(t, err)

refreshReq.Body = ioutil.NopCloser(bytes.NewReader(bs))
MakeRequest(t, refreshReq, 200)

refreshReq.Body = ioutil.NopCloser(bytes.NewReader(bs))
MakeRequest(t, refreshReq, 200)

// test with invalidation
setting.OAuth2.InvalidateRefreshTokens = true
refreshReq.Body = ioutil.NopCloser(bytes.NewReader(bs))
MakeRequest(t, refreshReq, 200)

refreshReq.Body = ioutil.NopCloser(bytes.NewReader(bs))
MakeRequest(t, refreshReq, 400)
}
7 changes: 5 additions & 2 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"sync"

"code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/alecthomas/chroma/formatters/html"
Expand Down Expand Up @@ -117,9 +118,11 @@ func File(numLines int, fileName string, code []byte) map[int]string {
fileName = "test." + val
}

lexer := lexers.Match(fileName)
language := analyze.GetCodeLanguage(fileName, code)

lexer := lexers.Get(language)
if lexer == nil {
lexer = lexers.Analyse(string(code))
lexer = lexers.Match(fileName)
if lexer == nil {
lexer = lexers.Fallback
}
Expand Down
8 changes: 8 additions & 0 deletions modules/notification/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,11 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *model
log.Error("PrepareWebhooks: %v", err)
}
}

func (m *webhookNotifier) NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
m.NotifyCreateRef(pusher, repo, refType, refFullName)
}

func (m *webhookNotifier) NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
m.NotifyDeleteRef(pusher, repo, refType, refFullName)
}
6 changes: 2 additions & 4 deletions modules/public/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

package public

import (
"gitea.com/macaron/macaron"
)
import "net/http"

// Static implements the macaron static handler for serving assets.
func Static(opts *Options) macaron.Handler {
func Static(opts *Options) func(next http.Handler) http.Handler {
return opts.staticHandler(opts.Directory)
}
Loading

0 comments on commit 3b3e089

Please sign in to comment.