Skip to content

Commit dc7078d

Browse files
authored
Merge branch 'main' into compare
2 parents 7d9723d + c77e814 commit dc7078d

File tree

10 files changed

+45
-46
lines changed

10 files changed

+45
-46
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* text=auto eol=lf
22
*.tmpl linguist-language=Handlebars
3+
*.pb.go linguist-generated
34
/assets/*.json linguist-generated
45
/public/assets/img/svg/*.svg linguist-generated
56
/templates/swagger/v1_json.tmpl linguist-generated

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ clean:
295295

296296
.PHONY: fmt
297297
fmt:
298-
GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
298+
@GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
299299
$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
300300
@# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
301301
@# whitespace before it

build/code-batch-process.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func newFileCollector(fileFilter string, batchSize int) (*fileCollector, error)
6969
co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`))
7070

7171
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`.*\bbindata\.go$`))
72+
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`\.pb\.go$`))
7273
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/gitea-repositories-meta`))
7374
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/integration/migration-test`))
7475
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`modules/git/tests`))
@@ -203,17 +204,6 @@ Example:
203204
`, "file-batch-exec")
204205
}
205206

206-
func getGoVersion() string {
207-
goModFile, err := os.ReadFile("go.mod")
208-
if err != nil {
209-
log.Fatalf(`Faild to read "go.mod": %v`, err)
210-
os.Exit(1)
211-
}
212-
goModVersionRegex := regexp.MustCompile(`go \d+\.\d+`)
213-
goModVersionLine := goModVersionRegex.Find(goModFile)
214-
return string(goModVersionLine[3:])
215-
}
216-
217207
func newFileCollectorFromMainOptions(mainOptions map[string]string) (fc *fileCollector, err error) {
218208
fileFilter := mainOptions["file-filter"]
219209
if fileFilter == "" {
@@ -278,7 +268,8 @@ func main() {
278268
log.Print("the -d option is not supported by gitea-fmt")
279269
}
280270
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-w")))
281-
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...)))
271+
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", append([]string{"-w", "-r", "interface{} -> any"}, substArgs...)))
272+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra"}, substArgs...)))
282273
default:
283274
log.Fatalf("unknown cmd: %s %v", subCmd, subArgs)
284275
}

modules/optional/serialization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error {
3535
return nil
3636
}
3737

38-
func (o Option[T]) MarshalYAML() (interface{}, error) {
38+
func (o Option[T]) MarshalYAML() (any, error) {
3939
if !o.Has() {
4040
return nil, nil
4141
}

modules/templates/util_misc.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,35 +142,39 @@ type remoteAddress struct {
142142
Password string
143143
}
144144

145-
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string, ignoreOriginalURL bool) remoteAddress {
146-
a := remoteAddress{}
147-
148-
remoteURL := m.OriginalURL
149-
if ignoreOriginalURL || remoteURL == "" {
150-
var err error
151-
remoteURL, err = git.GetRemoteAddress(ctx, m.RepoPath(), remoteName)
152-
if err != nil {
153-
log.Error("GetRemoteURL %v", err)
154-
return a
155-
}
145+
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
146+
ret := remoteAddress{}
147+
remoteURL, err := git.GetRemoteAddress(ctx, m.RepoPath(), remoteName)
148+
if err != nil {
149+
log.Error("GetRemoteURL %v", err)
150+
return ret
156151
}
157152

158153
u, err := giturl.Parse(remoteURL)
159154
if err != nil {
160155
log.Error("giturl.Parse %v", err)
161-
return a
156+
return ret
162157
}
163158

164159
if u.Scheme != "ssh" && u.Scheme != "file" {
165160
if u.User != nil {
166-
a.Username = u.User.Username()
167-
a.Password, _ = u.User.Password()
161+
ret.Username = u.User.Username()
162+
ret.Password, _ = u.User.Password()
168163
}
169-
u.User = nil
170164
}
171-
a.Address = u.String()
172165

173-
return a
166+
// The URL stored in the git repo could contain authentication,
167+
// erase it, or it will be shown in the UI.
168+
u.User = nil
169+
ret.Address = u.String()
170+
// Why not use m.OriginalURL to set ret.Address?
171+
// It should be OK to use it, since m.OriginalURL should be the same as the authentication-erased URL from the Git repository.
172+
// However, the old code has already stored authentication in m.OriginalURL when updating mirror settings.
173+
// That means we need to use "giturl.Parse" for m.OriginalURL again to ensure authentication is erased.
174+
// Instead of doing this, why not directly use the authentication-erased URL from the Git repository?
175+
// It should be the same as long as there are no bugs.
176+
177+
return ret
174178
}
175179

176180
func FilenameIsImage(filename string) bool {

routers/web/org/projects.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10-
"net/url"
1110
"strconv"
1211
"strings"
1312

@@ -195,22 +194,23 @@ func NewProjectPost(ctx *context.Context) {
195194

196195
// ChangeProjectStatus updates the status of a project between "open" and "close"
197196
func ChangeProjectStatus(ctx *context.Context) {
198-
toClose := false
197+
var toClose bool
199198
switch ctx.Params(":action") {
200199
case "open":
201200
toClose = false
202201
case "close":
203202
toClose = true
204203
default:
205-
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
204+
ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
205+
return
206206
}
207207
id := ctx.ParamsInt64(":id")
208208

209209
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil {
210210
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
211211
return
212212
}
213-
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action")))
213+
ctx.JSONRedirect(fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), id))
214214
}
215215

216216
// DeleteProject delete a project

routers/web/repo/projects.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10-
"net/url"
1110
"strings"
1211

1312
"code.gitea.io/gitea/models/db"
@@ -181,14 +180,10 @@ func ChangeProjectStatus(ctx *context.Context) {
181180
id := ctx.ParamsInt64(":id")
182181

183182
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
184-
if project_model.IsErrProjectNotExist(err) {
185-
ctx.NotFound("", err)
186-
} else {
187-
ctx.ServerError("ChangeProjectStatusByIDAndRepoID", err)
188-
}
183+
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
189184
return
190185
}
191-
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action")))
186+
ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id))
192187
}
193188

194189
// DeleteProject delete a project

services/actions/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestCreateAuthorizationToken(t *testing.T) {
2020
assert.Nil(t, err)
2121
assert.NotEqual(t, "", token)
2222
claims := jwt.MapClaims{}
23-
_, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (interface{}, error) {
23+
_, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {
2424
return setting.GetGeneralTokenSigningSecret(), nil
2525
})
2626
assert.Nil(t, err)

services/mirror/mirror_pull.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
system_model "code.gitea.io/gitea/models/system"
1414
"code.gitea.io/gitea/modules/cache"
1515
"code.gitea.io/gitea/modules/git"
16+
giturl "code.gitea.io/gitea/modules/git/url"
1617
"code.gitea.io/gitea/modules/gitrepo"
1718
"code.gitea.io/gitea/modules/lfs"
1819
"code.gitea.io/gitea/modules/log"
@@ -30,10 +31,15 @@ const gitShortEmptySha = "0000000"
3031

3132
// UpdateAddress writes new address to Git repository and database
3233
func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error {
34+
u, err := giturl.Parse(addr)
35+
if err != nil {
36+
return fmt.Errorf("invalid addr: %v", err)
37+
}
38+
3339
remoteName := m.GetRemoteName()
3440
repoPath := m.GetRepository(ctx).RepoPath()
3541
// Remove old remote
36-
_, _, err := git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(remoteName).RunStdString(&git.RunOpts{Dir: repoPath})
42+
_, _, err = git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(remoteName).RunStdString(&git.RunOpts{Dir: repoPath})
3743
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
3844
return err
3945
}
@@ -70,7 +76,9 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
7076
}
7177
}
7278

73-
m.Repo.OriginalURL = addr
79+
// erase authentication before storing in database
80+
u.User = nil
81+
m.Repo.OriginalURL = u.String()
7482
return repo_model.UpdateRepositoryCols(ctx, m.Repo, "original_url")
7583
}
7684

templates/repo/settings/options.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<label for="interval">{{ctx.Locale.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
157157
<input id="interval" name="interval" value="{{.PullMirror.Interval}}">
158158
</div>
159-
{{$address := MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false}}
159+
{{$address := MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName}}
160160
<div class="field {{if .Err_MirrorAddress}}error{{end}}">
161161
<label for="mirror_address">{{ctx.Locale.Tr "repo.mirror_address"}}</label>
162162
<input id="mirror_address" name="mirror_address" value="{{$address.Address}}" required>

0 commit comments

Comments
 (0)