Skip to content

Commit 717f2ab

Browse files
committed
Merge remote-tracking branch 'origin/master' into time-user-filter
2 parents 276f68b + addd424 commit 717f2ab

Some content is hidden

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

50 files changed

+434
-113
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,re
6666
PREFIX_ARCHIVE_FILES = true
6767
; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
6868
DISABLE_MIRRORS = false
69+
; Disable migrating feature.
70+
DISABLE_MIGRATIONS = false
6971
; The default branch name of new repositories
7072
DEFAULT_BRANCH = master
7173
; Allow adoption of unadopted repositories

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7474
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects**: Comma separated list of default repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
7575
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
7676
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
77+
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
7778
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
7879
- `ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to adopt unadopted repositories
7980
- `ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to delete unadopted repositories

integrations/api_settings_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func TestAPIExposedSettings(t *testing.T) {
4343

4444
DecodeJSON(t, resp, &repo)
4545
assert.EqualValues(t, &api.GeneralRepoSettings{
46-
MirrorsDisabled: setting.Repository.DisableMirrors,
47-
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
46+
MirrorsDisabled: setting.Repository.DisableMirrors,
47+
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
48+
MigrationsDisabled: setting.Repository.DisableMigrations,
4849
}, repo)
4950

5051
attachment := new(api.GeneralAttachmentSettings)

models/issue.go

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,30 +1847,43 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
18471847
if err = issue.loadRepo(ctx.e); err != nil {
18481848
return
18491849
}
1850-
resolved := make(map[string]bool, 20)
1851-
names := make([]string, 0, 20)
1850+
1851+
resolved := make(map[string]bool, 10)
1852+
var mentionTeams []string
1853+
1854+
if err := issue.Repo.getOwner(ctx.e); err != nil {
1855+
return nil, err
1856+
}
1857+
1858+
repoOwnerIsOrg := issue.Repo.Owner.IsOrganization()
1859+
if repoOwnerIsOrg {
1860+
mentionTeams = make([]string, 0, 5)
1861+
}
1862+
18521863
resolved[doer.LowerName] = true
18531864
for _, name := range mentions {
18541865
name := strings.ToLower(name)
18551866
if _, ok := resolved[name]; ok {
18561867
continue
18571868
}
1858-
resolved[name] = false
1859-
names = append(names, name)
1860-
}
1861-
1862-
if err := issue.Repo.getOwner(ctx.e); err != nil {
1863-
return nil, err
1869+
if repoOwnerIsOrg && strings.Contains(name, "/") {
1870+
names := strings.Split(name, "/")
1871+
if len(names) < 2 || names[0] != issue.Repo.Owner.LowerName {
1872+
continue
1873+
}
1874+
mentionTeams = append(mentionTeams, names[1])
1875+
resolved[name] = true
1876+
} else {
1877+
resolved[name] = false
1878+
}
18641879
}
18651880

1866-
if issue.Repo.Owner.IsOrganization() {
1867-
// Since there can be users with names that match the name of a team,
1868-
// if the team exists and can read the issue, the team takes precedence.
1869-
teams := make([]*Team, 0, len(names))
1881+
if issue.Repo.Owner.IsOrganization() && len(mentionTeams) > 0 {
1882+
teams := make([]*Team, 0, len(mentionTeams))
18701883
if err := ctx.e.
18711884
Join("INNER", "team_repo", "team_repo.team_id = team.id").
18721885
Where("team_repo.repo_id=?", issue.Repo.ID).
1873-
In("team.lower_name", names).
1886+
In("team.lower_name", mentionTeams).
18741887
Find(&teams); err != nil {
18751888
return nil, fmt.Errorf("find mentioned teams: %v", err)
18761889
}
@@ -1883,7 +1896,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
18831896
for _, team := range teams {
18841897
if team.Authorize >= AccessModeOwner {
18851898
checked = append(checked, team.ID)
1886-
resolved[team.LowerName] = true
1899+
resolved[issue.Repo.Owner.LowerName+"/"+team.LowerName] = true
18871900
continue
18881901
}
18891902
has, err := ctx.e.Get(&TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype})
@@ -1892,7 +1905,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
18921905
}
18931906
if has {
18941907
checked = append(checked, team.ID)
1895-
resolved[team.LowerName] = true
1908+
resolved[issue.Repo.Owner.LowerName+"/"+team.LowerName] = true
18961909
}
18971910
}
18981911
if len(checked) != 0 {
@@ -1916,24 +1929,28 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
19161929
}
19171930
}
19181931
}
1932+
}
19191933

