mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-28 20:51:36 +00:00
Compare commits
103 Commits
v1.17.0-rc
...
v1.17.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32eef4aa2e | ||
|
|
449b39ea0e | ||
|
|
06f968d662 | ||
|
|
084797b4dc | ||
|
|
7888a55e8c | ||
|
|
ea416d7d0e | ||
|
|
0db6add5c0 | ||
|
|
0ecbb71bee | ||
|
|
ea38455e1f | ||
|
|
8fc80b34a0 | ||
|
|
71aa64ae25 | ||
|
|
3aba72c613 | ||
|
|
bd1412c3af | ||
|
|
3973ce36d9 | ||
|
|
fbde31fb1e | ||
|
|
2f0a1eb0d5 | ||
|
|
e3697efbb0 | ||
|
|
989dd5502c | ||
|
|
54c0fe62cc | ||
|
|
2e2133d33f | ||
|
|
0d869c574e | ||
|
|
04105dbb7c | ||
|
|
0a0cd75071 | ||
|
|
85f829fb3c | ||
|
|
5ebd26d306 | ||
|
|
bc7a4375be | ||
|
|
fbcb42488f | ||
|
|
0230f1e1aa | ||
|
|
6779c351b1 | ||
|
|
c1889f5b01 | ||
|
|
c0754e9d19 | ||
|
|
bf41958c16 | ||
|
|
033178f2fc | ||
|
|
ebc8801fb2 | ||
|
|
37458bffbf | ||
|
|
ec9b43ba16 | ||
|
|
e6ec411491 | ||
|
|
17d3a474e0 | ||
|
|
9e8b1c6630 | ||
|
|
eee51d8366 | ||
|
|
c61ed6fad4 | ||
|
|
b88a4b4854 | ||
|
|
399917a2d4 | ||
|
|
68cceb5321 | ||
|
|
15b61dac98 | ||
|
|
35ca651c80 | ||
|
|
737486152c | ||
|
|
c40c753613 | ||
|
|
7a9b01a2dd | ||
|
|
b43d7e1254 | ||
|
|
987798a3a9 | ||
|
|
13b74accda | ||
|
|
79fa1c15a4 | ||
|
|
78dabdd9ae | ||
|
|
e5d2031828 | ||
|
|
c3b4f3f7e9 | ||
|
|
9bccfe9856 | ||
|
|
85034564c2 | ||
|
|
eacab6b10d | ||
|
|
ac9792c0c7 | ||
|
|
f7c874cb1a | ||
|
|
d19c2c9fcb | ||
|
|
59228d8a71 | ||
|
|
67701771af | ||
|
|
113d13a026 | ||
|
|
9ec1c8812e | ||
|
|
e1e43333cf | ||
|
|
cedf4fef0a | ||
|
|
a04fc567b4 | ||
|
|
92d79b556b | ||
|
|
65176fdaf3 | ||
|
|
aac905dcfb | ||
|
|
5ce8fdbc37 | ||
|
|
76accb51ed | ||
|
|
bd2218e14c | ||
|
|
0747592865 | ||
|
|
07d140625e | ||
|
|
a6c2a1a117 | ||
|
|
56b99551ae | ||
|
|
51c8c0f3fe | ||
|
|
8769df117d | ||
|
|
09f2e1e1a2 | ||
|
|
eeb490c7ab | ||
|
|
97a8c96c5b | ||
|
|
d1e53bfd7f | ||
|
|
fc7b5afd9b | ||
|
|
210b096da7 | ||
|
|
d6bc1558c6 | ||
|
|
6986e56791 | ||
|
|
ae86a0bc9f | ||
|
|
4b53a5c3a1 | ||
|
|
da10ce8b07 | ||
|
|
4ed32e79b6 | ||
|
|
fa46d66835 | ||
|
|
648ec3cfed | ||
|
|
a9a440e600 | ||
|
|
39b2ede930 | ||
|
|
0a32bd56eb | ||
|
|
e0f35ea00f | ||
|
|
bed13bfa9e | ||
|
|
435038b2c6 | ||
|
|
2fe0dab2d5 | ||
|
|
e930d66a9c |
153
CHANGELOG.md
153
CHANGELOG.md
@@ -4,44 +4,90 @@ This changelog goes through all the changes that have been made in each release
|
||||
without substantial changes to our git log; to see the highlights of what has
|
||||
been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
|
||||
## [1.17.0-rc2](https://github.com/go-gitea/gitea/releases/tag/v1.17.0-rc2) - 2022-07-13
|
||||
## [1.17.2](https://github.com/go-gitea/gitea/releases/tag/v1.17.2) - 2022-09-06
|
||||
|
||||
* SECURITY
|
||||
* Use git.HOME_PATH for Git HOME directory (#20114) (#20293)
|
||||
* Add write check for creating Commit Statuses (#20332) (#20333)
|
||||
* Double check CloneURL is acceptable (#20869) (#20892)
|
||||
* Add more checks in migration code (#21011) (#21050)
|
||||
* ENHANCEMENTS
|
||||
* Make notification bell more prominent on mobile (#20108, #20236, #20251) (#20269)
|
||||
* Adjust max-widths for the repository file table (#20243) (#20247)
|
||||
* Display full name (#20171) (#20246)
|
||||
* Fix hard-coded timeout and error panic in API archive download endpoint (#20925) (#21051)
|
||||
* Improve arc-green code theme (#21039) (#21042)
|
||||
* Enable contenthash in filename for dynamic assets (#20813) (#20932)
|
||||
* Don't open new page for ext wiki on same repository (#20725) (#20910)
|
||||
* Disable doctor logging on panic (#20847) (#20898)
|
||||
* Remove calls to load Mirrors in user.Dashboard (#20855) (#20897)
|
||||
* Update codemirror to 5.65.8 (#20875)
|
||||
* Rework repo buttons (#20602, #20718) (#20719)
|
||||
* BUGFIXES
|
||||
* Allow RSA 2047 bit keys (#20272) (#20396)
|
||||
* Add missing return for when topic isn't found (#20351) (#20395)
|
||||
* Fix commit status icon when in subdirectory (#20285) (#20385)
|
||||
* Initialize cron last (#20373) (#20384)
|
||||
* Set target on create release with existing tag (#20381) (#20382)
|
||||
* Update xorm.io/xorm to fix a interpreting db column sizes issue on 32bit systems (#20371) (#20372)
|
||||
* Make sure `repo_dir` is an empty directory or doesn't exist before 'dump-repo' (#20205) (#20370)
|
||||
* Prevent context deadline error propagation in GetCommitsInfo (#20346) (#20361)
|
||||
* Correctly handle draft releases without a tag (#20314) (#20335)
|
||||
* Prevent "empty" scrollbars on Firefox (#20294) (#20308)
|
||||
* Refactor SSH init code, fix directory creation for TrustedUserCAKeys file (#20299) (#20306)
|
||||
* Bump goldmark to v1.4.13 (#20300) (#20301)
|
||||
* Do not create empty ".ssh" directory when loading config (#20289) (#20298)
|
||||
* Fix NPE when using non-numeric (#20277) (#20278)
|
||||
* Store read access in access for team repositories (#20275) (#20276)
|
||||
* EscapeFilter the group dn membership (#20200) (#20254)
|
||||
* Only show Followers that current user can access (#20220) (#20252)
|
||||
* Update Bluemonday to v1.0.19 (#20199) (#20209)
|
||||
* Refix indices on actions table (#20158) (#20198)
|
||||
* Check if project has the same repository id with issue when assign project to issue (#20133) (#20188)
|
||||
* Fix remove file on initial comment (#20127) (#20128)
|
||||
* Catch the error before the response is processed by goth (#20000) (#20102)
|
||||
* Dashboard feed respect setting.UI.FeedPagingNum again (#20094) (#20099)
|
||||
* Alter hook_task TEXT fields to LONGTEXT (#20038) (#20041)
|
||||
* Respond with a 401 on git push when password isn't changed yet (#20026) (#20027)
|
||||
* Return 404 when tag is broken (#20017) (#20024)
|
||||
* Ensure delete user deletes all comments (#21067) (#21068)
|
||||
* Delete unreferenced packages when deleting a package version (#20977) (#21060)
|
||||
* Redirect if user does not exist on admin pages (#20981) (#21059)
|
||||
* Set uploadpack.allowFilter etc on gitea serv to enable partial clones with ssh (#20902) (#21058)
|
||||
* Fix 500 on time in timeline API (#21052) (#21057)
|
||||
* Fill the specified ref in webhook test payload (#20961) (#21055)
|
||||
* Add another index for Action table on postgres (#21033) (#21054)
|
||||
* Fix broken insecureskipverify handling in redis connection uris (#20967) (#21053)
|
||||
* Add Dev, Peer and Optional dependencies to npm PackageMetadataVersion (#21017) (#21044)
|
||||
* Do not add links to Posters or Assignees with ID < 0 (#20577) (#21037)
|
||||
* Fix modified due date message (#20388) (#21032)
|
||||
* Fix missed sort bug (#21006)
|
||||
* Fix input.value attr for RequiredClaimName/Value (#20946) (#21001)
|
||||
* Change review buttons to icons to make space for text (#20934) (#20978)
|
||||
* Fix download archiver of a commit (#20962) (#20971)
|
||||
* Return 404 NotFound if requested attachment does not exist (#20886) (#20941)
|
||||
* Set no-tags in git fetch on compare (#20893) (#20936)
|
||||
* Allow multiple metadata files for Maven packages (#20674) (#20916)
|
||||
* Increase Content field size of gpg_key and public_key to MEDIUMTEXT (#20896) (#20911)
|
||||
* Fix mirror address setting not working (#20850) (#20904)
|
||||
* Fix push mirror address backend get error Address cause setting page display error (#20593) (#20901)
|
||||
* Fix panic when an invalid oauth2 name is passed (#20820) (#20900)
|
||||
* In PushMirrorsIterate and MirrorsIterate if limit is negative do not set it (#20837) (#20899)
|
||||
* Ensure that graceful start-up is informed of unused SSH listener (#20877) (#20888)
|
||||
* Pad GPG Key ID with preceding zeroes (#20878) (#20885)
|
||||
* Fix SQL Query for `SearchTeam` (#20844) (#20872)
|
||||
* Fix the mode of custom dir to 0700 in docker-rootless (#20861) (#20867)
|
||||
* Fix UI mis-align for PR commit history (#20845) (#20859)
|
||||
|
||||
## [1.17.0-rc1](https://github.com/go-gitea/gitea/releases/tag/v1.17.0-rc1) - 2022-06-18
|
||||
## [1.17.1](https://github.com/go-gitea/gitea/releases/tag/1.17.1) - 2022-08-17
|
||||
|
||||
* SECURITY
|
||||
* Correctly escape within tribute.js (#20831) (#20832)
|
||||
* ENHANCEMENTS
|
||||
* Add support for NuGet API keys (#20721) (#20734)
|
||||
* Display project in issue list (#20583)
|
||||
* Add disable download source configuration (#20548) (#20579)
|
||||
* Add username check to doctor (#20140) (#20671)
|
||||
* Enable Wire 2 for Internal SSH Server (#20616) (#20617)
|
||||
* BUGFIXES
|
||||
* Use the total issue count for UI (#20785) (#20827)
|
||||
* Add proxy host into allow list (#20798) (#20819)
|
||||
* Add missing translation for queue flush workers (#20791) (#20792)
|
||||
* Improve comment header for mobile (#20781) (#20789)
|
||||
* Fix git.Init for doctor sub-command (#20782) (#20783)
|
||||
* Check webhooks slice length before calling xorm (#20642) (#20768)
|
||||
* Remove manual rollback for failed generated repositories (#20639) (#20762)
|
||||
* Use correct field name in npm template (#20675) (#20760)
|
||||
* Keep download count on Container tag overwrite (#20728) (#20735)
|
||||
* Fix v220 migration to be compatible for MSSQL 2008 r2 (#20702) (#20707)
|
||||
* Use request timeout for git service rpc (#20689) (#20693)
|
||||
* Send correct NuGet status codes (#20647) (#20677)
|
||||
* Use correct context to get package content (#20673) (#20676)
|
||||
* Fix the JS error "EventSource is not defined" caused by some non-standard browsers (#20584) (#20663)
|
||||
* Add default commit messages to PR for squash merge (#20618) (#20645)
|
||||
* Fix package upload for files >32mb (#20622) (#20635)
|
||||
* Fix the new-line copy-paste for rendered code (#20612)
|
||||
* Clean up and fix clone button script (#20415 & #20600) (#20599)
|
||||
* Fix default merge style (#20564) (#20565)
|
||||
* Add repository condition for issue count (#20454) (#20496)
|
||||
* Make branch icon stand out more (#20726) (#20774)
|
||||
* Fix loading button with invalid form (#20754) (#20759)
|
||||
* Fix SecToTime edge-cases (#20610) (#20611)
|
||||
* Executable check always returns true for windows (#20637) (#20835)
|
||||
* Check issue labels slice length before calling xorm Insert (#20655) (#20836)
|
||||
* Fix owners cannot create organization repos bug (#20841) (#20854)
|
||||
* Prevent 500 is head repo does not have PullRequest unit in IsUserAllowedToUpdate (#20839) (#20848)
|
||||
|
||||
## [1.17.0](https://github.com/go-gitea/gitea/releases/tag/v1.17.0) - 2022-07-30
|
||||
|
||||
* BREAKING
|
||||
* Require go1.18 for Gitea 1.17 (#19918)
|
||||
@@ -66,6 +112,8 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Restrict email address validation (#17688)
|
||||
* Refactor Router Logger (#17308)
|
||||
* SECURITY
|
||||
* Use git.HOME_PATH for Git HOME directory (#20114) (#20293)
|
||||
* Add write check for creating Commit Statuses (#20332) (#20333)
|
||||
* Remove deprecated SSH ciphers from default (#18697)
|
||||
* FEDERATION
|
||||
* Return statistic information for nodeinfo (#19561)
|
||||
@@ -104,6 +152,9 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Return primary language and repository language stats API URL (#18396)
|
||||
* Implement http signatures support for the API (#17565)
|
||||
* ENHANCEMENTS
|
||||
* Make notification bell more prominent on mobile (#20108, #20236, #20251) (#20269)
|
||||
* Adjust max-widths for the repository file table (#20243) (#20247)
|
||||
* Display full name (#20171) (#20246)
|
||||
* Add dbconsistency checks for Stopwatches (#20010)
|
||||
* Add fetch.writeCommitGraph to gitconfig (#20006)
|
||||
* Add fgprof pprof profiler (#20005)
|
||||
@@ -148,7 +199,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* PullService lock via pullID (#19520)
|
||||
* Make repository file list useable on mobile (#19515)
|
||||
* more context for models (#19511)
|
||||
* Allow package dump skipping (#19506)
|
||||
* Refactor readme file renderer (#19502)
|
||||
* By default force vertical tabs on mobile (#19486)
|
||||
* Github style following followers (#19482)
|
||||
@@ -165,7 +215,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Move access and repo permission to models/perm/access (#19350)
|
||||
* Disallow selecting the text of buttons (#19330)
|
||||
* Allow custom redirect for landing page (#19324)
|
||||
* Repository level enable package or disable (#19323)
|
||||
* Remove dependent on session auth for api/v1 routers (#19321)
|
||||
* Never use /api/v1 from Gitea UI Pages (#19318)
|
||||
* Remove legacy unmaintained packages, refactor to support change default locale (#19308)
|
||||
@@ -222,13 +271,44 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Allow custom default merge message with .gitea/default_merge_message/<merge_style>_TEMPLATE.md (#18177)
|
||||
* Prettify number of issues (#17760)
|
||||
* Add a "admin user generate-access-token" subcommand (#17722)
|
||||
* Move project files into models/project sub package (#17704)
|
||||
* Custom regexp external issues (#17624)
|
||||
* Add smtp password to install page (#17564)
|
||||
* Add config options to hide issue events (#17414)
|
||||
* Prevent double click new issue/pull/comment button (#16157)
|
||||
* Show issue assignee on project board (#15232)
|
||||
* BUGFIXES
|
||||
* WebAuthn CredentialID field needs to be increased in size (#20530) (#20555)
|
||||
* Ensure that all unmerged files are merged when conflict checking (#20528) (#20536)
|
||||
* Stop logging EOFs and exit(1)s in ssh handler (#20476) (#20529)
|
||||
* Add labels to two buttons that were missing them (#20419) (#20524)
|
||||
* Fix ROOT_URL detection for URLs without trailing slash (#20502) (#20503)
|
||||
* Dismiss prior pull reviews if done via web in review dismiss (#20197) (#20407)
|
||||
* Allow RSA 2047 bit keys (#20272) (#20396)
|
||||
* Add missing return for when topic isn't found (#20351) (#20395)
|
||||
* Fix commit status icon when in subdirectory (#20285) (#20385)
|
||||
* Initialize cron last (#20373) (#20384)
|
||||
* Set target on create release with existing tag (#20381) (#20382)
|
||||
* Update xorm.io/xorm to fix a interpreting db column sizes issue on 32bit systems (#20371) (#20372)
|
||||
* Make sure `repo_dir` is an empty directory or doesn't exist before 'dump-repo' (#20205) (#20370)
|
||||
* Prevent context deadline error propagation in GetCommitsInfo (#20346) (#20361)
|
||||
* Correctly handle draft releases without a tag (#20314) (#20335)
|
||||
* Prevent "empty" scrollbars on Firefox (#20294) (#20308)
|
||||
* Refactor SSH init code, fix directory creation for TrustedUserCAKeys file (#20299) (#20306)
|
||||
* Bump goldmark to v1.4.13 (#20300) (#20301)
|
||||
* Do not create empty ".ssh" directory when loading config (#20289) (#20298)
|
||||
* Fix NPE when using non-numeric (#20277) (#20278)
|
||||
* Store read access in access for team repositories (#20275) (#20276)
|
||||
* EscapeFilter the group dn membership (#20200) (#20254)
|
||||
* Only show Followers that current user can access (#20220) (#20252)
|
||||
* Update Bluemonday to v1.0.19 (#20199) (#20209)
|
||||
* Refix indices on actions table (#20158) (#20198)
|
||||
* Check if project has the same repository id with issue when assign project to issue (#20133) (#20188)
|
||||
* Fix remove file on initial comment (#20127) (#20128)
|
||||
* Catch the error before the response is processed by goth (#20000) (#20102)
|
||||
* Dashboard feed respect setting.UI.FeedPagingNum again (#20094) (#20099)
|
||||
* Alter hook_task TEXT fields to LONGTEXT (#20038) (#20041)
|
||||
* Respond with a 401 on git push when password isn't changed yet (#20026) (#20027)
|
||||
* Return 404 when tag is broken (#20017) (#20024)
|
||||
* Alter hook_task TEXT fields to LONGTEXT (#20038) (#20041)
|
||||
* Respond with a 401 on git push when password isn't changed yet (#20026) (#20027)
|
||||
* Return 404 when tag is broken (#20017) (#20024)
|
||||
@@ -303,7 +383,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* MISC
|
||||
* Fix aria for logo (#19955)
|
||||
* In code search, get code unit accessible repos in one (main) query (#19764)
|
||||
* Enable packages by default again (#19746)
|
||||
* Add tooltip to pending PR comments (#19662)
|
||||
* Improve sync performance for pull-mirrors (#19125)
|
||||
* Improve dashboard's repo list performance (#18963)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
golog "log"
|
||||
"os"
|
||||
@@ -123,6 +124,47 @@ func runRecreateTable(ctx *cli.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func setDoctorLogger(ctx *cli.Context) {
|
||||
logFile := ctx.String("log-file")
|
||||
if !ctx.IsSet("log-file") {
|
||||
logFile = "doctor.log"
|
||||
}
|
||||
colorize := log.CanColorStdout
|
||||
if ctx.IsSet("color") {
|
||||
colorize = ctx.Bool("color")
|
||||
}
|
||||
|
||||
if len(logFile) == 0 {
|
||||
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"NONE","stacktracelevel":"NONE","colorize":%t}`, colorize))
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
recovered := recover()
|
||||
if recovered == nil {
|
||||
return
|
||||
}
|
||||
|
||||
err, ok := recovered.(error)
|
||||
if !ok {
|
||||
panic(recovered)
|
||||
}
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: Unable to write logs to provided file due to permissions error: %s\n %v\n", logFile, err)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: Unable to write logs to provided file: %s\n %v\n", logFile, err)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "WARN: Logging will be disabled\n Use `--log-file` to configure log file location\n")
|
||||
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"NONE","stacktracelevel":"NONE","colorize":%t}`, colorize))
|
||||
}()
|
||||
|
||||
if logFile == "-" {
|
||||
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"trace","stacktracelevel":"NONE","colorize":%t}`, colorize))
|
||||
} else {
|
||||
log.NewLogger(1000, "doctor", "file", fmt.Sprintf(`{"filename":%q,"level":"trace","stacktracelevel":"NONE"}`, logFile))
|
||||
}
|
||||
}
|
||||
|
||||
func runDoctor(ctx *cli.Context) error {
|
||||
// Silence the default loggers
|
||||
log.DelNamedLogger("console")
|
||||
@@ -132,24 +174,13 @@ func runDoctor(ctx *cli.Context) error {
|
||||
defer cancel()
|
||||
|
||||
// Now setup our own
|
||||
logFile := ctx.String("log-file")
|
||||
if !ctx.IsSet("log-file") {
|
||||
logFile = "doctor.log"
|
||||
}
|
||||
setDoctorLogger(ctx)
|
||||
|
||||
colorize := log.CanColorStdout
|
||||
if ctx.IsSet("color") {
|
||||
colorize = ctx.Bool("color")
|
||||
}
|
||||
|
||||
if len(logFile) == 0 {
|
||||
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"NONE","stacktracelevel":"NONE","colorize":%t}`, colorize))
|
||||
} else if logFile == "-" {
|
||||
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"trace","stacktracelevel":"NONE","colorize":%t}`, colorize))
|
||||
} else {
|
||||
log.NewLogger(1000, "doctor", "file", fmt.Sprintf(`{"filename":%q,"level":"trace","stacktracelevel":"NONE"}`, logFile))
|
||||
}
|
||||
|
||||
// Finally redirect the default golog to here
|
||||
golog.SetFlags(0)
|
||||
golog.SetPrefix("")
|
||||
|
||||
23
cmd/main_test.go
Normal file
23
cmd/main_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
func init() {
|
||||
setting.SetCustomPathAndConf("", "", "")
|
||||
setting.LoadForTest()
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: "..",
|
||||
})
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
"code.gitea.io/gitea/models/migrations"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
|
||||
@@ -25,13 +27,13 @@ import (
|
||||
var CmdMigrateStorage = cli.Command{
|
||||
Name: "migrate-storage",
|
||||
Usage: "Migrate the storage",
|
||||
Description: "This is a command for migrating storage.",
|
||||
Description: "Copies stored files from storage configured in app.ini to parameter-configured storage",
|
||||
Action: runMigrateStorage,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "type, t",
|
||||
Value: "",
|
||||
Usage: "Kinds of files to migrate, currently only 'attachments' is supported",
|
||||
Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "storage, s",
|
||||
@@ -80,34 +82,50 @@ var CmdMigrateStorage = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func migrateAttachments(dstStorage storage.ObjectStorage) error {
|
||||
return repo_model.IterateAttachment(func(attach *repo_model.Attachment) error {
|
||||
func migrateAttachments(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(attach *repo_model.Attachment) error {
|
||||
_, err := storage.Copy(dstStorage, attach.RelativePath(), storage.Attachments, attach.RelativePath())
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func migrateLFS(dstStorage storage.ObjectStorage) error {
|
||||
return git_model.IterateLFS(func(mo *git_model.LFSMetaObject) error {
|
||||
func migrateLFS(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(mo *git_model.LFSMetaObject) error {
|
||||
_, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath())
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func migrateAvatars(dstStorage storage.ObjectStorage) error {
|
||||
return user_model.IterateUser(func(user *user_model.User) error {
|
||||
func migrateAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(user *user_model.User) error {
|
||||
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func migrateRepoAvatars(dstStorage storage.ObjectStorage) error {
|
||||
return repo_model.IterateRepository(func(repo *repo_model.Repository) error {
|
||||
func migrateRepoAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(repo *repo_model.Repository) error {
|
||||
_, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath())
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func migrateRepoArchivers(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(archiver *repo_model.RepoArchiver) error {
|
||||
p := archiver.RelativePath()
|
||||
_, err := storage.Copy(dstStorage, p, storage.RepoArchives, p)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func migratePackages(ctx context.Context, dstStorage storage.ObjectStorage) error {
|
||||
return db.IterateObjects(ctx, func(pb *packages_model.PackageBlob) error {
|
||||
p := packages_module.KeyToRelativePath(packages_module.BlobHash256Key(pb.HashSHA256))
|
||||
_, err := storage.Copy(dstStorage, p, storage.Packages, p)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func runMigrateStorage(ctx *cli.Context) error {
|
||||
stdCtx, cancel := installSignals()
|
||||
defer cancel()
|
||||
@@ -127,8 +145,6 @@ func runMigrateStorage(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
goCtx := context.Background()
|
||||
|
||||
if err := storage.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -145,13 +161,13 @@ func runMigrateStorage(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
dstStorage, err = storage.NewLocalStorage(
|
||||
goCtx,
|
||||
stdCtx,
|
||||
storage.LocalStorageConfig{
|
||||
Path: p,
|
||||
})
|
||||
case string(storage.MinioStorageType):
|
||||
dstStorage, err = storage.NewMinioStorage(
|
||||
goCtx,
|
||||
stdCtx,
|
||||
storage.MinioStorageConfig{
|
||||
Endpoint: ctx.String("minio-endpoint"),
|
||||
AccessKeyID: ctx.String("minio-access-key-id"),
|
||||
@@ -162,35 +178,29 @@ func runMigrateStorage(ctx *cli.Context) error {
|
||||
UseSSL: ctx.Bool("minio-use-ssl"),
|
||||
})
|
||||
default:
|
||||
return fmt.Errorf("Unsupported storage type: %s", ctx.String("storage"))
|
||||
return fmt.Errorf("unsupported storage type: %s", ctx.String("storage"))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tp := strings.ToLower(ctx.String("type"))
|
||||
switch tp {
|
||||
case "attachments":
|
||||
if err := migrateAttachments(dstStorage); err != nil {
|
||||
return err
|
||||
}
|
||||
case "lfs":
|
||||
if err := migrateLFS(dstStorage); err != nil {
|
||||
return err
|
||||
}
|
||||
case "avatars":
|
||||
if err := migrateAvatars(dstStorage); err != nil {
|
||||
return err
|
||||
}
|
||||
case "repo-avatars":
|
||||
if err := migrateRepoAvatars(dstStorage); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Unsupported storage: %s", ctx.String("type"))
|
||||
migratedMethods := map[string]func(context.Context, storage.ObjectStorage) error{
|
||||
"attachments": migrateAttachments,
|
||||
"lfs": migrateLFS,
|
||||
"avatars": migrateAvatars,
|
||||
"repo-avatars": migrateRepoAvatars,
|
||||
"repo-archivers": migrateRepoArchivers,
|
||||
"packages": migratePackages,
|
||||
}
|
||||
|
||||
log.Warn("All files have been copied to the new placement but old files are still on the original placement.")
|
||||
tp := strings.ToLower(ctx.String("type"))
|
||||
if m, ok := migratedMethods[tp]; ok {
|
||||
if err := m(stdCtx, dstStorage); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("%s files have successfully been copied to the new storage.", tp)
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
return fmt.Errorf("unsupported storage: %s", ctx.String("type"))
|
||||
}
|
||||
|
||||
74
cmd/migrate_storage_test.go
Normal file
74
cmd/migrate_storage_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
packages_service "code.gitea.io/gitea/services/packages"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMigratePackages(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
creator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||
|
||||
content := "package main\n\nfunc main() {\nfmt.Println(\"hi\")\n}\n"
|
||||
buf, err := packages_module.CreateHashedBufferFromReader(strings.NewReader(content), 1024)
|
||||
assert.NoError(t, err)
|
||||
defer buf.Close()
|
||||
|
||||
v, f, err := packages_service.CreatePackageAndAddFile(&packages_service.PackageCreationInfo{
|
||||
PackageInfo: packages_service.PackageInfo{
|
||||
Owner: creator,
|
||||
PackageType: packages.TypeGeneric,
|
||||
Name: "test",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
Creator: creator,
|
||||
SemverCompatible: true,
|
||||
VersionProperties: map[string]string{},
|
||||
}, &packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: "a.go",
|
||||
},
|
||||
Data: buf,
|
||||
IsLead: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, v)
|
||||
assert.NotNil(t, f)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
p, err := os.MkdirTemp(os.TempDir(), "migrated_packages")
|
||||
assert.NoError(t, err)
|
||||
|
||||
dstStorage, err := storage.NewLocalStorage(
|
||||
ctx,
|
||||
storage.LocalStorageConfig{
|
||||
Path: p,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = migratePackages(ctx, dstStorage)
|
||||
assert.NoError(t, err)
|
||||
|
||||
entries, err := os.ReadDir(p)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, len(entries))
|
||||
assert.EqualValues(t, "01", entries[0].Name())
|
||||
assert.EqualValues(t, "tmp", entries[1].Name())
|
||||
}
|
||||
@@ -892,6 +892,9 @@ ROUTER = console
|
||||
;; Allow deletion of unadopted repositories
|
||||
;ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES = false
|
||||
|
||||
;; Don't allow download source archive files from UI
|
||||
;DISABLE_DOWNLOAD_SOURCE_ARCHIVES = false
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;[repository.editor]
|
||||
|
||||
@@ -5,7 +5,7 @@ mkdir -p ${HOME} && chmod 0700 ${HOME}
|
||||
if [ ! -w ${HOME} ]; then echo "${HOME} is not writable"; exit 1; fi
|
||||
|
||||
# Prepare custom folder
|
||||
mkdir -p ${GITEA_CUSTOM} && chmod 0500 ${GITEA_CUSTOM}
|
||||
mkdir -p ${GITEA_CUSTOM} && chmod 0700 ${GITEA_CUSTOM}
|
||||
|
||||
# Prepare temp folder
|
||||
mkdir -p ${GITEA_TEMP} && chmod 0700 ${GITEA_TEMP}
|
||||
|
||||
@@ -78,6 +78,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||
- `DEFAULT_BRANCH`: **main**: Default branch name of all repositories.
|
||||
- `ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to adopt unadopted repositories
|
||||
- `ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to delete unadopted repositories
|
||||
- `DISABLE_DOWNLOAD_SOURCE_ARCHIVES`: **false**: Don't allow download source archive files from UI
|
||||
|
||||
### Repository - Editor (`repository.editor`)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ PUT https://gitea.example.com/api/packages/{owner}/generic/{package_name}/{packa
|
||||
| ----------------- | ----------- |
|
||||
| `owner` | The owner of the package. |
|
||||
| `package_name` | The package name. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`). |
|
||||
| `package_version` | The package version as described in the [SemVer](https://semver.org/) spec. |
|
||||
| `package_version` | The package version, a non-empty string. |
|
||||
| `file_name` | The filename. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`). |
|
||||
|
||||
Example request using HTTP Basic authentication:
|
||||
|
||||
@@ -47,6 +47,8 @@ For example:
|
||||
dotnet nuget add source --name gitea --username testuser --password password123 https://gitea.example.com/api/packages/testuser/nuget/index.json
|
||||
```
|
||||
|
||||
You can add the source without credentials and use the [`--api-key`](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push) parameter when publishing packages. In this case you need to provide a [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}).
|
||||
|
||||
## Publish a package
|
||||
|
||||
Publish a package by running the following command:
|
||||
|
||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
gitea.com/go-chi/cache v0.2.0
|
||||
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5
|
||||
gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8
|
||||
gitea.com/lunny/levelqueue v0.4.1
|
||||
gitea.com/lunny/levelqueue v0.4.2-0.20220729054728-f020868cc2f7
|
||||
github.com/42wim/sshsig v0.0.0-20211121163825-841cf5bbc121
|
||||
github.com/NYTimes/gziphandler v1.1.1
|
||||
github.com/PuerkitoBio/goquery v1.8.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -78,8 +78,8 @@ gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5 h1:J/1i8u40TbcLP/w2w
|
||||
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5/go.mod h1:hQ9SYHKdOX968wJglb/NMQ+UqpOKwW4L+EYdvkWjHSo=
|
||||
gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8 h1:tJQRXgZigkLeeW9LPlps9G9aMoE6LAmqigLA+wxmd1Q=
|
||||
gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8/go.mod h1:fc/pjt5EqNKgqQXYzcas1Z5L5whkZHyOvTA7OzWVJck=
|
||||
gitea.com/lunny/levelqueue v0.4.1 h1:RZ+AFx5gBsZuyqCvofhAkPQ9uaVDPJnsULoJZIYaJNw=
|
||||
gitea.com/lunny/levelqueue v0.4.1/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
|
||||
gitea.com/lunny/levelqueue v0.4.2-0.20220729054728-f020868cc2f7 h1:Zc3RQWC2xOVglLciQH/ZIC5IqSk3Jn96LflGQLv18Rg=
|
||||
gitea.com/lunny/levelqueue v0.4.2-0.20220729054728-f020868cc2f7/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
|
||||
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
func TestPackageContainer(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
|
||||
has := func(l packages_model.PackagePropertyList, name string) bool {
|
||||
@@ -36,6 +37,15 @@ func TestPackageContainer(t *testing.T) {
|
||||
}
|
||||
return false
|
||||
}
|
||||
getAllByName := func(l packages_model.PackagePropertyList, name string) []string {
|
||||
values := make([]string, 0, len(l))
|
||||
for _, pp := range l {
|
||||
if pp.Name == name {
|
||||
values = append(values, pp.Value)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
images := []string{"test", "te/st"}
|
||||
tags := []string{"latest", "main"}
|
||||
@@ -66,7 +76,7 @@ func TestPackageContainer(t *testing.T) {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
authenticate := []string{`Bearer realm="` + setting.AppURL + `v2/token"`}
|
||||
authenticate := []string{`Bearer realm="` + setting.AppURL + `v2/token",service="container_registry",scope="*"`}
|
||||
|
||||
t.Run("Anonymous", func(t *testing.T) {
|
||||
defer PrintCurrentTest(t)()
|
||||
@@ -236,7 +246,8 @@ func TestPackageContainer(t *testing.T) {
|
||||
assert.Nil(t, pd.SemVer)
|
||||
assert.Equal(t, image, pd.Package.Name)
|
||||
assert.Equal(t, tag, pd.Version.Version)
|
||||
assert.True(t, has(pd.Properties, container_module.PropertyManifestTagged))
|
||||
assert.ElementsMatch(t, []string{strings.ToLower(user.LowerName + "/" + image)}, getAllByName(pd.PackageProperties, container_module.PropertyRepository))
|
||||
assert.True(t, has(pd.VersionProperties, container_module.PropertyManifestTagged))
|
||||
|
||||
assert.IsType(t, &container_module.Metadata{}, pd.Metadata)
|
||||
metadata := pd.Metadata.(*container_module.Metadata)
|
||||
@@ -264,11 +275,23 @@ func TestPackageContainer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite existing tag
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/manifests/%s", url, tag))
|
||||
addTokenAuthHeader(req, userToken)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
pv, err = packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, tag)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, pv.DownloadCount)
|
||||
|
||||
// Overwrite existing tag should keep the download count
|
||||
req = NewRequestWithBody(t, "PUT", fmt.Sprintf("%s/manifests/%s", url, tag), strings.NewReader(manifestContent))
|
||||
addTokenAuthHeader(req, userToken)
|
||||
req.Header.Set("Content-Type", oci.MediaTypeDockerManifest)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
pv, err = packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, tag)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, pv.DownloadCount)
|
||||
})
|
||||
|
||||
t.Run("HeadManifest", func(t *testing.T) {
|
||||
@@ -330,7 +353,8 @@ func TestPackageContainer(t *testing.T) {
|
||||
assert.Nil(t, pd.SemVer)
|
||||
assert.Equal(t, image, pd.Package.Name)
|
||||
assert.Equal(t, untaggedManifestDigest, pd.Version.Version)
|
||||
assert.False(t, has(pd.Properties, container_module.PropertyManifestTagged))
|
||||
assert.ElementsMatch(t, []string{strings.ToLower(user.LowerName + "/" + image)}, getAllByName(pd.PackageProperties, container_module.PropertyRepository))
|
||||
assert.False(t, has(pd.VersionProperties, container_module.PropertyManifestTagged))
|
||||
|
||||
assert.IsType(t, &container_module.Metadata{}, pd.Metadata)
|
||||
|
||||
@@ -362,18 +386,10 @@ func TestPackageContainer(t *testing.T) {
|
||||
assert.Nil(t, pd.SemVer)
|
||||
assert.Equal(t, image, pd.Package.Name)
|
||||
assert.Equal(t, multiTag, pd.Version.Version)
|
||||
assert.True(t, has(pd.Properties, container_module.PropertyManifestTagged))
|
||||
assert.ElementsMatch(t, []string{strings.ToLower(user.LowerName + "/" + image)}, getAllByName(pd.PackageProperties, container_module.PropertyRepository))
|
||||
assert.True(t, has(pd.VersionProperties, container_module.PropertyManifestTagged))
|
||||
|
||||
getAllByName := func(l packages_model.PackagePropertyList, name string) []string {
|
||||
values := make([]string, 0, len(l))
|
||||
for _, pp := range l {
|
||||
if pp.Name == name {
|
||||
values = append(values, pp.Value)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
assert.ElementsMatch(t, []string{manifestDigest, untaggedManifestDigest}, getAllByName(pd.Properties, container_module.PropertyManifestReference))
|
||||
assert.ElementsMatch(t, []string{manifestDigest, untaggedManifestDigest}, getAllByName(pd.VersionProperties, container_module.PropertyManifestReference))
|
||||
|
||||
assert.IsType(t, &container_module.Metadata{}, pd.Metadata)
|
||||
metadata := pd.Metadata.(*container_module.Metadata)
|
||||
@@ -528,4 +544,56 @@ func TestPackageContainer(t *testing.T) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("OwnerNameChange", func(t *testing.T) {
|
||||
defer PrintCurrentTest(t)()
|
||||
|
||||
checkCatalog := func(owner string) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
defer PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%sv2/_catalog", setting.AppURL))
|
||||
addTokenAuthHeader(req, userToken)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
type RepositoryList struct {
|
||||
Repositories []string `json:"repositories"`
|
||||
}
|
||||
|
||||
repoList := &RepositoryList{}
|
||||
DecodeJSON(t, resp, &repoList)
|
||||
|
||||
assert.Len(t, repoList.Repositories, len(images))
|
||||
names := make([]string, 0, len(images))
|
||||
for _, image := range images {
|
||||
names = append(names, strings.ToLower(owner+"/"+image))
|
||||
}
|
||||
assert.ElementsMatch(t, names, repoList.Repositories)
|
||||
}
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("Catalog[%s]", user.LowerName), checkCatalog(user.LowerName))
|
||||
|
||||
session := loginUser(t, user.Name)
|
||||
|
||||
newOwnerName := "newUsername"
|
||||
|
||||
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||
"name": newOwnerName,
|
||||
"email": "user2@example.com",
|
||||
"language": "en-US",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
t.Run(fmt.Sprintf("Catalog[%s]", newOwnerName), checkCatalog(newOwnerName))
|
||||
|
||||
req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||
"name": user.Name,
|
||||
"email": "user2@example.com",
|
||||
"language": "en-US",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ func TestPackageGeneric(t *testing.T) {
|
||||
|
||||
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, pd.SemVer)
|
||||
assert.Nil(t, pd.Metadata)
|
||||
assert.Equal(t, packageName, pd.Package.Name)
|
||||
assert.Equal(t, packageVersion, pd.Version.Version)
|
||||
|
||||
@@ -42,6 +42,7 @@ func TestPackageMaven(t *testing.T) {
|
||||
defer PrintCurrentTest(t)()
|
||||
|
||||
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusCreated)
|
||||
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusBadRequest)
|
||||
putFile(t, "/maven-metadata.xml", "test", http.StatusOK)
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
|
||||
@@ -135,12 +136,14 @@ func TestPackageMaven(t *testing.T) {
|
||||
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pfs, 2)
|
||||
i := 0
|
||||
if strings.HasSuffix(pfs[1].Name, ".pom") {
|
||||
i = 1
|
||||
for _, pf := range pfs {
|
||||
if strings.HasSuffix(pf.Name, ".pom") {
|
||||
assert.Equal(t, filename+".pom", pf.Name)
|
||||
assert.True(t, pf.IsLead)
|
||||
} else {
|
||||
assert.False(t, pf.IsLead)
|
||||
}
|
||||
}
|
||||
assert.Equal(t, filename+".pom", pfs[i].Name)
|
||||
assert.True(t, pfs[i].IsLead)
|
||||
})
|
||||
|
||||
t.Run("DownloadPOM", func(t *testing.T) {
|
||||
@@ -202,4 +205,13 @@ func TestPackageMaven(t *testing.T) {
|
||||
assert.Equal(t, checksum, resp.Body.String())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("UploadSnapshot", func(t *testing.T) {
|
||||
snapshotVersion := packageVersion + "-SNAPSHOT"
|
||||
|
||||
putFile(t, fmt.Sprintf("/%s/%s", snapshotVersion, filename), "test", http.StatusCreated)
|
||||
putFile(t, "/maven-metadata.xml", "test", http.StatusOK)
|
||||
putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test", http.StatusCreated)
|
||||
putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test-overwrite", http.StatusCreated)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ func TestPackageNpm(t *testing.T) {
|
||||
assert.IsType(t, &npm.Metadata{}, pd.Metadata)
|
||||
assert.Equal(t, packageName, pd.Package.Name)
|
||||
assert.Equal(t, packageVersion, pd.Version.Version)
|
||||
assert.Len(t, pd.Properties, 1)
|
||||
assert.Equal(t, npm.TagProperty, pd.Properties[0].Name)
|
||||
assert.Equal(t, packageTag, pd.Properties[0].Value)
|
||||
assert.Len(t, pd.VersionProperties, 1)
|
||||
assert.Equal(t, npm.TagProperty, pd.VersionProperties[0].Name)
|
||||
assert.Equal(t, packageTag, pd.VersionProperties[0].Value)
|
||||
|
||||
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -24,9 +24,16 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func addNuGetAPIKeyHeader(request *http.Request, token string) *http.Request {
|
||||
request.Header.Set("X-NuGet-ApiKey", token)
|
||||
return request
|
||||
}
|
||||
|
||||
func TestPackageNuGet(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
token := getUserToken(t, user.Name)
|
||||
|
||||
packageName := "test.package"
|
||||
packageVersion := "1.0.3"
|
||||
@@ -60,6 +67,10 @@ func TestPackageNuGet(t *testing.T) {
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/index.json", url))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/index.json", url))
|
||||
req = addNuGetAPIKeyHeader(req, token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var result nuget.ServiceIndexResponse
|
||||
@@ -122,7 +133,7 @@ func TestPackageNuGet(t *testing.T) {
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
MakeRequest(t, req, http.StatusConflict)
|
||||
})
|
||||
|
||||
t.Run("SymbolPackage", func(t *testing.T) {
|
||||
@@ -208,7 +219,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", fmt.Sprintf("%s/symbolpackage", url), createPackage(packageName, "SymbolsPackage"))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
MakeRequest(t, req, http.StatusConflict)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -352,7 +363,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
|
||||
req := NewRequest(t, "DELETE", fmt.Sprintf("%s/%s/%s", url, packageName, packageVersion))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -223,7 +223,7 @@ func TestAPITeamSearch(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}).(*user_model.User)
|
||||
|
||||
var results TeamSearchResults
|
||||
|
||||
|
||||
@@ -26,8 +26,19 @@ func TestUserOrgs(t *testing.T) {
|
||||
orgs := getUserOrgs(t, adminUsername, normalUsername)
|
||||
|
||||
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}).(*user_model.User)
|
||||
user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}).(*user_model.User)
|
||||
|
||||
assert.Equal(t, []*api.Organization{
|
||||
{
|
||||
ID: 17,
|
||||
UserName: user17.Name,
|
||||
FullName: user17.FullName,
|
||||
AvatarURL: user17.AvatarLink(),
|
||||
Description: "",
|
||||
Website: "",
|
||||
Location: "",
|
||||
Visibility: "public",
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
UserName: user3.Name,
|
||||
@@ -82,8 +93,19 @@ func TestMyOrgs(t *testing.T) {
|
||||
var orgs []*api.Organization
|
||||
DecodeJSON(t, resp, &orgs)
|
||||
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}).(*user_model.User)
|
||||
user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}).(*user_model.User)
|
||||
|
||||
assert.Equal(t, []*api.Organization{
|
||||
{
|
||||
ID: 17,
|
||||
UserName: user17.Name,
|
||||
FullName: user17.FullName,
|
||||
AvatarURL: user17.AvatarLink(),
|
||||
Description: "",
|
||||
Website: "",
|
||||
Location: "",
|
||||
Visibility: "public",
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
UserName: user3.Name,
|
||||
|
||||
@@ -179,8 +179,8 @@ func TestOrgRestrictedUser(t *testing.T) {
|
||||
func TestTeamSearch(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}).(*user_model.User)
|
||||
|
||||
var results TeamSearchResults
|
||||
|
||||
@@ -190,9 +190,9 @@ func TestTeamSearch(t *testing.T) {
|
||||
req.Header.Add("X-Csrf-Token", csrf)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &results)
|
||||
assert.NotEmpty(t, results.Data)
|
||||
assert.Len(t, results.Data, 1)
|
||||
assert.Equal(t, "test_team", results.Data[0].Name)
|
||||
assert.Len(t, results.Data, 2)
|
||||
assert.Equal(t, "review_team", results.Data[0].Name)
|
||||
assert.Equal(t, "test_team", results.Data[1].Name)
|
||||
|
||||
// no access if not organization member
|
||||
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default {
|
||||
rootDir: 'web_src',
|
||||
setupFilesAfterEnv: ['jest-extended/all'],
|
||||
testEnvironment: '@happy-dom/jest-environment',
|
||||
testEnvironment: 'jest-environment-jsdom',
|
||||
testMatch: ['<rootDir>/**/*.test.js'],
|
||||
testTimeout: 20000,
|
||||
transform: {
|
||||
|
||||
@@ -98,7 +98,14 @@ func (a *Action) TableIndices() []*schemas.Index {
|
||||
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
|
||||
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
|
||||
|
||||
return []*schemas.Index{actUserIndex, repoIndex}
|
||||
indices := []*schemas.Index{actUserIndex, repoIndex}
|
||||
if setting.Database.UsePostgreSQL {
|
||||
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
|
||||
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
|
||||
indices = append(indices, cudIndex)
|
||||
}
|
||||
|
||||
return indices
|
||||
}
|
||||
|
||||
// GetOpType gets the ActionType of this action.
|
||||
@@ -275,7 +282,7 @@ func (a *Action) GetRefLink() string {
|
||||
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
|
||||
case strings.HasPrefix(a.RefName, git.TagPrefix):
|
||||
return a.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.TagPrefix))
|
||||
case len(a.RefName) == 40 && git.SHAPattern.MatchString(a.RefName):
|
||||
case len(a.RefName) == 40 && git.IsValidSHAPattern(a.RefName):
|
||||
return a.GetRepoLink() + "/src/commit/" + a.RefName
|
||||
default:
|
||||
// FIXME: we will just assume it's a branch - this was the old way - at some point we may want to enforce that there is always a ref here.
|
||||
|
||||
@@ -33,7 +33,7 @@ type GPGKey struct {
|
||||
OwnerID int64 `xorm:"INDEX NOT NULL"`
|
||||
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
|
||||
PrimaryKeyID string `xorm:"CHAR(16)"`
|
||||
Content string `xorm:"TEXT NOT NULL"`
|
||||
Content string `xorm:"MEDIUMTEXT NOT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
ExpiredUnix timeutil.TimeStamp
|
||||
AddedUnix timeutil.TimeStamp
|
||||
@@ -63,6 +63,15 @@ func (key *GPGKey) AfterLoad(session *xorm.Session) {
|
||||
}
|
||||
}
|
||||
|
||||
// PaddedKeyID show KeyID padded to 16 characters
|
||||
func (key *GPGKey) PaddedKeyID() string {
|
||||
if len(key.KeyID) > 15 {
|
||||
return key.KeyID
|
||||
}
|
||||
zeros := "0000000000000000"
|
||||
return zeros[0:16-len(key.KeyID)] + key.KeyID
|
||||
}
|
||||
|
||||
// ListGPGKeys returns a list of public keys belongs to given user.
|
||||
func ListGPGKeys(ctx context.Context, uid int64, listOptions db.ListOptions) ([]*GPGKey, error) {
|
||||
sess := db.GetEngine(ctx).Table(&GPGKey{}).Where("owner_id=? AND primary_key_id=''", uid)
|
||||
|
||||
@@ -41,7 +41,7 @@ type PublicKey struct {
|
||||
OwnerID int64 `xorm:"INDEX NOT NULL"`
|
||||
Name string `xorm:"NOT NULL"`
|
||||
Fingerprint string `xorm:"INDEX NOT NULL"`
|
||||
Content string `xorm:"TEXT NOT NULL"`
|
||||
Content string `xorm:"MEDIUMTEXT NOT NULL"`
|
||||
Mode perm.AccessMode `xorm:"NOT NULL DEFAULT 2"`
|
||||
Type KeyType `xorm:"NOT NULL DEFAULT 1"`
|
||||
LoginSourceID int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
|
||||
@@ -512,10 +512,14 @@ func GetActiveOAuth2ProviderSources() ([]*Source, error) {
|
||||
func GetActiveOAuth2SourceByName(name string) (*Source, error) {
|
||||
authSource := new(Source)
|
||||
has, err := db.GetEngine(db.DefaultContext).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(authSource)
|
||||
if !has || err != nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !has {
|
||||
return nil, fmt.Errorf("oauth2 source not found, name: %q", name)
|
||||
}
|
||||
|
||||
return authSource, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base32"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -20,14 +19,14 @@ import (
|
||||
// ErrWebAuthnCredentialNotExist represents a "ErrWebAuthnCRedentialNotExist" kind of error.
|
||||
type ErrWebAuthnCredentialNotExist struct {
|
||||
ID int64
|
||||
CredentialID string
|
||||
CredentialID []byte
|
||||
}
|
||||
|
||||
func (err ErrWebAuthnCredentialNotExist) Error() string {
|
||||
if err.CredentialID == "" {
|
||||
if len(err.CredentialID) == 0 {
|
||||
return fmt.Sprintf("WebAuthn credential does not exist [id: %d]", err.ID)
|
||||
}
|
||||
return fmt.Sprintf("WebAuthn credential does not exist [credential_id: %s]", err.CredentialID)
|
||||
return fmt.Sprintf("WebAuthn credential does not exist [credential_id: %x]", err.CredentialID)
|
||||
}
|
||||
|
||||
// IsErrWebAuthnCredentialNotExist checks if an error is a ErrWebAuthnCredentialNotExist.
|
||||
@@ -43,7 +42,7 @@ type WebAuthnCredential struct {
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
CredentialID string `xorm:"INDEX VARCHAR(410)"`
|
||||
CredentialID []byte `xorm:"INDEX VARBINARY(1024)"`
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
@@ -94,9 +93,8 @@ type WebAuthnCredentialList []*WebAuthnCredential
|
||||
func (list WebAuthnCredentialList) ToCredentials() []webauthn.Credential {
|
||||
creds := make([]webauthn.Credential, 0, len(list))
|
||||
for _, cred := range list {
|
||||
credID, _ := base32.HexEncoding.DecodeString(cred.CredentialID)
|
||||
creds = append(creds, webauthn.Credential{
|
||||
ID: credID,
|
||||
ID: cred.CredentialID,
|
||||
PublicKey: cred.PublicKey,
|
||||
AttestationType: cred.AttestationType,
|
||||
Authenticator: webauthn.Authenticator{
|
||||
@@ -164,11 +162,11 @@ func HasWebAuthnRegistrationsByUID(uid int64) (bool, error) {
|
||||
}
|
||||
|
||||
// GetWebAuthnCredentialByCredID returns WebAuthn credential by credential ID
|
||||
func GetWebAuthnCredentialByCredID(userID int64, credID string) (*WebAuthnCredential, error) {
|
||||
func GetWebAuthnCredentialByCredID(userID int64, credID []byte) (*WebAuthnCredential, error) {
|
||||
return getWebAuthnCredentialByCredID(db.DefaultContext, userID, credID)
|
||||
}
|
||||
|
||||
func getWebAuthnCredentialByCredID(ctx context.Context, userID int64, credID string) (*WebAuthnCredential, error) {
|
||||
func getWebAuthnCredentialByCredID(ctx context.Context, userID int64, credID []byte) (*WebAuthnCredential, error) {
|
||||
cred := new(WebAuthnCredential)
|
||||
if found, err := db.GetEngine(ctx).Where("user_id = ? AND credential_id = ?", userID, credID).Get(cred); err != nil {
|
||||
return nil, err
|
||||
@@ -187,7 +185,7 @@ func createCredential(ctx context.Context, userID int64, name string, cred *weba
|
||||
c := &WebAuthnCredential{
|
||||
UserID: userID,
|
||||
Name: name,
|
||||
CredentialID: base32.HexEncoding.EncodeToString(cred.ID),
|
||||
CredentialID: cred.ID,
|
||||
PublicKey: cred.PublicKey,
|
||||
AttestationType: cred.AttestationType,
|
||||
AAGUID: cred.Authenticator.AAGUID,
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -61,9 +60,7 @@ func TestCreateCredential(t *testing.T) {
|
||||
res, err := CreateCredential(1, "WebAuthn Created Credential", &webauthn.Credential{ID: []byte("Test")})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "WebAuthn Created Credential", res.Name)
|
||||
bs, err := base32.HexEncoding.DecodeString(res.CredentialID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("Test"), bs)
|
||||
assert.Equal(t, []byte("Test"), res.CredentialID)
|
||||
|
||||
unittest.AssertExistsIf(t, true, &WebAuthnCredential{Name: "WebAuthn Created Credential", UserID: 1})
|
||||
}
|
||||
|
||||
34
models/db/iterate.go
Normal file
34
models/db/iterate.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// IterateObjects iterate all the Bean object
|
||||
func IterateObjects[Object any](ctx context.Context, f func(repo *Object) error) error {
|
||||
var start int
|
||||
batchSize := setting.Database.IterateBufferSize
|
||||
sess := GetEngine(ctx)
|
||||
for {
|
||||
repos := make([]*Object, 0, batchSize)
|
||||
if err := sess.Limit(batchSize, start).Find(&repos); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(repos)
|
||||
|
||||
for _, repo := range repos {
|
||||
if err := f(repo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,3 +63,9 @@
|
||||
uid: 29
|
||||
org_id: 17
|
||||
is_public: true
|
||||
|
||||
-
|
||||
id: 12
|
||||
uid: 2
|
||||
org_id: 17
|
||||
is_public: true
|
||||
|
||||
@@ -309,7 +309,7 @@
|
||||
avatar_email: user17@example.com
|
||||
num_repos: 2
|
||||
is_active: true
|
||||
num_members: 3
|
||||
num_members: 4
|
||||
num_teams: 3
|
||||
|
||||
-
|
||||
|
||||
@@ -278,29 +278,6 @@ func LFSAutoAssociate(metas []*LFSMetaObject, user *user_model.User, repoID int6
|
||||
return committer.Commit()
|
||||
}
|
||||
|
||||
// IterateLFS iterates lfs object
|
||||
func IterateLFS(f func(mo *LFSMetaObject) error) error {
|
||||
var start int
|
||||
const batchSize = 100
|
||||
e := db.GetEngine(db.DefaultContext)
|
||||
for {
|
||||
mos := make([]*LFSMetaObject, 0, batchSize)
|
||||
if err := e.Limit(batchSize, start).Find(&mos); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(mos) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(mos)
|
||||
|
||||
for _, mo := range mos {
|
||||
if err := f(mo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CopyLFS copies LFS data from one repo to another
|
||||
func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error {
|
||||
var lfsObjects []*LFSMetaObject
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
project_model "code.gitea.io/gitea/models/project"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
@@ -222,6 +223,46 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (issues IssueList) getProjectIDs() []int64 {
|
||||
ids := make(map[int64]struct{}, len(issues))
|
||||
for _, issue := range issues {
|
||||
projectID := issue.ProjectID()
|
||||
if _, ok := ids[projectID]; !ok {
|
||||
ids[projectID] = struct{}{}
|
||||
}
|
||||
}
|
||||
return container.KeysInt64(ids)
|
||||
}
|
||||
|
||||
func (issues IssueList) loadProjects(ctx context.Context) error {
|
||||
projectIDs := issues.getProjectIDs()
|
||||
if len(projectIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
projectMaps := make(map[int64]*project_model.Project, len(projectIDs))
|
||||
left := len(projectIDs)
|
||||
for left > 0 {
|
||||
limit := db.DefaultMaxInSize
|
||||
if left < limit {
|
||||
limit = left
|
||||
}
|
||||
err := db.GetEngine(ctx).
|
||||
In("id", projectIDs[:limit]).
|
||||
Find(&projectMaps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
left -= limit
|
||||
projectIDs = projectIDs[limit:]
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
issue.Project = projectMaps[issue.ProjectID()]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (issues IssueList) loadAssignees(ctx context.Context) error {
|
||||
if len(issues) == 0 {
|
||||
return nil
|
||||
@@ -495,6 +536,10 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
|
||||
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
|
||||
}
|
||||
|
||||
if err := issues.loadProjects(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
|
||||
}
|
||||
|
||||
if err := issues.loadAssignees(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ func LoadIssuesFromBoard(b *project_model.Board) (IssueList, error) {
|
||||
issues, err := Issues(&IssuesOptions{
|
||||
ProjectBoardID: b.ID,
|
||||
ProjectID: b.ProjectID,
|
||||
SortType: "project-column-sorting",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,6 +80,7 @@ func LoadIssuesFromBoard(b *project_model.Board) (IssueList, error) {
|
||||
issues, err := Issues(&IssuesOptions{
|
||||
ProjectBoardID: -1, // Issues without ProjectBoardID
|
||||
ProjectID: b.ProjectID,
|
||||
SortType: "project-column-sorting",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
@@ -361,7 +362,11 @@ func (opts GetMilestonesOption) toCond() builder.Cond {
|
||||
}
|
||||
|
||||
if len(opts.Name) != 0 {
|
||||
cond = cond.And(builder.Like{"name", opts.Name})
|
||||
if setting.Database.UseSQLite3 {
|
||||
cond = cond.And(builder.Like{"UPPER(name)", util.ToUpperASCII(opts.Name)})
|
||||
} else {
|
||||
cond = cond.And(builder.Like{"UPPER(name)", strings.ToUpper(opts.Name)})
|
||||
}
|
||||
}
|
||||
|
||||
return cond
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
@@ -474,6 +475,35 @@ func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, co
|
||||
return review, comm, committer.Commit()
|
||||
}
|
||||
|
||||
// GetReviewOptions represent filter options for GetReviews
|
||||
type GetReviewOptions struct {
|
||||
IssueID int64
|
||||
ReviewerID int64
|
||||
Dismissed util.OptionalBool
|
||||
}
|
||||
|
||||
// GetReviews return reviews based on GetReviewOptions
|
||||
func GetReviews(ctx context.Context, opts *GetReviewOptions) ([]*Review, error) {
|
||||
if opts == nil {
|
||||
return nil, fmt.Errorf("opts are nil")
|
||||
}
|
||||
|
||||
sess := db.GetEngine(ctx)
|
||||
|
||||
if opts.IssueID != 0 {
|
||||
sess = sess.Where("issue_id=?", opts.IssueID)
|
||||
}
|
||||
if opts.ReviewerID != 0 {
|
||||
sess = sess.Where("reviewer_id=?", opts.ReviewerID)
|
||||
}
|
||||
if !opts.Dismissed.IsNone() {
|
||||
sess = sess.Where("dismissed=?", opts.Dismissed.IsTrue())
|
||||
}
|
||||
|
||||
reviews := make([]*Review, 0, 4)
|
||||
return reviews, sess.Find(&reviews)
|
||||
}
|
||||
|
||||
// GetReviewersByIssueID gets the latest review of each reviewer for a pull request
|
||||
func GetReviewersByIssueID(issueID int64) ([]*Review, error) {
|
||||
reviews := make([]*Review, 0, 10)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
-
|
||||
id: 1
|
||||
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG="
|
||||
-
|
||||
id: 2
|
||||
credential_id: "051CLMMKB62S6M9M2A4H54K7MMCQALFJ36G4TGB2S9A47APLTILU6C6744CEBG4EKCGV357N21BSLH8JD33GQMFAR6DQ70S76P34J6FR="
|
||||
-
|
||||
id: 4
|
||||
credential_id: "APU4B1NDTEVTEM60V4T0FRL7SRJMO9KIE2AKFQ8JDGTQ7VHFI41FDEFTDLBVQEAE4ER49QV2GTGVFDNBO31BPOA3OQN6879OT6MTU3G="
|
||||
@@ -0,0 +1,31 @@
|
||||
-
|
||||
id: 1
|
||||
lower_name: "u2fkey-correctly-migrated"
|
||||
name: "u2fkey-correctly-migrated"
|
||||
user_id: 1
|
||||
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG="
|
||||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2
|
||||
attestation_type: 'fido-u2f'
|
||||
sign_count: 1
|
||||
clone_warning: false
|
||||
-
|
||||
id: 2
|
||||
lower_name: "non-u2f-key"
|
||||
name: "non-u2f-key"
|
||||
user_id: 1
|
||||
credential_id: "051CLMMKB62S6M9M2A4H54K7MMCQALFJ36G4TGB2S9A47APLTILU6C6744CEBG4EKCGV357N21BSLH8JD33GQMFAR6DQ70S76P34J6FR"
|
||||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2
|
||||
attestation_type: 'none'
|
||||
sign_count: 1
|
||||
clone_warning: false
|
||||
-
|
||||
id: 4
|
||||
lower_name: "packed-key"
|
||||
name: "packed-key"
|
||||
user_id: 1
|
||||
credential_id: "APU4B1NDTEVTEM60V4T0FRL7SRJMO9KIE2AKFQ8JDGTQ7VHFI41FDEFTDLBVQEAE4ER49QV2GTGVFDNBO31BPOA3OQN6879OT6MTU3G="
|
||||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2
|
||||
attestation_type: 'fido-u2f'
|
||||
sign_count: 1
|
||||
clone_warning: false
|
||||
|
||||
@@ -396,6 +396,16 @@ var migrations = []Migration{
|
||||
NewMigration("Alter hook_task table TEXT fields to LONGTEXT", alterHookTaskTextFieldsToLongText),
|
||||
// v218 -> v219
|
||||
NewMigration("Improve Action table indices v2", improveActionTableIndices),
|
||||
// v219 -> v220
|
||||
NewMigration("Add sync_on_commit column to push_mirror table", addSyncOnCommitColForPushMirror),
|
||||
// v220 -> v221
|
||||
NewMigration("Add container repository property", addContainerRepositoryProperty),
|
||||
// v221 -> v222
|
||||
NewMigration("Store WebAuthentication CredentialID as bytes and increase size to at least 1024", storeWebauthnCredentialIDAsBytes),
|
||||
// v222 -> v223
|
||||
NewMigration("Drop old CredentialID column", dropOldCredentialIDColumn),
|
||||
// v223 -> v224
|
||||
NewMigration("Rename CredentialIDBytes column to CredentialID", renameCredentialIDBytes),
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current db version
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
@@ -37,8 +38,14 @@ func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index {
|
||||
|
||||
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
|
||||
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
|
||||
indices := []*schemas.Index{actUserIndex, repoIndex}
|
||||
if setting.Database.UsePostgreSQL {
|
||||
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
|
||||
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
|
||||
indices = append(indices, cudIndex)
|
||||
}
|
||||
|
||||
return []*schemas.Index{actUserIndex, repoIndex}
|
||||
return indices
|
||||
}
|
||||
|
||||
func improveActionTableIndices(x *xorm.Engine) error {
|
||||
|
||||
31
models/migrations/v219.go
Normal file
31
models/migrations/v219.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func addSyncOnCommitColForPushMirror(x *xorm.Engine) error {
|
||||
type PushMirror struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX"`
|
||||
Repo *repo.Repository `xorm:"-"`
|
||||
RemoteName string
|
||||
|
||||
SyncOnCommit bool `xorm:"NOT NULL DEFAULT true"`
|
||||
Interval time.Duration
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
LastUpdateUnix timeutil.TimeStamp `xorm:"INDEX last_update"`
|
||||
LastError string `xorm:"text"`
|
||||
}
|
||||
|
||||
return x.Sync2(new(PushMirror))
|
||||
}
|
||||
28
models/migrations/v220.go
Normal file
28
models/migrations/v220.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
container_module "code.gitea.io/gitea/modules/packages/container"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func addContainerRepositoryProperty(x *xorm.Engine) (err error) {
|
||||
switch x.Dialect().URI().DBType {
|
||||
case schemas.SQLITE:
|
||||
_, err = x.Exec("INSERT INTO package_property (ref_type, ref_id, name, value) SELECT ?, p.id, ?, u.lower_name || '/' || p.lower_name FROM package p JOIN `user` u ON p.owner_id = u.id WHERE p.type = ?",
|
||||
packages_model.PropertyTypePackage, container_module.PropertyRepository, packages_model.TypeContainer)
|
||||
case schemas.MSSQL:
|
||||
_, err = x.Exec("INSERT INTO package_property (ref_type, ref_id, name, value) SELECT ?, p.id, ?, u.lower_name + '/' + p.lower_name FROM package p JOIN `user` u ON p.owner_id = u.id WHERE p.type = ?",
|
||||
packages_model.PropertyTypePackage, container_module.PropertyRepository, packages_model.TypeContainer)
|
||||
default:
|
||||
_, err = x.Exec("INSERT INTO package_property (ref_type, ref_id, name, value) SELECT ?, p.id, ?, CONCAT(u.lower_name, '/', p.lower_name) FROM package p JOIN `user` u ON p.owner_id = u.id WHERE p.type = ?",
|
||||
packages_model.PropertyTypePackage, container_module.PropertyRepository, packages_model.TypeContainer)
|
||||
}
|
||||
return err
|
||||
}
|
||||
75
models/migrations/v221.go
Normal file
75
models/migrations/v221.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func storeWebauthnCredentialIDAsBytes(x *xorm.Engine) error {
|
||||
// Create webauthnCredential table
|
||||
type webauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
CredentialID string `xorm:"INDEX VARCHAR(410)"`
|
||||
// Note the lack of INDEX here - these will be created once the column is renamed in v223.go
|
||||
CredentialIDBytes []byte `xorm:"VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
SignCount uint32 `xorm:"BIGINT"`
|
||||
CloneWarning bool
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
}
|
||||
if err := x.Sync2(&webauthnCredential{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var start int
|
||||
creds := make([]*webauthnCredential, 0, 50)
|
||||
for {
|
||||
err := x.Select("id, credential_id").OrderBy("id").Limit(50, start).Find(&creds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return fmt.Errorf("unable to allow start session. Error: %w", err)
|
||||
}
|
||||
for _, cred := range creds {
|
||||
cred.CredentialIDBytes, err = base32.HexEncoding.DecodeString(cred.CredentialID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse credential id %s for credential[%d]: %w", cred.CredentialID, cred.ID, err)
|
||||
}
|
||||
count, err := sess.ID(cred.ID).Cols("credential_id_bytes").Update(cred)
|
||||
if count != 1 || err != nil {
|
||||
return fmt.Errorf("unable to update credential id bytes for credential[%d]: %d,%w", cred.ID, count, err)
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(creds) < 50 {
|
||||
break
|
||||
}
|
||||
start += 50
|
||||
creds = creds[:0]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
65
models/migrations/v221_test.go
Normal file
65
models/migrations/v221_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_storeWebauthnCredentialIDAsBytes(t *testing.T) {
|
||||
// Create webauthnCredential table
|
||||
type WebauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
CredentialID string `xorm:"INDEX VARCHAR(410)"`
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
SignCount uint32 `xorm:"BIGINT"`
|
||||
CloneWarning bool
|
||||
}
|
||||
|
||||
type ExpectedWebauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CredentialID string // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
}
|
||||
|
||||
type ConvertedWebauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CredentialIDBytes []byte `xorm:"VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := prepareTestEnv(t, 0, new(WebauthnCredential), new(ExpectedWebauthnCredential))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := storeWebauthnCredentialIDAsBytes(x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
expected := []ExpectedWebauthnCredential{}
|
||||
if err := x.Table("expected_webauthn_credential").Asc("id").Find(&expected); !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
got := []ConvertedWebauthnCredential{}
|
||||
if err := x.Table("webauthn_credential").Select("id, credential_id_bytes").Asc("id").Find(&got); !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
for i, e := range expected {
|
||||
credIDBytes, _ := base32.HexEncoding.DecodeString(e.CredentialID)
|
||||
assert.Equal(t, credIDBytes, got[i].CredentialIDBytes)
|
||||
}
|
||||
}
|
||||
64
models/migrations/v222.go
Normal file
64
models/migrations/v222.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func dropOldCredentialIDColumn(x *xorm.Engine) error {
|
||||
// This migration maybe rerun so that we should check if it has been run
|
||||
credentialIDExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webauthn_credential", "credential_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !credentialIDExist {
|
||||
// Column is already non-extant
|
||||
return nil
|
||||
}
|
||||
credentialIDBytesExists, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webauthn_credential", "credential_id_bytes")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !credentialIDBytesExists {
|
||||
// looks like 221 hasn't properly run
|
||||
return fmt.Errorf("webauthn_credential does not have a credential_id_bytes column... it is not safe to run this migration")
|
||||
}
|
||||
|
||||
// Create webauthnCredential table
|
||||
type webauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
CredentialID string `xorm:"INDEX VARCHAR(410)"`
|
||||
// Note the lack of the INDEX on CredentialIDBytes - we will add this in v223.go
|
||||
CredentialIDBytes []byte `xorm:"VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
SignCount uint32 `xorm:"BIGINT"`
|
||||
CloneWarning bool
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
}
|
||||
if err := x.Sync2(&webauthnCredential{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Drop the old credential ID
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
if err := dropTableColumns(sess, "webauthn_credential", "credential_id"); err != nil {
|
||||
return fmt.Errorf("unable to drop old credentialID column: %w", err)
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
103
models/migrations/v223.go
Normal file
103
models/migrations/v223.go
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func renameCredentialIDBytes(x *xorm.Engine) error {
|
||||
// This migration maybe rerun so that we should check if it has been run
|
||||
credentialIDExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webauthn_credential", "credential_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if credentialIDExist {
|
||||
credentialIDBytesExists, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webauthn_credential", "credential_id_bytes")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !credentialIDBytesExists {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
// webauthnCredential table
|
||||
type webauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
// Note the lack of INDEX here
|
||||
CredentialIDBytes []byte `xorm:"VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
SignCount uint32 `xorm:"BIGINT"`
|
||||
CloneWarning bool
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
}
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := sess.Sync2(new(webauthnCredential)); err != nil {
|
||||
return fmt.Errorf("error on Sync2: %v", err)
|
||||
}
|
||||
|
||||
if credentialIDExist {
|
||||
// if both errors and message exist, drop message at first
|
||||
if err := dropTableColumns(sess, "webauthn_credential", "credential_id"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case setting.Database.UseMySQL:
|
||||
if _, err := sess.Exec("ALTER TABLE `webauthn_credential` CHANGE credential_id_bytes credential_id VARBINARY(1024)"); err != nil {
|
||||
return err
|
||||
}
|
||||
case setting.Database.UseMSSQL:
|
||||
if _, err := sess.Exec("sp_rename 'webauthn_credential.credential_id_bytes', 'credential_id', 'COLUMN'"); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if _, err := sess.Exec("ALTER TABLE `webauthn_credential` RENAME COLUMN credential_id_bytes TO credential_id"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create webauthnCredential table
|
||||
type webauthnCredential struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string
|
||||
LowerName string `xorm:"unique(s)"`
|
||||
UserID int64 `xorm:"INDEX unique(s)"`
|
||||
CredentialID []byte `xorm:"INDEX VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
||||
PublicKey []byte
|
||||
AttestationType string
|
||||
AAGUID []byte
|
||||
SignCount uint32 `xorm:"BIGINT"`
|
||||
CloneWarning bool
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
}
|
||||
return x.Sync2(&webauthnCredential{})
|
||||
}
|
||||
@@ -96,16 +96,7 @@ type SearchTeamOptions struct {
|
||||
IncludeDesc bool
|
||||
}
|
||||
|
||||
// SearchTeam search for teams. Caller is responsible to check permissions.
|
||||
func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
|
||||
if opts.Page <= 0 {
|
||||
opts.Page = 1
|
||||
}
|
||||
if opts.PageSize == 0 {
|
||||
// Default limit
|
||||
opts.PageSize = 10
|
||||
}
|
||||
|
||||
func (opts *SearchTeamOptions) toCond() builder.Cond {
|
||||
cond := builder.NewCond()
|
||||
|
||||
if len(opts.Keyword) > 0 {
|
||||
@@ -117,10 +108,28 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
|
||||
cond = cond.And(keywordCond)
|
||||
}
|
||||
|
||||
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
|
||||
if opts.OrgID > 0 {
|
||||
cond = cond.And(builder.Eq{"`team`.org_id": opts.OrgID})
|
||||
}
|
||||
|
||||
if opts.UserID > 0 {
|
||||
cond = cond.And(builder.Eq{"team_user.uid": opts.UserID})
|
||||
}
|
||||
|
||||
return cond
|
||||
}
|
||||
|
||||
// SearchTeam search for teams. Caller is responsible to check permissions.
|
||||
func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
|
||||
sess := db.GetEngine(db.DefaultContext)
|
||||
|
||||
opts.SetDefaultValues()
|
||||
cond := opts.toCond()
|
||||
|
||||
if opts.UserID > 0 {
|
||||
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id")
|
||||
}
|
||||
|
||||
count, err := sess.
|
||||
Where(cond).
|
||||
Count(new(Team))
|
||||
@@ -128,6 +137,10 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if opts.UserID > 0 {
|
||||
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id")
|
||||
}
|
||||
|
||||
sess = sess.Where(cond)
|
||||
if opts.PageSize == -1 {
|
||||
opts.PageSize = int(count)
|
||||
@@ -137,6 +150,7 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
|
||||
|
||||
teams := make([]*Team, 0, opts.PageSize)
|
||||
if err = sess.
|
||||
Where(cond).
|
||||
OrderBy("lower_name").
|
||||
Find(&teams); err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/packages"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
container_module "code.gitea.io/gitea/modules/packages/container"
|
||||
|
||||
"xorm.io/builder"
|
||||
@@ -210,6 +211,7 @@ func SearchImageTags(ctx context.Context, opts *ImageTagsSearchOptions) ([]*pack
|
||||
return pvs, count, err
|
||||
}
|
||||
|
||||
// SearchExpiredUploadedBlobs gets all uploaded blobs which are older than specified
|
||||
func SearchExpiredUploadedBlobs(ctx context.Context, olderThan time.Duration) ([]*packages.PackageFile, error) {
|
||||
var cond builder.Cond = builder.Eq{
|
||||
"package_version.is_internal": true,
|
||||
@@ -225,3 +227,37 @@ func SearchExpiredUploadedBlobs(ctx context.Context, olderThan time.Duration) ([
|
||||
Where(cond).
|
||||
Find(&pfs)
|
||||
}
|
||||
|
||||
// GetRepositories gets a sorted list of all repositories
|
||||
func GetRepositories(ctx context.Context, actor *user_model.User, n int, last string) ([]string, error) {
|
||||
var cond builder.Cond = builder.Eq{
|
||||
"package.type": packages.TypeContainer,
|
||||
"package_property.ref_type": packages.PropertyTypePackage,
|
||||
"package_property.name": container_module.PropertyRepository,
|
||||
}
|
||||
|
||||
cond = cond.And(builder.Exists(
|
||||
builder.
|
||||
Select("package_version.id").
|
||||
Where(builder.Eq{"package_version.is_internal": false}.And(builder.Expr("package.id = package_version.package_id"))).
|
||||
From("package_version"),
|
||||
))
|
||||
|
||||
if last != "" {
|
||||
cond = cond.And(builder.Gt{"package_property.value": strings.ToLower(last)})
|
||||
}
|
||||
|
||||
cond = cond.And(user_model.BuildCanSeeUserCondition(actor))
|
||||
|
||||
sess := db.GetEngine(ctx).
|
||||
Table("package").
|
||||
Select("package_property.value").
|
||||
Join("INNER", "user", "`user`.id = package.owner_id").
|
||||
Join("INNER", "package_property", "package_property.ref_id = package.id").
|
||||
Where(cond).
|
||||
Asc("package_property.value").
|
||||
Limit(n)
|
||||
|
||||
repositories := make([]string, 0, n)
|
||||
return repositories, sess.Find(&repositories)
|
||||
}
|
||||
|
||||
@@ -40,15 +40,16 @@ func (l PackagePropertyList) GetByName(name string) string {
|
||||
|
||||
// PackageDescriptor describes a package
|
||||
type PackageDescriptor struct {
|
||||
Package *Package
|
||||
Owner *user_model.User
|
||||
Repository *repo_model.Repository
|
||||
Version *PackageVersion
|
||||
SemVer *version.Version
|
||||
Creator *user_model.User
|
||||
Properties PackagePropertyList
|
||||
Metadata interface{}
|
||||
Files []*PackageFileDescriptor
|
||||
Package *Package
|
||||
Owner *user_model.User
|
||||
Repository *repo_model.Repository
|
||||
Version *PackageVersion
|
||||
SemVer *version.Version
|
||||
Creator *user_model.User
|
||||
PackageProperties PackagePropertyList
|
||||
VersionProperties PackagePropertyList
|
||||
Metadata interface{}
|
||||
Files []*PackageFileDescriptor
|
||||
}
|
||||
|
||||
// PackageFileDescriptor describes a package file
|
||||
@@ -102,6 +103,10 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
pps, err := GetProperties(ctx, PropertyTypePackage, p.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pvps, err := GetProperties(ctx, PropertyTypeVersion, pv.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -152,15 +157,16 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
|
||||
}
|
||||
|
||||
return &PackageDescriptor{
|
||||
Package: p,
|
||||
Owner: o,
|
||||
Repository: repository,
|
||||
Version: pv,
|
||||
SemVer: semVer,
|
||||
Creator: creator,
|
||||
Properties: PackagePropertyList(pvps),
|
||||
Metadata: metadata,
|
||||
Files: pfds,
|
||||
Package: p,
|
||||
Owner: o,
|
||||
Repository: repository,
|
||||
Version: pv,
|
||||
SemVer: semVer,
|
||||
Creator: creator,
|
||||
PackageProperties: PackagePropertyList(pps),
|
||||
VersionProperties: PackagePropertyList(pvps),
|
||||
Metadata: metadata,
|
||||
Files: pfds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,12 @@ func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// DeletePackageByID deletes a package by id
|
||||
func DeletePackageByID(ctx context.Context, packageID int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(packageID).Delete(&Package{})
|
||||
return err
|
||||
}
|
||||
|
||||
// SetRepositoryLink sets the linked repository
|
||||
func SetRepositoryLink(ctx context.Context, packageID, repoID int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(packageID).Cols("repo_id").Update(&Package{RepoID: repoID})
|
||||
@@ -192,26 +198,32 @@ func GetPackagesByType(ctx context.Context, ownerID int64, packageType Type) ([]
|
||||
Find(&ps)
|
||||
}
|
||||
|
||||
// DeletePackagesIfUnreferenced deletes a package if there are no associated versions
|
||||
func DeletePackagesIfUnreferenced(ctx context.Context) error {
|
||||
// FindUnreferencedPackages gets all packages without associated versions
|
||||
func FindUnreferencedPackages(ctx context.Context) ([]*Package, error) {
|
||||
in := builder.
|
||||
Select("package.id").
|
||||
From("package").
|
||||
LeftJoin("package_version", "package_version.package_id = package.id").
|
||||
Where(builder.Expr("package_version.id IS NULL"))
|
||||
|
||||
_, err := db.GetEngine(ctx).
|
||||
ps := make([]*Package, 0, 10)
|
||||
return ps, db.GetEngine(ctx).
|
||||
// double select workaround for MySQL
|
||||
// https://stackoverflow.com/questions/4471277/mysql-delete-from-with-subquery-as-condition
|
||||
Where(builder.In("package.id", builder.Select("id").From(in, "temp"))).
|
||||
Delete(&Package{})
|
||||
|
||||
return err
|
||||
Find(&ps)
|
||||
}
|
||||
|
||||
// HasOwnerPackages tests if a user/org has packages
|
||||
// HasOwnerPackages tests if a user/org has accessible packages
|
||||
func HasOwnerPackages(ctx context.Context, ownerID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).Where("owner_id = ?", ownerID).Exist(&Package{})
|
||||
return db.GetEngine(ctx).
|
||||
Table("package_version").
|
||||
Join("INNER", "package", "package.id = package_version.package_id").
|
||||
Where(builder.Eq{
|
||||
"package_version.is_internal": false,
|
||||
"package.owner_id": ownerID,
|
||||
}).
|
||||
Exist(&PackageVersion{})
|
||||
}
|
||||
|
||||
// HasRepositoryPackages tests if a repository has packages
|
||||
|
||||
@@ -21,9 +21,11 @@ const (
|
||||
PropertyTypeVersion PropertyType = iota // 0
|
||||
// PropertyTypeFile means the reference is a package file
|
||||
PropertyTypeFile // 1
|
||||
// PropertyTypePackage means the reference is a package
|
||||
PropertyTypePackage // 2
|
||||
)
|
||||
|
||||
// PackageProperty represents a property of a package version or file
|
||||
// PackageProperty represents a property of a package, version or file
|
||||
type PackageProperty struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RefType PropertyType `xorm:"INDEX NOT NULL"`
|
||||
@@ -68,3 +70,9 @@ func DeletePropertyByID(ctx context.Context, propertyID int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(propertyID).Delete(&PackageProperty{})
|
||||
return err
|
||||
}
|
||||
|
||||
// DeletePropertyByName deletes properties by name
|
||||
func DeletePropertyByName(ctx context.Context, refType PropertyType, refID int64, name string) error {
|
||||
_, err := db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ? AND name = ?", refType, refID, name).Delete(&PackageProperty{})
|
||||
return err
|
||||
}
|
||||
|
||||
69
models/packages/package_test.go
Normal file
69
models/packages/package_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package packages_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
_ "code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", ".."),
|
||||
})
|
||||
}
|
||||
|
||||
func TestHasOwnerPackages(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||
|
||||
p, err := packages_model.TryInsertPackage(db.DefaultContext, &packages_model.Package{
|
||||
OwnerID: owner.ID,
|
||||
LowerName: "package",
|
||||
})
|
||||
assert.NotNil(t, p)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// A package without package versions gets automatically cleaned up and should return false
|
||||
has, err := packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
||||
assert.False(t, has)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pv, err := packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
|
||||
PackageID: p.ID,
|
||||
LowerVersion: "internal",
|
||||
IsInternal: true,
|
||||
})
|
||||
assert.NotNil(t, pv)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// A package with an internal package version gets automaticaly cleaned up and should return false
|
||||
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
||||
assert.False(t, has)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pv, err = packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
|
||||
PackageID: p.ID,
|
||||
LowerVersion: "normal",
|
||||
IsInternal: false,
|
||||
})
|
||||
assert.NotNil(t, pv)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// A package with a normal package version should return true
|
||||
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
||||
assert.True(t, has)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -385,8 +385,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
||||
|
||||
archivePaths := make([]string, 0, len(archives))
|
||||
for _, v := range archives {
|
||||
p, _ := v.RelativePath()
|
||||
archivePaths = append(archivePaths, p)
|
||||
archivePaths = append(archivePaths, v.RelativePath())
|
||||
}
|
||||
|
||||
if _, err := db.DeleteByBean(ctx, &repo_model.RepoArchiver{RepoID: repoID}); err != nil {
|
||||
|
||||
@@ -39,9 +39,9 @@ func init() {
|
||||
db.RegisterModel(new(RepoArchiver))
|
||||
}
|
||||
|
||||
// RelativePath returns relative path
|
||||
func (archiver *RepoArchiver) RelativePath() (string, error) {
|
||||
return fmt.Sprintf("%d/%s/%s.%s", archiver.RepoID, archiver.CommitID[:2], archiver.CommitID, archiver.Type.String()), nil
|
||||
// RelativePath returns the archive path relative to the archive storage root.
|
||||
func (archiver *RepoArchiver) RelativePath() string {
|
||||
return fmt.Sprintf("%d/%s/%s.%s", archiver.RepoID, archiver.CommitID[:2], archiver.CommitID, archiver.Type.String())
|
||||
}
|
||||
|
||||
var delRepoArchiver = new(RepoArchiver)
|
||||
|
||||
@@ -226,28 +226,6 @@ func DeleteAttachmentsByRelease(releaseID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// IterateAttachment iterates attachments; it should not be used when Gitea is servicing users.
|
||||
func IterateAttachment(f func(attach *Attachment) error) error {
|
||||
var start int
|
||||
const batchSize = 100
|
||||
for {
|
||||
attachments := make([]*Attachment, 0, batchSize)
|
||||
if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&attachments); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(attachments) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(attachments)
|
||||
|
||||
for _, attach := range attachments {
|
||||
if err := f(attach); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CountOrphanedAttachments returns the number of bad attachments
|
||||
func CountOrphanedAttachments() (int64, error) {
|
||||
return db.GetEngine(db.DefaultContext).Where("(issue_id > 0 and issue_id not in (select id from issue)) or (release_id > 0 and release_id not in (select id from `release`))").
|
||||
|
||||
@@ -8,7 +8,6 @@ package repo
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -108,12 +107,14 @@ func DeleteMirrorByRepoID(repoID int64) error {
|
||||
|
||||
// MirrorsIterate iterates all mirror repositories.
|
||||
func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
|
||||
return db.GetEngine(db.DefaultContext).
|
||||
sess := db.GetEngine(db.DefaultContext).
|
||||
Where("next_update_unix<=?", time.Now().Unix()).
|
||||
And("next_update_unix!=0").
|
||||
OrderBy("updated_unix ASC").
|
||||
Limit(limit).
|
||||
Iterate(new(Mirror), f)
|
||||
OrderBy("updated_unix ASC")
|
||||
if limit > 0 {
|
||||
sess = sess.Limit(limit)
|
||||
}
|
||||
return sess.Iterate(new(Mirror), f)
|
||||
}
|
||||
|
||||
// InsertMirror inserts a mirror to database
|
||||
@@ -121,53 +122,3 @@ func InsertMirror(ctx context.Context, mirror *Mirror) error {
|
||||
_, err := db.GetEngine(ctx).Insert(mirror)
|
||||
return err
|
||||
}
|
||||
|
||||
// MirrorRepositoryList contains the mirror repositories
|
||||
type MirrorRepositoryList []*Repository
|
||||
|
||||
func (repos MirrorRepositoryList) loadAttributes(ctx context.Context) error {
|
||||
if len(repos) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Load mirrors.
|
||||
repoIDs := make([]int64, 0, len(repos))
|
||||
for i := range repos {
|
||||
if !repos[i].IsMirror {
|
||||
continue
|
||||
}
|
||||
|
||||
repoIDs = append(repoIDs, repos[i].ID)
|
||||
}
|
||||
mirrors := make([]*Mirror, 0, len(repoIDs))
|
||||
if err := db.GetEngine(ctx).
|
||||
Where("id > 0").
|
||||
In("repo_id", repoIDs).
|
||||
Find(&mirrors); err != nil {
|
||||
return fmt.Errorf("find mirrors: %v", err)
|
||||
}
|
||||
|
||||
set := make(map[int64]*Mirror)
|
||||
for i := range mirrors {
|
||||
set[mirrors[i].RepoID] = mirrors[i]
|
||||
}
|
||||
for i := range repos {
|
||||
repos[i].Mirror = set[repos[i].ID]
|
||||
repos[i].Mirror.Repo = repos[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadAttributes loads the attributes for the given MirrorRepositoryList
|
||||
func (repos MirrorRepositoryList) LoadAttributes() error {
|
||||
return repos.loadAttributes(db.DefaultContext)
|
||||
}
|
||||
|
||||
// GetUserMirrorRepositories returns a list of mirror repositories of given user.
|
||||
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, db.GetEngine(db.DefaultContext).
|
||||
Where("owner_id = ?", userID).
|
||||
And("is_mirror = ?", true).
|
||||
Find(&repos)
|
||||
}
|
||||
|
||||
@@ -95,10 +95,12 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) {
|
||||
|
||||
// PushMirrorsIterate iterates all push-mirror repositories.
|
||||
func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
|
||||
return db.GetEngine(db.DefaultContext).
|
||||
sess := db.GetEngine(db.DefaultContext).
|
||||
Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
|
||||
And("`interval` != 0").
|
||||
OrderBy("last_update ASC").
|
||||
Limit(limit).
|
||||
Iterate(new(PushMirror), f)
|
||||
OrderBy("last_update ASC")
|
||||
if limit > 0 {
|
||||
sess = sess.Limit(limit)
|
||||
}
|
||||
return sess.Iterate(new(PushMirror), f)
|
||||
}
|
||||
|
||||
@@ -14,36 +14,12 @@ import (
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// IterateRepository iterate repositories
|
||||
func IterateRepository(f func(repo *Repository) error) error {
|
||||
var start int
|
||||
batchSize := setting.Database.IterateBufferSize
|
||||
sess := db.GetEngine(db.DefaultContext)
|
||||
for {
|
||||
repos := make([]*Repository, 0, batchSize)
|
||||
if err := sess.Limit(batchSize, start).Find(&repos); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(repos)
|
||||
|
||||
for _, repo := range repos {
|
||||
if err := f(repo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FindReposMapByIDs find repos as map
|
||||
func FindReposMapByIDs(repoIDs []int64, res map[int64]*Repository) error {
|
||||
return db.GetEngine(db.DefaultContext).In("id", repoIDs).Find(&res)
|
||||
|
||||
@@ -100,9 +100,9 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
|
||||
|
||||
// Delete Comments
|
||||
const batchSize = 50
|
||||
for start := 0; ; start += batchSize {
|
||||
for {
|
||||
comments := make([]*issues_model.Comment, 0, batchSize)
|
||||
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil {
|
||||
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, 0).Find(&comments); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(comments) == 0 {
|
||||
@@ -200,7 +200,7 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
|
||||
// ***** END: ExternalLoginUser *****
|
||||
|
||||
if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("delete: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
@@ -58,31 +57,7 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
|
||||
cond = cond.And(builder.In("visibility", opts.Visible))
|
||||
}
|
||||
|
||||
if opts.Actor != nil {
|
||||
var exprCond builder.Cond = builder.Expr("org_user.org_id = `user`.id")
|
||||
|
||||
// If Admin - they see all users!
|
||||
if !opts.Actor.IsAdmin {
|
||||
// Force visibility for privacy
|
||||
var accessCond builder.Cond
|
||||
if !opts.Actor.IsRestricted {
|
||||
accessCond = builder.Or(
|
||||
builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
|
||||
builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
|
||||
} else {
|
||||
// restricted users only see orgs they are a member of
|
||||
accessCond = builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID})))
|
||||
}
|
||||
// Don't forget about self
|
||||
accessCond = accessCond.Or(builder.Eq{"id": opts.Actor.ID})
|
||||
cond = cond.And(accessCond)
|
||||
}
|
||||
|
||||
} else {
|
||||
// Force visibility for privacy
|
||||
// Not logged in - only public users
|
||||
cond = cond.And(builder.In("visibility", structs.VisibleTypePublic))
|
||||
}
|
||||
cond = cond.And(BuildCanSeeUserCondition(opts.Actor))
|
||||
|
||||
if opts.UID > 0 {
|
||||
cond = cond.And(builder.Eq{"id": opts.UID})
|
||||
@@ -149,24 +124,25 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
|
||||
return users, count, sessQuery.Find(&users)
|
||||
}
|
||||
|
||||
// IterateUser iterate users
|
||||
func IterateUser(f func(user *User) error) error {
|
||||
var start int
|
||||
batchSize := setting.Database.IterateBufferSize
|
||||
for {
|
||||
users := make([]*User, 0, batchSize)
|
||||
if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(users)
|
||||
|
||||
for _, user := range users {
|
||||
if err := f(user); err != nil {
|
||||
return err
|
||||
// BuildCanSeeUserCondition creates a condition which can be used to restrict results to users/orgs the actor can see
|
||||
func BuildCanSeeUserCondition(actor *User) builder.Cond {
|
||||
if actor != nil {
|
||||
// If Admin - they see all users!
|
||||
if !actor.IsAdmin {
|
||||
// Users can see an organization they are a member of
|
||||
cond := builder.In("`user`.id", builder.Select("org_id").From("org_user").Where(builder.Eq{"uid": actor.ID}))
|
||||
if !actor.IsRestricted {
|
||||
// Not-Restricted users can see public and limited users/organizations
|
||||
cond = cond.Or(builder.In("`user`.visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
|
||||
}
|
||||
// Don't forget about self
|
||||
return cond.Or(builder.Eq{"`user`.id": actor.ID})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Force visibility for privacy
|
||||
// Not logged in - only public users
|
||||
return builder.In("`user`.visibility", structs.VisibleTypePublic)
|
||||
}
|
||||
|
||||
@@ -399,6 +399,10 @@ func CreateWebhook(ctx context.Context, w *Webhook) error {
|
||||
|
||||
// CreateWebhooks creates multiple web hooks
|
||||
func CreateWebhooks(ctx context.Context, ws []*Webhook) error {
|
||||
// xorm returns err "no element on slice when insert" for empty slices.
|
||||
if len(ws) == 0 {
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < len(ws); i++ {
|
||||
ws[i].Type = strings.TrimSpace(ws[i].Type)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/httpcache"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web/middleware"
|
||||
@@ -268,6 +269,7 @@ func APIContexter() func(http.Handler) http.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
|
||||
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
|
||||
|
||||
ctx.Data["Context"] = &ctx
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
mc "code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/httpcache"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -223,7 +224,7 @@ func (ctx *Context) HTML(status int, name base.TplName) {
|
||||
ctx.Data["TemplateLoadTimes"] = func() string {
|
||||
return strconv.FormatInt(time.Since(tmplStartTime).Nanoseconds()/1e6, 10) + "ms"
|
||||
}
|
||||
if err := ctx.Render.HTML(ctx.Resp, status, string(name), ctx.Data); err != nil {
|
||||
if err := ctx.Render.HTML(ctx.Resp, status, string(name), templates.BaseVars().Merge(ctx.Data)); err != nil {
|
||||
if status == http.StatusInternalServerError && name == base.TplName("status/500") {
|
||||
ctx.PlainText(http.StatusInternalServerError, "Unable to find status/500 template")
|
||||
return
|
||||
@@ -767,6 +768,7 @@ func Contexter() func(next http.Handler) http.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
|
||||
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
|
||||
|
||||
ctx.Data["CsrfToken"] = ctx.csrf.GetToken()
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
@@ -52,14 +53,30 @@ func packageAssignment(ctx *Context, errCb func(int, string, interface{})) {
|
||||
}
|
||||
|
||||
if ctx.Package.Owner.IsOrganization() {
|
||||
org := organization.OrgFromUser(ctx.Package.Owner)
|
||||
|
||||
// 1. Get user max authorize level for the org (may be none, if user is not member of the org)
|
||||
if ctx.Doer != nil {
|
||||
var err error
|
||||
ctx.Package.AccessMode, err = organization.OrgFromUser(ctx.Package.Owner).GetOrgUserMaxAuthorizeLevel(ctx.Doer.ID)
|
||||
ctx.Package.AccessMode, err = org.GetOrgUserMaxAuthorizeLevel(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
errCb(http.StatusInternalServerError, "GetOrgUserMaxAuthorizeLevel", err)
|
||||
return
|
||||
}
|
||||
// If access mode is less than write check every team for more permissions
|
||||
if ctx.Package.AccessMode < perm.AccessModeWrite {
|
||||
teams, err := organization.GetUserOrgTeams(ctx, org.ID, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
errCb(http.StatusInternalServerError, "GetUserOrgTeams", err)
|
||||
return
|
||||
}
|
||||
for _, t := range teams {
|
||||
perm := t.UnitAccessModeCtx(ctx, unit.TypePackages)
|
||||
if ctx.Package.AccessMode < perm {
|
||||
ctx.Package.AccessMode = perm
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2. If authorize level is none, check if org is visible to user
|
||||
if ctx.Package.AccessMode == perm.AccessModeNone && organization.HasOrgOrUserVisible(ctx, ctx.Package.Owner, ctx.Doer) {
|
||||
|
||||
@@ -986,6 +986,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||
}
|
||||
|
||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||
ctx.Data["RefName"] = ctx.Repo.RefName
|
||||
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
|
||||
ctx.Data["TagName"] = ctx.Repo.TagName
|
||||
ctx.Data["CommitID"] = ctx.Repo.CommitID
|
||||
|
||||
@@ -101,6 +101,12 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
|
||||
}
|
||||
|
||||
if c.Time != nil {
|
||||
err = c.Time.LoadAttributes()
|
||||
if err != nil {
|
||||
log.Error("Time.LoadAttributes: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
comment.TrackedTime = ToTrackedTime(c.Time)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,29 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// From time to time Gitea makes changes to the reserved usernames and which symbols
|
||||
// are allowed for various reasons. This check helps with detecting users that, according
|
||||
// to our reserved names, don't have a valid username.
|
||||
func checkUserName(ctx context.Context, logger log.Logger, _ bool) error {
|
||||
var invalidUserCount int64
|
||||
if err := iterateUserAccounts(ctx, func(u *user.User) error {
|
||||
if err := user.IsUsableUsername(u.Name); err != nil {
|
||||
invalidUserCount++
|
||||
logger.Warn("User[id=%d] does not have a valid username: %v", u.ID, err)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("iterateUserAccounts: %v", err)
|
||||
}
|
||||
|
||||
if invalidUserCount == 0 {
|
||||
logger.Info("All users have a valid username.")
|
||||
} else {
|
||||
logger.Warn("%d user(s) have a non-valid username.", invalidUserCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&Check{
|
||||
Title: "Check if users has an valid email address",
|
||||
@@ -66,4 +89,11 @@ func init() {
|
||||
Run: checkUserEmail,
|
||||
Priority: 9,
|
||||
})
|
||||
Register(&Check{
|
||||
Title: "Check if users have a valid username",
|
||||
Name: "check-user-names",
|
||||
IsDefault: false,
|
||||
Run: checkUserName,
|
||||
Priority: 9,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
@@ -49,7 +50,11 @@ func initDBDisableConsole(ctx context.Context, disableConsole bool) error {
|
||||
|
||||
setting.NewXORMLogService(disableConsole)
|
||||
if err := db.InitEngine(ctx); err != nil {
|
||||
return fmt.Errorf("models.SetEngine: %v", err)
|
||||
return fmt.Errorf("db.InitEngine: %w", err)
|
||||
}
|
||||
// some doctor sub-commands need to use git command
|
||||
if err := git.InitOnceWithSync(ctx); err != nil {
|
||||
return fmt.Errorf("git.InitOnceWithSync: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -95,14 +95,15 @@ func (c *Command) AddArguments(args ...string) *Command {
|
||||
return c
|
||||
}
|
||||
|
||||
// RunOpts represents parameters to run the command
|
||||
// RunOpts represents parameters to run the command. If UseContextTimeout is specified, then Timeout is ignored.
|
||||
type RunOpts struct {
|
||||
Env []string
|
||||
Timeout time.Duration
|
||||
Dir string
|
||||
Stdout, Stderr io.Writer
|
||||
Stdin io.Reader
|
||||
PipelineFunc func(context.Context, context.CancelFunc) error
|
||||
Env []string
|
||||
Timeout time.Duration
|
||||
UseContextTimeout bool
|
||||
Dir string
|
||||
Stdout, Stderr io.Writer
|
||||
Stdin io.Reader
|
||||
PipelineFunc func(context.Context, context.CancelFunc) error
|
||||
}
|
||||
|
||||
func commonBaseEnvs() []string {
|
||||
@@ -171,7 +172,15 @@ func (c *Command) Run(opts *RunOpts) error {
|
||||
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(args, " "), opts.Dir)
|
||||
}
|
||||
|
||||
ctx, cancel, finished := process.GetManager().AddContextTimeout(c.parentContext, opts.Timeout, desc)
|
||||
var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
var finished context.CancelFunc
|
||||
|
||||
if opts.UseContextTimeout {
|
||||
ctx, cancel, finished = process.GetManager().AddContext(c.parentContext, desc)
|
||||
} else {
|
||||
ctx, cancel, finished = process.GetManager().AddContextTimeout(c.parentContext, opts.Timeout, desc)
|
||||
}
|
||||
defer finished()
|
||||
|
||||
cmd := exec.CommandContext(ctx, c.name, c.args...)
|
||||
|
||||
@@ -287,7 +287,20 @@ func syncGitConfig() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
// By default partial clones are disabled, enable them from git v2.22
|
||||
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
|
||||
if err = configSet("uploadpack.allowfilter", "true"); err != nil {
|
||||
return err
|
||||
}
|
||||
err = configSet("uploadpack.allowAnySHA1InWant", "true")
|
||||
} else {
|
||||
if err = configUnsetAll("uploadpack.allowfilter", "true"); err != nil {
|
||||
return err
|
||||
}
|
||||
err = configUnsetAll("uploadpack.allowAnySHA1InWant", "true")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CheckGitVersionAtLeast check git version is at least the constraint version
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
package git
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// RemotePrefix is the base directory of the remotes information of git.
|
||||
@@ -15,6 +18,29 @@ const (
|
||||
pullLen = len(PullPrefix)
|
||||
)
|
||||
|
||||
// refNamePatternInvalid is regular expression with unallowed characters in git reference name
|
||||
// They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.
|
||||
// They cannot have question-mark ?, asterisk *, or open bracket [ anywhere
|
||||
var refNamePatternInvalid = regexp.MustCompile(
|
||||
`[\000-\037\177 \\~^:?*[]|` + // No absolutely invalid characters
|
||||
`(?:^[/.])|` + // Not HasPrefix("/") or "."
|
||||
`(?:/\.)|` + // no "/."
|
||||
`(?:\.lock$)|(?:\.lock/)|` + // No ".lock/"" or ".lock" at the end
|
||||
`(?:\.\.)|` + // no ".." anywhere
|
||||
`(?://)|` + // no "//" anywhere
|
||||
`(?:@{)|` + // no "@{"
|
||||
`(?:[/.]$)|` + // no terminal '/' or '.'
|
||||
`(?:^@$)`) // Not "@"
|
||||
|
||||
// IsValidRefPattern ensures that the provided string could be a valid reference
|
||||
func IsValidRefPattern(name string) bool {
|
||||
return !refNamePatternInvalid.MatchString(name)
|
||||
}
|
||||
|
||||
func SanitizeRefPattern(name string) string {
|
||||
return refNamePatternInvalid.ReplaceAllString(name, "_")
|
||||
}
|
||||
|
||||
// Reference represents a Git ref.
|
||||
type Reference struct {
|
||||
Name string
|
||||
|
||||
@@ -138,7 +138,7 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
|
||||
|
||||
// ConvertToSHA1 returns a Hash object from a potential ID string
|
||||
func (repo *Repository) ConvertToSHA1(commitID string) (SHA1, error) {
|
||||
if len(commitID) == 40 && SHAPattern.MatchString(commitID) {
|
||||
if len(commitID) == 40 && IsValidSHAPattern(commitID) {
|
||||
sha1, err := NewIDFromString(commitID)
|
||||
if err == nil {
|
||||
return sha1, nil
|
||||
|
||||
@@ -40,7 +40,7 @@ func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, stri
|
||||
if tmpRemote != "origin" {
|
||||
tmpBaseName := RemotePrefix + tmpRemote + "/tmp_" + base
|
||||
// Fetch commit into a temporary branch in order to be able to handle commits and tags
|
||||
_, _, err := NewCommand(repo.Ctx, "fetch", tmpRemote, base+":"+tmpBaseName).RunStdString(&RunOpts{Dir: repo.Path})
|
||||
_, _, err := NewCommand(repo.Ctx, "fetch", "--no-tags", tmpRemote, "--", base+":"+tmpBaseName).RunStdString(&RunOpts{Dir: repo.Path})
|
||||
if err == nil {
|
||||
base = tmpBaseName
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ const EmptySHA = "0000000000000000000000000000000000000000"
|
||||
const EmptyTreeSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||
|
||||
// SHAPattern can be used to determine if a string is an valid sha
|
||||
var SHAPattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
|
||||
var shaPattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
|
||||
|
||||
// IsValidSHAPattern will check if the provided string matches the SHA Pattern
|
||||
func IsValidSHAPattern(sha string) bool {
|
||||
return shaPattern.MatchString(sha)
|
||||
}
|
||||
|
||||
// MustID always creates a new SHA1 from a [20]byte array with no validation of input.
|
||||
func MustID(b []byte) SHA1 {
|
||||
|
||||
@@ -114,9 +114,9 @@ func (g *Manager) start() {
|
||||
// Execute makes Manager implement svc.Handler
|
||||
func (g *Manager) Execute(args []string, changes <-chan svc.ChangeRequest, status chan<- svc.Status) (svcSpecificEC bool, exitCode uint32) {
|
||||
if setting.StartupTimeout > 0 {
|
||||
status <- svc.Status{State: svc.StartPending}
|
||||
} else {
|
||||
status <- svc.Status{State: svc.StartPending, WaitHint: uint32(setting.StartupTimeout / time.Millisecond)}
|
||||
} else {
|
||||
status <- svc.Status{State: svc.StartPending}
|
||||
}
|
||||
|
||||
log.Trace("Awaiting server start-up")
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
// don't index files larger than this many bytes for performance purposes
|
||||
const sizeLimit = 1000000
|
||||
const sizeLimit = 1024 * 1024
|
||||
|
||||
var (
|
||||
// For custom user mapping
|
||||
@@ -58,7 +58,7 @@ func NewContext() {
|
||||
func Code(fileName, language, code string) string {
|
||||
NewContext()
|
||||
|
||||
// diff view newline will be passed as empty, change to literal \n so it can be copied
|
||||
// diff view newline will be passed as empty, change to literal '\n' so it can be copied
|
||||
// preserve literal newline in blame view
|
||||
if code == "" || code == "\n" {
|
||||
return "\n"
|
||||
@@ -104,6 +104,11 @@ func Code(fileName, language, code string) string {
|
||||
return CodeFromLexer(lexer, code)
|
||||
}
|
||||
|
||||
type nopPreWrapper struct{}
|
||||
|
||||
func (nopPreWrapper) Start(code bool, styleAttr string) string { return "" }
|
||||
func (nopPreWrapper) End(code bool) string { return "" }
|
||||
|
||||
// CodeFromLexer returns a HTML version of code string with chroma syntax highlighting classes
|
||||
func CodeFromLexer(lexer chroma.Lexer, code string) string {
|
||||
formatter := html.New(html.WithClasses(true),
|
||||
@@ -126,9 +131,9 @@ func CodeFromLexer(lexer chroma.Lexer, code string) string {
|
||||
return code
|
||||
}
|
||||
|
||||
htmlw.Flush()
|
||||
_ = htmlw.Flush()
|
||||
// Chroma will add newlines for certain lexers in order to highlight them properly
|
||||
// Once highlighted, strip them here so they don't cause copy/paste trouble in HTML output
|
||||
// Once highlighted, strip them here, so they don't cause copy/paste trouble in HTML output
|
||||
return strings.TrimSuffix(htmlbuf.String(), "\n")
|
||||
}
|
||||
|
||||
@@ -141,7 +146,7 @@ func File(numLines int, fileName, language string, code []byte) []string {
|
||||
}
|
||||
formatter := html.New(html.WithClasses(true),
|
||||
html.WithLineNumbers(false),
|
||||
html.PreventSurroundingPre(true),
|
||||
html.WithPreWrapper(nopPreWrapper{}),
|
||||
)
|
||||
|
||||
if formatter == nil {
|
||||
@@ -189,27 +194,19 @@ func File(numLines int, fileName, language string, code []byte) []string {
|
||||
return plainText(string(code), numLines)
|
||||
}
|
||||
|
||||
htmlw.Flush()
|
||||
_ = htmlw.Flush()
|
||||
finalNewLine := false
|
||||
if len(code) > 0 {
|
||||
finalNewLine = code[len(code)-1] == '\n'
|
||||
}
|
||||
|
||||
m := make([]string, 0, numLines)
|
||||
for _, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) {
|
||||
content := string(v)
|
||||
// need to keep lines that are only \n so copy/paste works properly in browser
|
||||
if content == "" {
|
||||
content = "\n"
|
||||
} else if content == `</span><span class="w">` {
|
||||
content += "\n</span>"
|
||||
} else if content == `</span></span><span class="line"><span class="cl">` {
|
||||
content += "\n"
|
||||
}
|
||||
content = strings.TrimSuffix(content, `<span class="w">`)
|
||||
content = strings.TrimPrefix(content, `</span>`)
|
||||
m = append(m, content)
|
||||
m := strings.SplitN(htmlbuf.String(), `</span></span><span class="line"><span class="cl">`, numLines)
|
||||
if len(m) > 0 {
|
||||
m[0] = m[0][len(`<span class="line"><span class="cl">`):]
|
||||
last := m[len(m)-1]
|
||||
m[len(m)-1] = last[:len(last)-len(`</span></span>`)]
|
||||
}
|
||||
|
||||
if finalNewLine {
|
||||
m = append(m, "<span class=\"w\">\n</span>")
|
||||
}
|
||||
@@ -219,14 +216,14 @@ func File(numLines int, fileName, language string, code []byte) []string {
|
||||
|
||||
// return unhiglighted map
|
||||
func plainText(code string, numLines int) []string {
|
||||
m := make([]string, 0, numLines)
|
||||
for _, v := range strings.SplitN(string(code), "\n", numLines) {
|
||||
content := string(v)
|
||||
m := strings.SplitN(code, "\n", numLines)
|
||||
|
||||
for i, content := range m {
|
||||
// need to keep lines that are only \n so copy/paste works properly in browser
|
||||
if content == "" {
|
||||
content = "\n"
|
||||
}
|
||||
m = append(m, gohtml.EscapeString(content))
|
||||
m[i] = gohtml.EscapeString(content)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -43,18 +43,29 @@ func TestFile(t *testing.T) {
|
||||
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
|
||||
`),
|
||||
want: util.Dedent(`
|
||||
<span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default</span>
|
||||
</span></span><span class="line"><span class="cl">
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">steps</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">environment</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">commands</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go build -v</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go test -v -race -coverprofile=coverage.txt -covermode=atomic</span></span></span>
|
||||
<span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default</span><span class="w">
|
||||
</span>
|
||||
<span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="nt">steps</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">environment</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">commands</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span>- <span class="l">go build -v</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span>- <span class="l">go test -v -race -coverprofile=coverage.txt -covermode=atomic</span>
|
||||
`),
|
||||
},
|
||||
{
|
||||
@@ -76,19 +87,30 @@ func TestFile(t *testing.T) {
|
||||
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
|
||||
`)+"\n", "name: default", "name: default ", 1),
|
||||
want: util.Dedent(`
|
||||
<span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default </span>
|
||||
</span></span><span class="line"><span class="cl">
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">steps</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">environment</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">commands</span><span class="p">:</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go build -v</span>
|
||||
</span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go test -v -race -coverprofile=coverage.txt -covermode=atomic</span>
|
||||
</span></span>
|
||||
<span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default </span><span class="w">
|
||||
</span>
|
||||
<span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="nt">steps</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">environment</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span><span class="nt">commands</span><span class="p">:</span><span class="w">
|
||||
</span>
|
||||
<span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span>- <span class="l">go build -v</span><span class="w">
|
||||
</span>
|
||||
<span class="w"> </span>- <span class="l">go test -v -race -coverprofile=coverage.txt -covermode=atomic</span><span class="w">
|
||||
</span>
|
||||
<span class="w">
|
||||
</span>
|
||||
`),
|
||||
|
||||
@@ -78,6 +78,11 @@ func (hl *HostMatchList) AppendBuiltin(builtin string) {
|
||||
hl.builtins = append(hl.builtins, builtin)
|
||||
}
|
||||
|
||||
// AppendPattern appends more pattern to match
|
||||
func (hl *HostMatchList) AppendPattern(pattern string) {
|
||||
hl.patterns = append(hl.patterns, pattern)
|
||||
}
|
||||
|
||||
// IsEmpty checks if the checklist is empty
|
||||
func (hl *HostMatchList) IsEmpty() bool {
|
||||
return hl == nil || (len(hl.builtins) == 0 && len(hl.patterns) == 0 && len(hl.ipNets) == 0)
|
||||
|
||||
@@ -17,16 +17,23 @@ import (
|
||||
)
|
||||
|
||||
// AddCacheControlToHeader adds suitable cache-control headers to response
|
||||
func AddCacheControlToHeader(h http.Header, d time.Duration) {
|
||||
func AddCacheControlToHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) {
|
||||
directives := make([]string, 0, 2+len(additionalDirectives))
|
||||
|
||||
if setting.IsProd {
|
||||
h.Set("Cache-Control", "private, max-age="+strconv.Itoa(int(d.Seconds())))
|
||||
if maxAge == 0 {
|
||||
directives = append(directives, "no-store")
|
||||
} else {
|
||||
directives = append(directives, "private", "max-age="+strconv.Itoa(int(maxAge.Seconds())))
|
||||
}
|
||||
} else {
|
||||
h.Set("Cache-Control", "no-store")
|
||||
directives = append(directives, "no-store")
|
||||
|
||||
// to remind users they are using non-prod setting.
|
||||
// some users may be confused by "Cache-Control: no-store" in their setup if they did wrong to `RUN_MODE` in `app.ini`.
|
||||
h.Add("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
|
||||
h.Add("X-Gitea-Debug", "CacheControl=no-store")
|
||||
}
|
||||
|
||||
h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", "))
|
||||
}
|
||||
|
||||
// generateETag generates an ETag based on size, filename and file modification time
|
||||
|
||||
@@ -33,7 +33,7 @@ func newLogger(name string, buffer int64) *MultiChannelledLogger {
|
||||
func (l *MultiChannelledLogger) SetLogger(name, provider, config string) error {
|
||||
eventLogger, err := NewChannelledLog(l.ctx, name, provider, config, l.bufferLength)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create sublogger (%s): %v", name, err)
|
||||
return fmt.Errorf("failed to create sublogger (%s): %w", name, err)
|
||||
}
|
||||
|
||||
l.MultiChannelledLog.DelLogger(name)
|
||||
@@ -41,9 +41,9 @@ func (l *MultiChannelledLogger) SetLogger(name, provider, config string) error {
|
||||
err = l.MultiChannelledLog.AddLogger(eventLogger)
|
||||
if err != nil {
|
||||
if IsErrDuplicateName(err) {
|
||||
return fmt.Errorf("Duplicate named sublogger %s %v", name, l.MultiChannelledLog.GetEventLoggerNames())
|
||||
return fmt.Errorf("%w other names: %v", err, l.MultiChannelledLog.GetEventLoggerNames())
|
||||
}
|
||||
return fmt.Errorf("Failed to add sublogger (%s): %v", name, err)
|
||||
return fmt.Errorf("failed to add sublogger (%s): %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -26,7 +26,7 @@ type PullRequest struct {
|
||||
Updated time.Time
|
||||
Closed *time.Time
|
||||
Labels []*Label
|
||||
PatchURL string `yaml:"patch_url"`
|
||||
PatchURL string `yaml:"patch_url"` // SECURITY: This must be safe to download directly from
|
||||
Merged bool
|
||||
MergedTime *time.Time `yaml:"merged_time"`
|
||||
MergeCommitSHA string `yaml:"merge_commit_sha"`
|
||||
@@ -37,6 +37,7 @@ type PullRequest struct {
|
||||
Reactions []*Reaction
|
||||
ForeignIndex int64
|
||||
Context DownloaderContext `yaml:"-"`
|
||||
EnsuredSafe bool `yaml:"ensured_safe"`
|
||||
}
|
||||
|
||||
func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
|
||||
@@ -55,9 +56,9 @@ func (p PullRequest) GetGitRefName() string {
|
||||
|
||||
// PullRequestBranch represents a pull request branch
|
||||
type PullRequestBranch struct {
|
||||
CloneURL string `yaml:"clone_url"`
|
||||
Ref string
|
||||
SHA string
|
||||
CloneURL string `yaml:"clone_url"` // SECURITY: This must be safe to download from
|
||||
Ref string // SECURITY: this must be a git.IsValidRefPattern
|
||||
SHA string // SECURITY: this must be a git.IsValidSHAPattern
|
||||
RepoName string `yaml:"repo_name"`
|
||||
OwnerName string `yaml:"owner_name"`
|
||||
}
|
||||
|
||||
@@ -18,15 +18,16 @@ type ReleaseAsset struct {
|
||||
DownloadCount *int `yaml:"download_count"`
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
DownloadURL *string `yaml:"download_url"`
|
||||
|
||||
DownloadURL *string `yaml:"download_url"` // SECURITY: It is the responsibility of downloader to make sure this is safe
|
||||
// if DownloadURL is nil, the function should be invoked
|
||||
DownloadFunc func() (io.ReadCloser, error) `yaml:"-"`
|
||||
DownloadFunc func() (io.ReadCloser, error) `yaml:"-"` // SECURITY: It is the responsibility of downloader to make sure this is safe
|
||||
}
|
||||
|
||||
// Release represents a release
|
||||
type Release struct {
|
||||
TagName string `yaml:"tag_name"`
|
||||
TargetCommitish string `yaml:"target_commitish"`
|
||||
TagName string `yaml:"tag_name"` // SECURITY: This must pass git.IsValidRefPattern
|
||||
TargetCommitish string `yaml:"target_commitish"` // SECURITY: This must pass git.IsValidRefPattern
|
||||
Name string
|
||||
Body string
|
||||
Draft bool
|
||||
|
||||
@@ -12,7 +12,7 @@ type Repository struct {
|
||||
IsPrivate bool `yaml:"is_private"`
|
||||
IsMirror bool `yaml:"is_mirror"`
|
||||
Description string
|
||||
CloneURL string `yaml:"clone_url"`
|
||||
CloneURL string `yaml:"clone_url"` // SECURITY: This must be checked to ensure that is safe to be used
|
||||
OriginalURL string `yaml:"original_url"`
|
||||
DefaultBranch string
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ func getRedisTLSOptions(uri *url.URL) *tls.Config {
|
||||
|
||||
if len(skipverify) > 0 {
|
||||
skipverify, err := strconv.ParseBool(skipverify)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
tlsConfig.InsecureSkipVerify = skipverify
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func getRedisTLSOptions(uri *url.URL) *tls.Config {
|
||||
|
||||
if len(insecureskipverify) > 0 {
|
||||
insecureskipverify, err := strconv.ParseBool(insecureskipverify)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
tlsConfig.InsecureSkipVerify = insecureskipverify
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,24 @@ func TestRedisPasswordOpt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkipVerifyOpt(t *testing.T) {
|
||||
uri, _ := url.Parse("rediss://myredis/0?skipverify=true")
|
||||
tlsConfig := getRedisTLSOptions(uri)
|
||||
|
||||
if !tlsConfig.InsecureSkipVerify {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsecureSkipVerifyOpt(t *testing.T) {
|
||||
uri, _ := url.Parse("rediss://myredis/0?insecureskipverify=true")
|
||||
tlsConfig := getRedisTLSOptions(uri)
|
||||
|
||||
if !tlsConfig.InsecureSkipVerify {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedisSentinelUsernameOpt(t *testing.T) {
|
||||
uri, _ := url.Parse("redis+sentinel://redis:password@myredis/0?sentinelusername=suser&sentinelpassword=spass")
|
||||
opts := getRedisOptions(uri).Failover()
|
||||
|
||||
@@ -8,10 +8,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
goversion "github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -56,7 +55,9 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
|
||||
if !namePattern.MatchString(name) {
|
||||
return nil, ErrValidation
|
||||
}
|
||||
if _, err := goversion.NewSemver(version); err != nil {
|
||||
|
||||
v := strings.TrimSpace(version)
|
||||
if v == "" {
|
||||
return nil, ErrValidation
|
||||
}
|
||||
if user != "" && !namePattern.MatchString(user) {
|
||||
@@ -69,7 +70,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
|
||||
return nil, ErrValidation
|
||||
}
|
||||
|
||||
return &RecipeReference{name, version, user, channel, revision}, nil
|
||||
return &RecipeReference{name, v, user, channel, revision}, nil
|
||||
}
|
||||
|
||||
func (r *RecipeReference) RevisionOrDefault() string {
|
||||
|
||||
@@ -34,6 +34,7 @@ func TestNewRecipeReference(t *testing.T) {
|
||||
{"name", "1.0", "_", "_", "", true},
|
||||
{"name", "1.0", "_", "_", "0", true},
|
||||
{"name", "1.0", "", "", "0", true},
|
||||
{"name", "1.0.0q", "", "", "0", true},
|
||||
{"name", "1.0", "", "", "000000000000000000000000000000000000000000000000000000000000", false},
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
PropertyRepository = "container.repository"
|
||||
PropertyDigest = "container.digest"
|
||||
PropertyMediaType = "container.mediatype"
|
||||
PropertyManifestTagged = "container.manifest.tagged"
|
||||
|
||||
@@ -27,21 +27,21 @@ func NewContentStore() *ContentStore {
|
||||
|
||||
// Get gets a package blob
|
||||
func (s *ContentStore) Get(key BlobHash256Key) (storage.Object, error) {
|
||||
return s.store.Open(keyToRelativePath(key))
|
||||
return s.store.Open(KeyToRelativePath(key))
|
||||
}
|
||||
|
||||
// Save stores a package blob
|
||||
func (s *ContentStore) Save(key BlobHash256Key, r io.Reader, size int64) error {
|
||||
_, err := s.store.Save(keyToRelativePath(key), r, size)
|
||||
_, err := s.store.Save(KeyToRelativePath(key), r, size)
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete deletes a package blob
|
||||
func (s *ContentStore) Delete(key BlobHash256Key) error {
|
||||
return s.store.Delete(keyToRelativePath(key))
|
||||
return s.store.Delete(KeyToRelativePath(key))
|
||||
}
|
||||
|
||||
// keyToRelativePath converts the sha256 key aabb000000... to aa/bb/aabb000000...
|
||||
func keyToRelativePath(key BlobHash256Key) string {
|
||||
// KeyToRelativePath converts the sha256 key aabb000000... to aa/bb/aabb000000...
|
||||
func KeyToRelativePath(key BlobHash256Key) string {
|
||||
return path.Join(string(key)[0:2], string(key)[2:4], string(key))
|
||||
}
|
||||
|
||||
47
modules/packages/hashed_buffer_test.go
Normal file
47
modules/packages/hashed_buffer_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package packages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHashedBuffer(t *testing.T) {
|
||||
cases := []struct {
|
||||
MaxMemorySize int
|
||||
Data string
|
||||
HashMD5 string
|
||||
HashSHA1 string
|
||||
HashSHA256 string
|
||||
HashSHA512 string
|
||||
}{
|
||||
{5, "test", "098f6bcd4621d373cade4e832627b4f6", "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"},
|
||||
{5, "testtest", "05a671c66aefea124cc08b76ea6d30bb", "51abb9636078defbf888d8457a7c76f85c8f114c", "37268335dd6931045bdcdf92623ff819a64244b53d0e746d438797349d4da578", "125d6d03b32c84d492747f79cf0bf6e179d287f341384eb5d6d3197525ad6be8e6df0116032935698f99a09e265073d1d6c32c274591bf1d0a20ad67cba921bc"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
buf, err := CreateHashedBufferFromReader(strings.NewReader(c.Data), c.MaxMemorySize)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, len(c.Data), buf.Size())
|
||||
|
||||
data, err := io.ReadAll(buf)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, c.Data, string(data))
|
||||
|
||||
hashMD5, hashSHA1, hashSHA256, hashSHA512 := buf.Sums()
|
||||
assert.Equal(t, c.HashMD5, fmt.Sprintf("%x", hashMD5))
|
||||
assert.Equal(t, c.HashSHA1, fmt.Sprintf("%x", hashSHA1))
|
||||
assert.Equal(t, c.HashSHA256, fmt.Sprintf("%x", hashSHA256))
|
||||
assert.Equal(t, c.HashSHA512, fmt.Sprintf("%x", hashSHA512))
|
||||
|
||||
assert.NoError(t, buf.Close())
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,6 @@ type gemspec struct {
|
||||
VersionRequirements requirement `yaml:"version_requirements"`
|
||||
} `yaml:"dependencies"`
|
||||
Description string `yaml:"description"`
|
||||
Email string `yaml:"email"`
|
||||
Executables []string `yaml:"executables"`
|
||||
Extensions []interface{} `yaml:"extensions"`
|
||||
ExtraRdocFiles []string `yaml:"extra_rdoc_files"`
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -153,6 +154,10 @@ func createDelegateHooks(repoPath string) (err error) {
|
||||
}
|
||||
|
||||
func checkExecutable(filename string) bool {
|
||||
// windows has no concept of a executable bit
|
||||
if runtime.GOOS == "windows" {
|
||||
return true
|
||||
}
|
||||
fileInfo, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
return false
|
||||
|
||||
@@ -48,6 +48,7 @@ var (
|
||||
DefaultBranch string
|
||||
AllowAdoptionOfUnadoptedRepositories bool
|
||||
AllowDeleteOfUnadoptedRepositories bool
|
||||
DisableDownloadSourceArchives bool
|
||||
|
||||
// Repository editor settings
|
||||
Editor struct {
|
||||
|
||||
@@ -91,6 +91,8 @@ var (
|
||||
// LocalURL is the url for locally running applications to contact Gitea. It always has a '/' suffix
|
||||
// It maps to ini:"LOCAL_ROOT_URL"
|
||||
LocalURL string
|
||||
// AssetVersion holds a opaque value that is used for cache-busting assets
|
||||
AssetVersion string
|
||||
|
||||
// Server settings
|
||||
Protocol Scheme
|
||||
@@ -749,6 +751,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
|
||||
}
|
||||
|
||||
AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefix)
|
||||
AssetVersion = strings.ReplaceAll(AppVer, "+", "~") // make sure the version string is clear (no real escaping is needed)
|
||||
|
||||
manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL)
|
||||
ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
func Init() error {
|
||||
if setting.SSH.Disabled {
|
||||
builtinUnused()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -74,11 +75,21 @@ func sessionHandler(session ssh.Session) {
|
||||
ctx, cancel := context.WithCancel(session.Context())
|
||||
defer cancel()
|
||||
|
||||
gitProtocol := ""
|
||||
for _, env := range session.Environ() {
|
||||
if strings.HasPrefix(env, "GIT_PROTOCOL=") {
|
||||
// The value would be version=2, so using normal split doesn't work here.
|
||||
gitProtocol = strings.SplitN(env, "=", 2)[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, setting.AppPath, args...)
|
||||
cmd.Env = append(
|
||||
os.Environ(),
|
||||
"SSH_ORIGINAL_COMMAND="+command,
|
||||
"SKIP_MINWINSVC=1",
|
||||
"GIT_PROTOCOL="+gitProtocol,
|
||||
)
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
@@ -142,10 +153,14 @@ func sessionHandler(session ssh.Session) {
|
||||
// Wait for the command to exit and log any errors we get
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
log.Error("SSH: Wait: %v", err)
|
||||
// Cannot use errors.Is here because ExitError doesn't implement Is
|
||||
// Thus errors.Is will do equality test NOT type comparison
|
||||
if _, ok := err.(*exec.ExitError); !ok {
|
||||
log.Error("SSH: Wait: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := session.Exit(getExitStatusFromError(err)); err != nil {
|
||||
if err := session.Exit(getExitStatusFromError(err)); err != nil && !errors.Is(err, io.EOF) {
|
||||
log.Error("Session failed to exit. %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ type SubmitPullReviewOptions struct {
|
||||
// DismissPullReviewOptions are options to dismiss a pull review
|
||||
type DismissPullReviewOptions struct {
|
||||
Message string `json:"message"`
|
||||
Priors bool `json:"priors"`
|
||||
}
|
||||
|
||||
// PullReviewRequestOptions are options to add or remove pull review requests
|
||||
|
||||
@@ -35,10 +35,11 @@ func BaseVars() Vars {
|
||||
"IsLandingPageExplore": setting.LandingPageURL == setting.LandingPageExplore,
|
||||
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
|
||||
|
||||
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
||||
"ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage,
|
||||
"ShowFooterBranding": setting.ShowFooterBranding,
|
||||
"ShowFooterVersion": setting.ShowFooterVersion,
|
||||
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
||||
"ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage,
|
||||
"ShowFooterBranding": setting.ShowFooterBranding,
|
||||
"ShowFooterVersion": setting.ShowFooterVersion,
|
||||
"DisableDownloadSourceArchives": setting.Repository.DisableDownloadSourceArchives,
|
||||
|
||||
"EnableSwagger": setting.API.EnableSwagger,
|
||||
"EnableOpenIDSignIn": setting.Service.EnableOpenIDSignIn,
|
||||
|
||||
@@ -81,6 +81,9 @@ func NewFuncMap() []template.FuncMap {
|
||||
"AppDomain": func() string {
|
||||
return setting.Domain
|
||||
},
|
||||
"AssetVersion": func() string {
|
||||
return setting.AssetVersion
|
||||
},
|
||||
"DisableGravatar": func() bool {
|
||||
return setting.DisableGravatar
|
||||
},
|
||||
@@ -151,7 +154,6 @@ func NewFuncMap() []template.FuncMap {
|
||||
"DiffTypeToStr": DiffTypeToStr,
|
||||
"DiffLineTypeToStr": DiffLineTypeToStr,
|
||||
"ShortSha": base.ShortSha,
|
||||
"MD5": base.EncodeMD5,
|
||||
"ActionContent2Commits": ActionContent2Commits,
|
||||
"PathEscape": url.PathEscape,
|
||||
"PathEscapeSegments": util.PathEscapeSegments,
|
||||
@@ -454,6 +456,7 @@ func NewFuncMap() []template.FuncMap {
|
||||
}
|
||||
return items
|
||||
},
|
||||
"HasPrefix": strings.HasPrefix,
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -974,11 +977,11 @@ type remoteAddress struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
|
||||
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string, ignoreOriginalURL bool) remoteAddress {
|
||||
a := remoteAddress{}
|
||||
|
||||
remoteURL := m.OriginalURL
|
||||
if remoteURL == "" {
|
||||
if ignoreOriginalURL || remoteURL == "" {
|
||||
var err error
|
||||
remoteURL, err = git.GetRemoteAddress(ctx, m.RepoPath(), remoteName)
|
||||
if err != nil {
|
||||
|
||||
@@ -54,6 +54,11 @@ func (ts TimeStamp) AsTime() (tm time.Time) {
|
||||
return ts.AsTimeInLocation(setting.DefaultUILocation)
|
||||
}
|
||||
|
||||
// AsLocalTime convert timestamp as time.Time in local location
|
||||
func (ts TimeStamp) AsLocalTime() time.Time {
|
||||
return time.Unix(int64(ts), 0)
|
||||
}
|
||||
|
||||
// AsTimeInLocation convert timestamp as time.Time in Local locale
|
||||
func (ts TimeStamp) AsTimeInLocation(loc *time.Location) (tm time.Time) {
|
||||
tm = time.Unix(int64(ts), 0).In(loc)
|
||||
|
||||
@@ -70,6 +70,16 @@ func (ct SniffedType) IsRepresentableAsText() bool {
|
||||
return ct.IsText() || ct.IsSvgImage()
|
||||
}
|
||||
|
||||
// IsBrowsableType returns whether a non-text type can be displayed in a browser
|
||||
func (ct SniffedType) IsBrowsableBinaryType() bool {
|
||||
return ct.IsImage() || ct.IsSvgImage() || ct.IsPDF() || ct.IsVideo() || ct.IsAudio()
|
||||
}
|
||||
|
||||
// GetMimeType returns the mime type
|
||||
func (ct SniffedType) GetMimeType() string {
|
||||
return strings.SplitN(ct.contentType, ";", 2)[0]
|
||||
}
|
||||
|
||||
// DetectContentType extends http.DetectContentType with more content types. Defaults to text/unknown if input is empty.
|
||||
func DetectContentType(data []byte) SniffedType {
|
||||
if len(data) == 0 {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user