Skip to content

Commit 112a57d

Browse files
authored
Merge branch 'master' into 13682-review-requested-filter
2 parents 4ee14d2 + 3175d08 commit 112a57d

File tree

145 files changed

+3676
-4423
lines changed

Some content is hidden

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

145 files changed

+3676
-4423
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ rules:
346346
unicorn/catch-error-name: [0]
347347
unicorn/consistent-function-scoping: [2]
348348
unicorn/custom-error-definition: [0]
349+
unicorn/empty-brace-spaces: [2]
349350
unicorn/error-message: [0]
350351
unicorn/escape-case: [0]
351352
unicorn/expiring-todo-comments: [0]
@@ -361,6 +362,7 @@ rules:
361362
unicorn/no-for-loop: [0]
362363
unicorn/no-hex-escape: [0]
363364
unicorn/no-keyword-prefix: [0]
365+
unicorn/no-lonely-if: [2]
364366
unicorn/no-nested-ternary: [0]
365367
unicorn/no-new-buffer: [0]
366368
unicorn/no-null: [0]
@@ -377,6 +379,7 @@ rules:
377379
unicorn/prefer-add-event-listener: [2]
378380
unicorn/prefer-array-find: [2]
379381
unicorn/prefer-dataset: [2]
382+
unicorn/prefer-date-now: [2]
380383
unicorn/prefer-event-key: [2]
381384
unicorn/prefer-includes: [2]
382385
unicorn/prefer-math-trunc: [2]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ lint: lint-frontend lint-backend
317317

318318
.PHONY: lint-frontend
319319
lint-frontend: node_modules
320-
npx eslint --max-warnings=0 web_src/js build templates webpack.config.js
321-
npx stylelint --max-warnings=0 web_src/less
320+
npx eslint --color --max-warnings=0 web_src/js build templates webpack.config.js
321+
npx stylelint --color --max-warnings=0 web_src/less
322322

323323
.PHONY: lint-backend
324324
lint-backend: golangci-lint revive vet
@@ -330,7 +330,7 @@ watch:
330330
.PHONY: watch-frontend
331331
watch-frontend: node-check node_modules
332332
rm -rf $(WEBPACK_DEST_ENTRIES)
333-
NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
333+
NODE_ENV=development npx webpack --watch --progress
334334

335335
.PHONY: watch-backend
336336
watch-backend: go-check
@@ -660,7 +660,7 @@ webpack: $(WEBPACK_DEST)
660660

661661
$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
662662
rm -rf $(WEBPACK_DEST_ENTRIES)
663-
npx webpack --hide-modules --display-entrypoints=false
663+
npx webpack
664664
@touch $(WEBPACK_DEST)
665665

666666
.PHONY: svg

cmd/admin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ var (
282282
Value: "",
283283
Usage: "Use a custom Email URL (option for GitHub)",
284284
},
285+
cli.StringFlag{
286+
Name: "icon-url",
287+
Value: "",
288+
Usage: "Custom icon URL for OAuth2 login source",
289+
},
285290
}
286291

287292
microcmdAuthUpdateOauth = cli.Command{
@@ -606,6 +611,7 @@ func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
606611
ClientSecret: c.String("secret"),
607612
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
608613
CustomURLMapping: customURLMapping,
614+
IconURL: c.String("icon-url"),
609615
}
610616
}
611617

@@ -658,6 +664,10 @@ func runUpdateOauth(c *cli.Context) error {
658664
oAuth2Config.OpenIDConnectAutoDiscoveryURL = c.String("auto-discover-url")
659665
}
660666

667+
if c.IsSet("icon-url") {
668+
oAuth2Config.IconURL = c.String("icon-url")
669+
}
670+
661671
// update custom URL mapping
662672
var customURLMapping = &oauth2.CustomURLMapping{}
663673

