Skip to content

Commit 5094c0d

Browse files
committed
Merge branch 'main' of https://github.com/go-gitea/gitea into feature-incoming-email
2 parents b0a2c8f + 4fc1517 commit 5094c0d

File tree

22 files changed

+344
-637
lines changed

22 files changed

+344
-637
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ linters-settings:
7676
extra-rules: true
7777
lang-version: "1.19"
7878
depguard:
79-
# TODO: use depguard to replace import checks in gitea-vet
8079
list-type: denylist
8180
# Check the list against standard lib.
8281
include-go-root: true
8382
packages-with-error-message:
8483
- encoding/json: "use gitea's modules/json instead of encoding/json"
8584
- github.com/unknwon/com: "use gitea's util and replacements"
85+
- io/ioutil: "use os or io instead"
86+
- golang.org/x/exp: "it's experimental and unreliable."
8687

8788
issues:
8889
max-issues-per-linter: 0

assets/go-licenses.json

Lines changed: 28 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 62 additions & 97 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 141 additions & 486 deletions
Large diffs are not rendered by default.

models/auth/webauthn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/timeutil"
1313
"code.gitea.io/gitea/modules/util"
1414

15-
"github.com/duo-labs/webauthn/webauthn"
15+
"github.com/go-webauthn/webauthn/webauthn"
1616
"xorm.io/xorm"
1717
)
1818

models/auth/webauthn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
auth_model "code.gitea.io/gitea/models/auth"
1010
"code.gitea.io/gitea/models/unittest"
1111

12-
"github.com/duo-labs/webauthn/webauthn"
12+
"github.com/go-webauthn/webauthn/webauthn"
1313
"github.com/stretchr/testify/assert"
1414
)
1515

modules/auth/webauthn/webauthn.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ package webauthn
66
import (
77
"encoding/binary"
88
"encoding/gob"
9-
"net/url"
109

1110
"code.gitea.io/gitea/models/auth"
1211
user_model "code.gitea.io/gitea/models/user"
1312
"code.gitea.io/gitea/modules/setting"
1413

15-
"github.com/duo-labs/webauthn/protocol"
16-
"github.com/duo-labs/webauthn/webauthn"
14+
"github.com/go-webauthn/webauthn/protocol"
15+
"github.com/go-webauthn/webauthn/webauthn"
1716
)
1817