1920-
// Remove names already in the list to avoid querying the database if pending names remain
1921-
names = make([]string, 0, len(resolved))
1922-
for name, already := range resolved {
1923-
if !already {
1924-
names = append(names, name)
1925-
}
1926-
}
1927-
if len(names) == 0 {
1928-
return
1934+
// Remove names already in the list to avoid querying the database if pending names remain
1935+
mentionUsers := make([]string, 0, len(resolved))
1936+
for name, already := range resolved {
1937+
if !already {
1938+
mentionUsers = append(mentionUsers, name)
19291939
}
19301940
}
1941+
if len(mentionUsers) == 0 {
1942+
return
1943+
}
1944+
1945+
if users == nil {
1946+
users = make([]*User, 0, len(mentionUsers))
1947+
}
19311948

1932-
unchecked := make([]*User, 0, len(names))
1949+
unchecked := make([]*User, 0, len(mentionUsers))
19331950
if err := ctx.e.
19341951
Where("`user`.is_active = ?", true).
19351952
And("`user`.prohibit_login = ?", false).
1936-
In("`user`.lower_name", names).
1953+
In("`user`.lower_name", mentionUsers).
19371954
Find(&unchecked); err != nil {
19381955
return nil, fmt.Errorf("find mentioned users: %v", err)
19391956
}

models/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,5 @@ func TestIssue_ResolveMentions(t *testing.T) {
400400
// Private repo, not a team member
401401
testSuccess("user17", "big_test_private_4", "user20", []string{"user5"}, []int64{})
402402
// Private repo, whole team
403-
testSuccess("user17", "big_test_private_4", "user15", []string{"owners"}, []int64{18})
403+
testSuccess("user17", "big_test_private_4", "user15", []string{"user17/owners"}, []int64{18})
404404
}

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ func Contexter() macaron.Handler {
343343

344344
ctx.Data["EnableSwagger"] = setting.API.EnableSwagger
345345
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
346+
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
346347

347348
c.Map(ctx)
348349
}

modules/cron/tasks_basic.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/migrations"
1313
repository_service "code.gitea.io/gitea/modules/repository"
14+
"code.gitea.io/gitea/modules/setting"
1415
mirror_service "code.gitea.io/gitea/services/mirror"
1516
)
1617

@@ -115,5 +116,7 @@ func initBasicTasks() {
115116
registerArchiveCleanup()
116117
registerSyncExternalUsers()
117118
registerDeletedBranchesCleanup()
118-
registerUpdateMigrationPosterID()
119+
if !setting.Repository.DisableMigrations {
120+
registerUpdateMigrationPosterID()
121+
}
119122
}

modules/git/commit_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package git
66

77
import (
88
"path/filepath"
9+
"strings"
910
"testing"
1011

1112
"github.com/stretchr/testify/assert"
@@ -36,3 +37,71 @@ func TestGetFullCommitIDError(t *testing.T) {
3637
assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]")
3738
}
3839
}
40+
41+
func TestCommitFromReader(t *testing.T) {
42+
commitString := `feaf4ba6bc635fec442f46ddd4512416ec43c2c2 commit 1074
43+
tree f1a6cb52b2d16773290cefe49ad0684b50a4f930
44+
parent 37991dec2c8e592043f47155ce4808d4580f9123
45+
author silverwind <[email protected]> 1563741793 +0200
46+
committer silverwind <[email protected]> 1563741793 +0200
47+
gpgsig -----BEGIN PGP SIGNATURE-----
48+
` + " " + `
49+
iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG
50+
lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK
51+
xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld
52+
vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg
53+
R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6
54+
FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ
55+
/maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL
56+
S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm
57+
sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm
58+
1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb
59+
mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i
60+
1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs=
61+
=FRsO
62+
-----END PGP SIGNATURE-----
63+
64+
empty commit`
65+
66+
sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
67+
gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
68+
assert.NoError(t, err)
69+
assert.NotNil(t, gitRepo)
70+
71+
commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString))
72+
assert.NoError(t, err)
73+
if !assert.NotNil(t, commitFromReader) {
74+
return
75+
}
76+
assert.EqualValues(t, sha, commitFromReader.ID)
77+
assert.EqualValues(t, `-----BEGIN PGP SIGNATURE-----
78+
79+
iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG
80+
lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK
81+
xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld
82+
vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg
83+
R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6
84+
FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ
85+
/maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL
86+
S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm
87+
sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm
88+
1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb
89+
mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i
90+
1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs=
91+
=FRsO
92+
-----END PGP SIGNATURE-----
93+
`, commitFromReader.Signature.Signature)
94+
assert.EqualValues(t, `tree f1a6cb52b2d16773290cefe49ad0684b50a4f930
95+
parent 37991dec2c8e592043f47155ce4808d4580f9123
96+
author silverwind <[email protected]> 1563741793 +0200
97+
committer silverwind <[email protected]> 1563741793 +0200
98+
99+
empty commit`, commitFromReader.Signature.Payload)
100+
assert.EqualValues(t, "silverwind <[email protected]>", commitFromReader.Author.String())
101+
102+
commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n"))
103+
assert.NoError(t, err)
104+
commitFromReader.CommitMessage += "\n\n"
105+
commitFromReader.Signature.Payload += "\n\n"
106+
assert.EqualValues(t, commitFromReader, commitFromReader2)
107+
}