cmd/dump_repo.go

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import (
8+
"context"
9+
"errors"
10+
"strings"
11+
12+
"code.gitea.io/gitea/modules/convert"
13+
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/migrations"
15+
"code.gitea.io/gitea/modules/migrations/base"
16+
"code.gitea.io/gitea/modules/setting"
17+
"code.gitea.io/gitea/modules/structs"
18+
19+
"github.com/urfave/cli"
20+
)
21+
22+
// CmdDumpRepository represents the available dump repository sub-command.
23+
var CmdDumpRepository = cli.Command{
24+
Name: "dump-repo",
25+
Usage: "Dump the repository from git/github/gitea/gitlab",
26+
Description: "This is a command for dumping the repository data.",
27+
Action: runDumpRepository,
28+
Flags: []cli.Flag{
29+
cli.StringFlag{
30+
Name: "git_service",
31+
Value: "",
32+
Usage: "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored.",
33+
},
34+
cli.StringFlag{
35+
Name: "repo_dir, r",
36+
Value: "./data",
37+
Usage: "Repository dir path to store the data",
38+
},
39+
cli.StringFlag{
40+
Name: "clone_addr",
41+
Value: "",
42+
Usage: "The URL will be clone, currently could be a git/github/gitea/gitlab http/https URL",
43+
},
44+
cli.StringFlag{
45+
Name: "auth_username",
46+
Value: "",
47+
Usage: "The username to visit the clone_addr",
48+
},
49+
cli.StringFlag{
50+
Name: "auth_password",
51+
Value: "",
52+
Usage: "The password to visit the clone_addr",
53+
},
54+
cli.StringFlag{
55+
Name: "auth_token",
56+
Value: "",
57+
Usage: "The personal token to visit the clone_addr",
58+
},
59+
cli.StringFlag{
60+
Name: "owner_name",
61+
Value: "",
62+
Usage: "The data will be stored on a directory with owner name if not empty",
63+
},
64+
cli.StringFlag{
65+
Name: "repo_name",
66+
Value: "",
67+
Usage: "The data will be stored on a directory with repository name if not empty",
68+
},
69+
cli.StringFlag{
70+
Name: "units",
71+
Value: "",
72+
Usage: `Which items will be migrated, one or more units should be separated as comma.
73+
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
74+
},
75+
},
76+
}
77+
78+
func runDumpRepository(ctx *cli.Context) error {
79+
if err := initDB(); err != nil {
80+
return err
81+
}
82+
83+
log.Trace("AppPath: %s", setting.AppPath)
84+
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
85+
log.Trace("Custom path: %s", setting.CustomPath)
86+
log.Trace("Log path: %s", setting.LogRootPath)
87+
setting.InitDBConfig()
88+
89+
var (
90+
serviceType structs.GitServiceType
91+
cloneAddr = ctx.String("clone_addr")
92+
serviceStr = ctx.String("git_service")
93+
)
94+
95+
if strings.HasPrefix(strings.ToLower(cloneAddr), "https://github.com/") {
96+
serviceStr = "github"
97+
} else if strings.HasPrefix(strings.ToLower(cloneAddr), "https://gitlab.com/") {
98+
serviceStr = "gitlab"
99+
} else if strings.HasPrefix(strings.ToLower(cloneAddr), "https://gitea.com/") {
100+
serviceStr = "gitea"
101+
}
102+
if serviceStr == "" {
103+
return errors.New("git_service missed or clone_addr cannot be recognized")
104+
}
105+
serviceType = convert.ToGitServiceType(serviceStr)
106+
107+
var opts = base.MigrateOptions{
108+
GitServiceType: serviceType,
109+
CloneAddr: cloneAddr,
110+
AuthUsername: ctx.String("auth_username"),
111+
AuthPassword: ctx.String("auth_password"),
112+
AuthToken: ctx.String("auth_token"),
113+
RepoName: ctx.String("repo_name"),
114+
}
115+
116+
if len(ctx.String("units")) == 0 {
117+
opts.Uncyclo = true
118+
opts.Issues = true
119+
opts.Milestones = true
120+
opts.Labels = true
121+
opts.Releases = true
122+
opts.Comments = true
123+
opts.PullRequests = true
124+
opts.ReleaseAssets = true
125+
} else {
126+
units := strings.Split(ctx.String("units"), ",")
127+
for _, unit := range units {
128+
switch strings.ToLower(unit) {
129+
case "wiki":
130+
opts.Uncyclo = true
131+
case "issues":
132+
opts.Issues = true
133+
case "milestones":
134+
opts.Milestones = true
135+
case "labels":
136+
opts.Labels = true
137+
case "releases":
138+
opts.Releases = true
139+
case "release_assets":
140+
opts.ReleaseAssets = true
141+
case "comments":
142+
opts.Comments = true
143+
case "pull_requests":
144+
opts.PullRequests = true
145+
}
146+
}
147+
}
148+
149+
if err := migrations.DumpRepository(
150+
context.Background(),
151+
ctx.String("repo_dir"),
152+
ctx.String("owner_name"),
153+
opts,
154+
); err != nil {
155+
log.Fatal("Failed to dump repository: %v", err)
156+
return err
157+
}
158+
159+
log.Trace("Dump finished!!!")
160+
161+
return nil
162+
}

cmd/restore_repo.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import (
8+
"context"
9+
"strings"
10+
11+
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/migrations"
13+
"code.gitea.io/gitea/modules/migrations/base"
14+
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/storage"
16+
pull_service "code.gitea.io/gitea/services/pull"
17+
18+
"github.com/urfave/cli"
19+
)
20+
21+
// CmdRestoreRepository represents the available restore a repository sub-command.
22+
var CmdRestoreRepository = cli.Command{
23+
Name: "restore-repo",
24+
Usage: "Restore the repository from disk",
25+
Description: "This is a command for restoring the repository data.",
26+
Action: runRestoreRepository,
27+
Flags: []cli.Flag{
28+
cli.StringFlag{
29+
Name: "repo_dir, r",
30+
Value: "./data",
31+
Usage: "Repository dir path to restore from",
32+
},
33+
cli.StringFlag{
34+
Name: "owner_name",
35+
Value: "",
36+
Usage: "Restore destination owner name",
37+
},
38+
cli.StringFlag{
39+
Name: "repo_name",
40+
Value: "",
41+
Usage: "Restore destination repository name",
42+
},
43+
cli.StringFlag{
44+
Name: "units",
45+
Value: "",
46+
Usage: `Which items will be restored, one or more units should be separated as comma.
47+
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
48+
},
49+
},
50+
}
51+
52+
func runRestoreRepository(ctx *cli.Context) error {
53+
if err := initDB(); err != nil {
54+
return err
55+
}
56+
57+
log.Trace("AppPath: %s", setting.AppPath)
58+
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
59+
log.Trace("Custom path: %s", setting.CustomPath)
60+
log.Trace("Log path: %s", setting.LogRootPath)
61+
setting.InitDBConfig()
62+
63+
if err := storage.Init(); err != nil {
64+
return err
65+
}
66+
67+
if err := pull_service.Init(); err != nil {
68+
return err
69+
}
70+
71+
var opts = base.MigrateOptions{
72+
RepoName: ctx.String("repo_name"),
73+
}
74+
75+
if len(ctx.String("units")) == 0 {
76+
opts.Uncyclo = true
77+
opts.Issues = true
78+
opts.Milestones = true
79+
opts.Labels = true
80+
opts.Releases = true
81+
opts.Comments = true
82+
opts.PullRequests = true
83+
opts.ReleaseAssets = true
84+
} else {
85+
units := strings.Split(ctx.String("units"), ",")
86+
for _, unit := range units {
87+
switch strings.ToLower(unit) {
88+
case "wiki":
89+
opts.Uncyclo = true
90+
case "issues":
91+
opts.Issues = true
92+
case "milestones":
93+
opts.Milestones = true
94+
case "labels":
95+
opts.Labels = true
96+
case "releases":
97+
opts.Releases = true
98+
case "release_assets":
99+
opts.ReleaseAssets = true
100+
case "comments":
101+
opts.Comments = true
102+
case "pull_requests":
103+
opts.PullRequests = true
104+
}
105+
}
106+
}
107+
108+
if err := migrations.RestoreRepository(
109+
context.Background(),
110+
ctx.String("repo_dir"),
111+
ctx.String("owner_name"),
112+
ctx.String("repo_name"),
113+
); err != nil {
114+
log.Fatal("Failed to restore repository: %v", err)
115+
return err
116+
}
117+
118+
return nil
119+
}

cmd/serv.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/dgrijalva/jwt-go"
2828
"github.com/kballard/go-shellquote"
29-
"github.com/unknwon/com"
3029
"github.com/urfave/cli"
3130
)
3231

@@ -105,7 +104,10 @@ func runServ(c *cli.Context) error {
105104
if len(keys) != 2 || keys[0] != "key" {
106105
fail("Key ID format error", "Invalid key argument: %s", c.Args()[0])
107106
}
108-
keyID := com.StrTo(keys[1]).MustInt64()
107+
keyID, err := strconv.ParseInt(keys[1], 10, 64)
108+
if err != nil {
109+
fail("Key ID format error", "Invalid key argument: %s", c.Args()[1])
110+
}
109111

110112
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
111113
if len(cmd) == 0 {

0 commit comments

Comments
 (0)