1918
// WebAuthn represents the global WebAuthn instance
@@ -23,13 +22,13 @@ var WebAuthn *webauthn.WebAuthn
2322
func Init() {
2423
gob.Register(&webauthn.SessionData{})
2524

26-
appURL, _ := url.Parse(setting.AppURL)
25+
appURL, _ := protocol.FullyQualifiedOrigin(setting.AppURL)
2726

2827
WebAuthn = &webauthn.WebAuthn{
2928
Config: &webauthn.Config{
3029
RPDisplayName: setting.AppName,
3130
RPID: setting.Domain,
32-
RPOrigin: protocol.FullyQualifiedOrigin(appURL),
31+
RPOrigin: appURL,
3332
AuthenticatorSelection: protocol.AuthenticatorSelection{
3433
UserVerification: "discouraged",
3534
},

modules/setting/mailer.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/log"
1313

1414
shellquote "github.com/kballard/go-shellquote"
15+
ini "gopkg.in/ini.v1"
1516
)
1617

1718
// Mailer represents mail service.
@@ -49,8 +50,8 @@ type Mailer struct {
4950
// MailService the global mailer
5051
var MailService *Mailer
5152

52-
func newMailService() {
53-
sec := Cfg.Section("mailer")
53+
func parseMailerConfig(rootCfg *ini.File) {
54+
sec := rootCfg.Section("mailer")
5455
// Check mailer setting.
5556
if !sec.Key("ENABLED").MustBool() {
5657
return
@@ -70,9 +71,14 @@ func newMailService() {
7071
if sec.HasKey("HOST") && !sec.HasKey("SMTP_ADDR") {
7172
givenHost := sec.Key("HOST").String()
7273
addr, port, err := net.SplitHostPort(givenHost)
73-
if err != nil {
74+
if err != nil && strings.Contains(err.Error(), "missing port in address") {
75+
addr = givenHost
76+
} else if err != nil {
7477
log.Fatal("Invalid mailer.HOST (%s): %v", givenHost, err)
7578
}
79+
if addr == "" {
80+
addr = "127.0.0.1"
81+
}
7682
sec.Key("SMTP_ADDR").MustString(addr)
7783
sec.Key("SMTP_PORT").MustString(port)
7884
}
@@ -172,6 +178,9 @@ func newMailService() {
172178
default:
173179
log.Error("unable to infer unspecified mailer.PROTOCOL from mailer.SMTP_PORT = %q, assume using smtps", MailService.SMTPPort)
174180
MailService.Protocol = "smtps"
181+
if MailService.SMTPPort == "" {
182+
MailService.SMTPPort = "465"
183+
}
175184
}
176185
}
177186
}

modules/setting/mailer_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package setting
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
ini "gopkg.in/ini.v1"
11+
)
12+
13+
func TestParseMailerConfig(t *testing.T) {
14+
iniFile := ini.Empty()
15+
kases := map[string]*Mailer{
16+
"smtp.mydomain.com": {
17+
SMTPAddr: "smtp.mydomain.com",
18+
SMTPPort: "465",
19+
},
20+
"smtp.mydomain.com:123": {
21+
SMTPAddr: "smtp.mydomain.com",
22+
SMTPPort: "123",
23+
},
24+
":123": {
25+
SMTPAddr: "127.0.0.1",
26+
SMTPPort: "123",
27+
},
28+
}
29+
for host, kase := range kases {
30+
t.Run(host, func(t *testing.T) {
31+
iniFile.DeleteSection("mailer")
32+
sec := iniFile.Section("mailer")
33+
sec.NewKey("ENABLED", "true")
34+
sec.NewKey("HOST", host)
35+
36+
// Check mailer setting
37+
parseMailerConfig(iniFile)
38+
39+
assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
40+
assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)
41+
})
42+
}
43+
}

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ func NewServices() {
13401340
newCacheService()
13411341
newSessionService()
13421342
newCORSService()
1343-
newMailService()
1343+
parseMailerConfig(Cfg)
13441344
newIncomingEmail()
13451345
newRegisterMailService()
13461346
newNotifyMailService()
@@ -1358,5 +1358,5 @@ func NewServices() {
13581358
// NewServicesForInstall initializes the services for install
13591359
func NewServicesForInstall() {
13601360
newService()
1361-
newMailService()
1361+
parseMailerConfig(Cfg)
13621362
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ issues.label_title = Label name
13791379
issues.label_description = Label description
13801380
issues.label_color = Label color
13811381
issues.label_count = %d labels
1382-
issues.label_open_issues = %d open issues
1382+
issues.label_open_issues = %d open issues/pull requests
13831383
issues.label_edit = Edit
13841384
issues.label_delete = Delete
13851385
issues.label_modify = Edit Label

routers/web/auth/webauthn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"code.gitea.io/gitea/modules/setting"
1717
"code.gitea.io/gitea/services/externalaccount"
1818

19-
"github.com/duo-labs/webauthn/protocol"
20-
"github.com/duo-labs/webauthn/webauthn"
19+
"github.com/go-webauthn/webauthn/protocol"
20+
"github.com/go-webauthn/webauthn/webauthn"
2121
)
2222

2323
var tplWebAuthn base.TplName = "user/auth/webauthn"

routers/web/user/setting/security/webauthn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"code.gitea.io/gitea/modules/web"
1616
"code.gitea.io/gitea/services/forms"
1717

18-
"github.com/duo-labs/webauthn/protocol"
19-
"github.com/duo-labs/webauthn/webauthn"
18+
"github.com/go-webauthn/webauthn/protocol"
19+
"github.com/go-webauthn/webauthn/webauthn"
2020
)
2121

2222
// WebAuthnRegister initializes the webauthn registration procedure

services/migrations/gitlab.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,10 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
352352
releases := make([]*base.Release, 0, perPage)
353353
for i := 1; ; i++ {
354354
ls, _, err := g.client.Releases.ListReleases(g.repoID, &gitlab.ListReleasesOptions{
355-
Page: i,
356-
PerPage: perPage,
355+
ListOptions: gitlab.ListOptions{
356+
Page: i,
357+
PerPage: perPage,
358+
},
357359
}, nil, gitlab.WithContext(g.ctx))
358360
if err != nil {
359361
return nil, err

services/repository/check.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
7373
return db.ErrCancelledf("before GC of %s", repo.FullName())
7474
default:
7575
}
76-
return GitGcRepo(ctx, repo, timeout, args)
76+
// we can ignore the error here because it will be logged in GitGCRepo
77+
_ = GitGcRepo(ctx, repo, timeout, args)
78+
return nil
7779
},
7880
); err != nil {
7981
return err
@@ -93,9 +95,9 @@ func GitGcRepo(ctx context.Context, repo *repo_model.Repository, timeout time.Du
9395
stdout, _, err = command.RunStdString(&git.RunOpts{Timeout: timeout, Dir: repo.RepoPath()})
9496

9597
if err != nil {
96-
log.Error("Repository garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
98+
log.Error("Repository garbage collection failed for %-v. Stdout: %s\nError: %v", repo, stdout, err)
9799
desc := fmt.Sprintf("Repository garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
98-
if err = system_model.CreateRepositoryNotice(desc); err != nil {
100+
if err := system_model.CreateRepositoryNotice(desc); err != nil {
99101
log.Error("CreateRepositoryNotice: %v", err)
100102
}
101103
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %w", repo.FullName(), err)
@@ -105,7 +107,7 @@ func GitGcRepo(ctx context.Context, repo *repo_model.Repository, timeout time.Du
105107
if err := repo_module.UpdateRepoSize(ctx, repo); err != nil {
106108
log.Error("Updating size as part of garbage collection failed for %-v. Stdout: %s\nError: %v", repo, stdout, err)
107109
desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
108-
if err = system_model.CreateRepositoryNotice(desc); err != nil {
110+
if err := system_model.CreateRepositoryNotice(desc); err != nil {
109111
log.Error("CreateRepositoryNotice: %v", err)
110112
}
111113
return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %w", repo.FullName(), err)
@@ -165,7 +167,7 @@ func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error
165167
}
166168
log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
167169
if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
168-
log.Error("Failed to DeleteRepository %s [%d]: Error: %v", repo.FullName(), repo.ID, err)
170+
log.Error("Failed to DeleteRepository %-v: Error: %v", repo, err)
169171
if err2 := system_model.CreateRepositoryNotice("Failed to DeleteRepository %s [%d]: Error: %v", repo.FullName(), repo.ID, err); err2 != nil {
170172
log.Error("CreateRepositoryNotice: %v", err)
171173
}

templates/base/head.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="{{.locale.Lang}}" class="theme-{{if .SignedUser.Theme}}{{.SignedUser.Theme}}{{else}}auto{{end}}">
2+
<html lang="{{.locale.Lang}}" class="theme-{{if .SignedUser.Theme}}{{.SignedUser.Theme}}{{else}}{{DefaultTheme}}{{end}}">
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">

templates/explore/repo_search.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131
</form>
3232
{{if .OnlyShowRelevant}}
33-
<div class="ui blue attached message explore-relevancy-note">
33+
<div class="ui message explore-relevancy-note">
3434
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span>
3535
</div>
3636
{{end}}

templates/repo/diff/box.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
{{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}}
144144
{{else}}
145145
{{$.locale.Tr "repo.diff.file_suppressed"}}
146-
<a class="ui basic tiny button diff-show-more-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
146+
<a class="ui basic tiny button diff-load-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
147147
{{end}}
148148
{{else}}
149149
{{$.locale.Tr "repo.diff.bin_not_shown"}}

web_src/js/components/DiffFileTree.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item" />
99
</div>
1010
<div v-if="isIncomplete" id="diff-too-many-files-stats" class="pt-2">
11-
<span>{{ tooManyFilesMessage }}</span><a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
11+
<span class="mr-2">{{ tooManyFilesMessage }}</span><a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
1212
</div>
1313
</div>
1414
</template>
@@ -94,6 +94,9 @@ export default {
9494
mounted() {
9595
// ensure correct buttons when we are mounted to the dom
9696
this.adjustToggleButton(this.fileTreeIsVisible);
97+
// replace the pageData.diffFileInfo.files with our watched data so we get updates
98+
pageData.diffFileInfo.files = this.files;
99+
97100
document.querySelector('.diff-toggle-file-tree-button').addEventListener('click', this.toggleVisibility);
98101
},
99102
unmounted() {

web_src/js/features/repo-diff.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,47 @@ function onShowMoreFiles() {
119119

120120
export function doLoadMoreFiles(link, diffEnd, callback) {
121121
const url = `${link}?skip-to=${diffEnd}&file-only=true`;
122+
loadMoreFiles(url, callback);
123+
}
124+
125+
function loadMoreFiles(url, callback) {
126+
const $target = $('a#diff-show-more-files');
127+
if ($target.hasClass('disabled')) {
128+
callback();
129+
return;
130+
}
131+
$target.addClass('disabled');
122132
$.ajax({
123133
type: 'GET',
124134
url,
125135
}).done((resp) => {
126136
if (!resp) {
137+
$target.removeClass('disabled');
127138
callback(resp);
128139
return;
129140
}
141+
$('#diff-incomplete').replaceWith($(resp).find('#diff-file-boxes').children());
130142
// By simply rerunning the script we add the new data to our existing
131143
// pagedata object. this triggers vue and the filetree and filelist will
132144
// render the new elements.
133145
$('body').append($(resp).find('script#diff-data-script'));
146+
onShowMoreFiles();
134147
callback(resp);
135148
}).fail(() => {
149+
$target.removeClass('disabled');
136150
callback();
137151
});
138152
}
139153

140154
export function initRepoDiffShowMore() {
141-
$(document).on('click', 'a.diff-show-more-button', (e) => {
155+
$(document).on('click', 'a#diff-show-more-files', (e) => {
156+
e.preventDefault();
157+
158+
const $target = $(e.target);
159+
loadMoreFiles($target.data('href'), () => {});
160+
});
161+
162+
$(document).on('click', 'a.diff-load-button', (e) => {
142163
e.preventDefault();
143164
const $target = $(e.target);
144165

web_src/less/_explore.less

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,3 @@
8989
}
9090
}
9191
}
92-
93-
.ui.explore-relevancy-note {
94-
border-top: 0;
95-
margin-top: 0;
96-
max-width: 90%;
97-
}

web_src/less/_repository.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,9 @@
16671667
background-color: var(--color-teal);
16681668
}
16691669
}
1670+
.button {
1671+
padding: 8px 12px;
1672+
}
16701673
}
16711674

16721675
.diff-box .header:not(.resolved-placeholder) {

0 commit comments

Comments
 (0)