modules/markup/html.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,15 @@ func mentionProcessor(ctx *postProcessCtx, node *html.Node) {
596596
mention := node.Data[loc.Start:loc.End]
597597
var teams string
598598
teams, ok := ctx.metas["teams"]
599-
if ok && strings.Contains(teams, ","+strings.ToLower(mention[1:])+",") {
600-
replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, "org", ctx.metas["org"], "teams", mention[1:]), mention, "mention"))
601-
} else {
602-
replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, mention[1:]), mention, "mention"))
599+
// team mention should follow @orgName/teamName style
600+
if ok && strings.Contains(mention, "/") {
601+
mentionOrgAndTeam := strings.Split(mention, "/")
602+
if mentionOrgAndTeam[0][1:] == ctx.metas["org"] && strings.Contains(teams, ","+strings.ToLower(mentionOrgAndTeam[1])+",") {
603+
replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, "org", ctx.metas["org"], "teams", mentionOrgAndTeam[1]), mention, "mention"))
604+
}
605+
return
603606
}
607+
replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, mention[1:]), mention, "mention"))
604608
}
605609

606610
func shortLinkProcessor(ctx *postProcessCtx, node *html.Node) {

modules/references/references.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ var (
2626
// While fast, this is also incorrect and lead to false positives.
2727
// TODO: fix invalid linking issue
2828

29-
// mentionPattern matches all mentions in the form of "@user"
30-
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`)
29+
// mentionPattern matches all mentions in the form of "@user" or "@org/team"
30+
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_]+\/?[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+\/?[0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`)
3131
// issueNumericPattern matches string that references to a numeric issue, e.g. #1287
3232
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
3333
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234

modules/references/references_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ func TestRegExp_mentionPattern(t *testing.T) {
325325
{"@gitea.", "@gitea"},
326326
{"@gitea,", "@gitea"},
327327
{"@gitea;", "@gitea"},
328+
{"@gitea/team1;", "@gitea/team1"},
328329
}
329330
falseTestCases := []string{
330331
"@ 0",
@@ -340,6 +341,7 @@ func TestRegExp_mentionPattern(t *testing.T) {
340341
"@gitea?this",
341342
"@gitea,this",
342343
"@gitea;this",
344+
"@gitea/team1/more",
343345
}
344346

345347
for _, testCase := range trueTestCases {

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
DefaultRepoUnits []string
4343
PrefixArchiveFiles bool
4444
DisableMirrors bool
45+
DisableMigrations bool
4546
DefaultBranch string
4647
AllowAdoptionOfUnadoptedRepositories bool
4748
AllowDeleteOfUnadoptedRepositories bool
@@ -152,6 +153,7 @@ var (
152153
DefaultRepoUnits: []string{},
153154
PrefixArchiveFiles: true,
154155
DisableMirrors: false,
156+
DisableMigrations: false,
155157
DefaultBranch: "master",
156158

157159
// Repository editor settings

modules/setting/storage.go

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,10 @@ func (s *Storage) MapTo(v interface{}) error {
3131
return nil
3232
}
3333

34-
func getStorage(name, typ string, overrides ...*ini.Section) Storage {
34+
func getStorage(name, typ string, targetSec *ini.Section) Storage {
3535
const sectionName = "storage"
3636
sec := Cfg.Section(sectionName)
3737

38-
if len(overrides) == 0 {
39-
overrides = []*ini.Section{
40-
Cfg.Section(sectionName + "." + typ),
41-
Cfg.Section(sectionName + "." + name),
42-
}
43-
}
44-
45-
var storage Storage
46-
47-
storage.Type = sec.Key("STORAGE_TYPE").MustString(typ)
48-
storage.ServeDirect = sec.Key("SERVE_DIRECT").MustBool(false)
49-
5038
// Global Defaults
5139
sec.Key("MINIO_ENDPOINT").MustString("localhost:9000")
5240
sec.Key("MINIO_ACCESS_KEY_ID").MustString("")
@@ -55,18 +43,22 @@ func getStorage(name, typ string, overrides ...*ini.Section) Storage {
5543
sec.Key("MINIO_LOCATION").MustString("us-east-1")
5644
sec.Key("MINIO_USE_SSL").MustBool(false)
5745

58-
storage.Section = sec
59-
60-
for _, override := range overrides {
61-
for _, key := range storage.Section.Keys() {
62-
if !override.HasKey(key.Name()) {
63-
_, _ = override.NewKey(key.Name(), key.Value())
46+
nameSec := Cfg.Section(sectionName + "." + name)
47+
typeSec := Cfg.Section(sectionName + "." + typ)
48+
for _, override := range []*ini.Section{nameSec, typeSec, sec} {
49+
for _, key := range override.Keys() {
50+
if !targetSec.HasKey(key.Name()) {
51+
_, _ = targetSec.NewKey(key.Name(), key.Value())
6452
}
6553
}
66-
storage.ServeDirect = override.Key("SERVE_DIRECT").MustBool(false)
67-
storage.Section = override
6854
}
6955

56+
var storage Storage
57+
storage.Section = targetSec
58+
59+
storage.Type = typeSec.Key("STORAGE_TYPE").MustString(typ)
60+
storage.ServeDirect = storage.Section.Key("SERVE_DIRECT").MustBool(false)
61+
7062
// Specific defaults
7163
storage.Path = storage.Section.Key("PATH").MustString(filepath.Join(AppDataPath, name))
7264
if !filepath.IsAbs(storage.Path) {

0 commit comments

Comments
 (0)