Skip to content

Commit f666bbc

Browse files
Merge branch 'master' into remote-internal-token
2 parents d38a69d + 202a8f6 commit f666bbc

File tree

134 files changed

+5801
-265
lines changed

Some content is hidden

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

134 files changed

+5801
-265
lines changed

.github/issue_template.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
<!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue -->
2+
13
<!--
2-
1. Please speak English, this is the language all of us can speak and write.
4+
1. Please speak English, this is the language all maintainers can speak and write.
35
2. Please ask questions or configuration/deploy problems on our Discord
4-
server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io).
6+
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
57
3. Please take a moment to check that your issue doesn't already exist.
68
4. Please give all relevant information below for bug reports, because
79
incomplete details will be handled as an invalid report.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
###################################
33
#Build stage
4-
FROM golang:1.11-alpine3.9 AS build-env
4+
FROM golang:1.12-alpine3.9 AS build-env
55

66
ARG GITEA_VERSION
77
ARG TAGS="sqlite sqlite_unlock_notify"

Gopkg.lock

+20-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ ignored = ["google.golang.org/appengine*"]
113113
[[constraint]]
114114
name = "github.com/prometheus/client_golang"
115115
version = "0.9.0"
116+
117+
[[constraint]]
118+
name = "github.com/mvdan/xurls"
119+
version = "2.0.0"

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,7 @@ generate-images:
420420
$(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
421421
$(PWD)/public/img/favicon.ico
422422
rm -rf $(TMPDIR)/images
423+
424+
.PHONY: pr
425+
pr:
426+
$(GO) run contrib/pr/checkout.go $(PR)

cmd/generate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func runGenerateInternalToken(c *cli.Context) error {
6363
}
6464

6565
func runGenerateLfsJwtSecret(c *cli.Context) error {
66-
JWTSecretBase64, err := generate.NewLfsJwtSecret()
66+
JWTSecretBase64, err := generate.NewJwtSecret()
6767
if err != nil {
6868
return err
6969
}

contrib/pr/checkout.go

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
package main
2+
3+
/*
4+
Checkout a PR and load the tests data into sqlite database
5+
*/
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"io/ioutil"
11+
"log"
12+
"net/http"
13+
"net/url"
14+
"os"
15+
"os/exec"
16+
"os/user"
17+
"path"
18+
"path/filepath"
19+
"runtime"
20+
"time"
21+
22+
"code.gitea.io/gitea/modules/markup/external"
23+
"code.gitea.io/gitea/routers"
24+
"code.gitea.io/gitea/routers/routes"
25+
"github.com/Unknwon/com"
26+
"github.com/go-xorm/xorm"
27+
context2 "github.com/gorilla/context"
28+
"gopkg.in/src-d/go-git.v4"
29+
"gopkg.in/src-d/go-git.v4/config"
30+
"gopkg.in/src-d/go-git.v4/plumbing"
31+
"gopkg.in/testfixtures.v2"
32+
33+
"code.gitea.io/gitea/models"
34+
"code.gitea.io/gitea/modules/setting"
35+
)
36+
37+
var codeFilePath = "contrib/pr/checkout.go"
38+
39+
func runPR() {
40+
log.Printf("[PR] Starting gitea ...\n")
41+
curDir, err := os.Getwd()
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
setting.NewContext()
46+
47+
setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")
48+
if err != nil {
49+
log.Fatalf("TempDir: %v\n", err)
50+
}
51+
setting.AppDataPath, err = ioutil.TempDir(os.TempDir(), "appdata")
52+
if err != nil {
53+
log.Fatalf("TempDir: %v\n", err)
54+
}
55+
setting.AppWorkPath = curDir
56+
setting.StaticRootPath = curDir
57+
setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/")
58+
if err != nil {
59+
log.Fatalf("url.Parse: %v\n", err)
60+
}
61+
62+
setting.AppURL = "http://localhost:8080/"
63+
setting.HTTPPort = "8080"
64+
setting.SSH.Domain = "localhost"
65+
setting.SSH.Port = 3000
66+
setting.InstallLock = true
67+
setting.SecretKey = "9pCviYTWSb"
68+
setting.InternalToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.OQkH5UmzID2XBdwQ9TAI6Jj2t1X-wElVTjbE7aoN4I8"
69+
curUser, err := user.Current()
70+
if err != nil {
71+
log.Fatal(err)
72+
}
73+
setting.RunUser = curUser.Username
74+
75+
log.Printf("[PR] Loading fixtures data ...\n")
76+
setting.CheckLFSVersion()
77+
//models.LoadConfigs()
78+
/*
79+
models.DbCfg.Type = "sqlite3"
80+
models.DbCfg.Path = ":memory:"
81+
models.DbCfg.Timeout = 500
82+
*/
83+
db := setting.Cfg.Section("database")
84+
db.NewKey("DB_TYPE", "sqlite3")
85+
db.NewKey("PATH", ":memory:")
86+
setting.LogSQL = true
87+
models.LoadConfigs()
88+
routers.NewServices()
89+
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
90+
91+
var helper testfixtures.Helper
92+
helper = &testfixtures.SQLite{}
93+
models.NewEngine(func(_ *xorm.Engine) error {
94+
return nil
95+
})
96+
models.HasEngine = true
97+
//x.ShowSQL(true)
98+
err = models.InitFixtures(
99+
helper,
100+
path.Join(curDir, "models/fixtures/"),
101+
)
102+
if err != nil {
103+
fmt.Printf("Error initializing test database: %v\n", err)
104+
os.Exit(1)
105+
}
106+
models.LoadFixtures()
107+
os.RemoveAll(setting.RepoRootPath)
108+
os.RemoveAll(models.LocalCopyPath())
109+
os.RemoveAll(models.LocalWikiPath())
110+
com.CopyDir(path.Join(curDir, "integrations/gitea-repositories-meta"), setting.RepoRootPath)
111+
112+
log.Printf("[PR] Setting up router\n")
113+
//routers.GlobalInit()
114+
external.RegisterParsers()
115+
m := routes.NewMacaron()
116+
routes.RegisterRoutes(m)
117+
118+
log.Printf("[PR] Ready for testing !\n")
119+
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")
120+
/*
121+
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
122+
123+
if setting.LFS.StartServer {
124+
log.Info("LFS server enabled")
125+
}
126+
127+
if setting.EnablePprof {
128+
go func() {
129+
log.Info("Starting pprof server on localhost:6060")
130+
log.Info("%v", http.ListenAndServe("localhost:6060", nil))
131+
}()
132+
}
133+
*/
134+
135+
//Start the server
136+
http.ListenAndServe(":8080", context2.ClearHandler(m))
137+
138+
log.Printf("[PR] Cleaning up ...\n")
139+
/*
140+
if err = os.RemoveAll(setting.Indexer.IssuePath); err != nil {
141+
fmt.Printf("os.RemoveAll: %v\n", err)
142+
os.Exit(1)
143+
}
144+
if err = os.RemoveAll(setting.Indexer.RepoPath); err != nil {
145+
fmt.Printf("Unable to remove repo indexer: %v\n", err)
146+
os.Exit(1)
147+
}
148+
*/
149+
if err = os.RemoveAll(setting.RepoRootPath); err != nil {
150+
log.Fatalf("os.RemoveAll: %v\n", err)
151+
}
152+
if err = os.RemoveAll(setting.AppDataPath); err != nil {
153+
log.Fatalf("os.RemoveAll: %v\n", err)
154+
}
155+
}
156+
157+
func main() {
158+
var runPRFlag = flag.Bool("run", false, "Run the PR code")
159+
flag.Parse()
160+
if *runPRFlag {
161+
runPR()
162+
return
163+
}
164+
165+
//Otherwise checkout PR
166+
if len(os.Args) != 2 {
167+
log.Fatal("Need only one arg: the PR number")
168+
}
169+
pr := os.Args[1]
170+
171+
codeFilePath = filepath.FromSlash(codeFilePath) //Convert to running OS
172+
173+
//Copy this file if it will not exist in the PR branch
174+
dat, err := ioutil.ReadFile(codeFilePath)
175+
if err != nil {
176+
log.Fatalf("Failed to cache this code file : %v", err)
177+
}
178+
179+
repo, err := git.PlainOpen(".")
180+
if err != nil {
181+
log.Fatalf("Failed to open the repo : %v", err)
182+
}
183+
184+
//Find remote upstream
185+
remotes, err := repo.Remotes()
186+
if err != nil {
187+
log.Fatalf("Failed to list remotes of repo : %v", err)
188+
}
189+
remoteUpstream := "origin" //Default
190+
for _, r := range remotes {
191+
if r.Config().URLs[0] == "https://github.com/go-gitea/gitea" || r.Config().URLs[0] == "git@github.com:go-gitea/gitea.git" { //fetch at index 0
192+
remoteUpstream = r.Config().Name
193+
break
194+
}
195+
}
196+
197+
branch := fmt.Sprintf("pr-%s-%d", pr, time.Now().Unix())
198+
branchRef := plumbing.NewBranchReferenceName(branch)
199+
200+
log.Printf("Fetching PR #%s in %s\n", pr, branch)
201+
if runtime.GOOS == "windows" {
202+
//Use git cli command for windows
203+
runCmd("git", "fetch", remoteUpstream, fmt.Sprintf("pull/%s/head:%s", pr, branch))
204+
} else {
205+
ref := fmt.Sprintf("refs/pull/%s/head:%s", pr, branchRef)
206+
err = repo.Fetch(&git.FetchOptions{
207+
RemoteName: remoteUpstream,
208+
RefSpecs: []config.RefSpec{
209+
config.RefSpec(ref),
210+
},
211+
})
212+
if err != nil {
213+
log.Fatalf("Failed to fetch %s from %s : %v", ref, remoteUpstream, err)
214+
}
215+
}
216+
217+
tree, err := repo.Worktree()
218+
if err != nil {
219+
log.Fatalf("Failed to parse git tree : %v", err)
220+
}
221+
log.Printf("Checkout PR #%s in %s\n", pr, branch)
222+
err = tree.Checkout(&git.CheckoutOptions{
223+
Branch: branchRef,
224+
//Force: runtime.GOOS == "windows",
225+
})
226+
if err != nil {
227+
log.Fatalf("Failed to checkout %s : %v", branch, err)
228+
}
229+
230+
//Copy this file if not exist
231+
if _, err := os.Stat(codeFilePath); os.IsNotExist(err) {
232+
err = os.MkdirAll(filepath.Dir(codeFilePath), 0755)
233+
if err != nil {
234+
log.Fatalf("Failed to duplicate this code file in PR : %v", err)
235+
}
236+
err = ioutil.WriteFile(codeFilePath, dat, 0644)
237+
if err != nil {
238+
log.Fatalf("Failed to duplicate this code file in PR : %v", err)
239+
}
240+
}
241+
time.Sleep(5 * time.Second)
242+
//Start with integration test
243+
runCmd("go", "run", "-tags", "sqlite sqlite_unlock_notify", codeFilePath, "-run")
244+
}
245+
func runCmd(cmd ...string) {
246+
log.Printf("Executing : %s ...\n", cmd)
247+
c := exec.Command(cmd[0], cmd[1:]...)
248+
c.Stdout = os.Stdout
249+
c.Stderr = os.Stderr
250+
if err := c.Start(); err != nil {
251+
log.Panicln(err)
252+
}
253+
if err := c.Wait(); err != nil {
254+
log.Panicln(err)
255+
}
256+
}

custom/conf/app.ini.sample

+10
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ DEFAULT_PAGING_NUM = 30
654654
; Default and maximum number of items per page for git trees api
655655
DEFAULT_GIT_TREES_PER_PAGE = 1000
656656

657+
[oauth2]
658+
; Enables OAuth2 provider
659+
ENABLED = true
660+
; Lifetime of an OAuth2 access token in seconds
661+
ACCESS_TOKEN_EXPIRATION_TIME=3600
662+
; Lifetime of an OAuth2 access token in hours
663+
REFRESH_TOKEN_EXPIRATION_TIME=730
664+
; OAuth2 authentication secret for access and refresh tokens, change this a unique string.
665+
JWT_SECRET=Bk0yK7Y9g_p56v86KaHqjSbxvNvu3SbKoOdOt2ZcXvU
666+
657667
[i18n]
658668
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR
659669
NAMES = English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어

0 commit comments

Comments
 (0)