Skip to content

Commit a15d976

Browse files
committed
Merge branch 'main' into add-issue-planned-time
2 parents 13982d5 + 171edfc commit a15d976

File tree

8 files changed

+88
-48
lines changed

8 files changed

+88
-48
lines changed

routers/api/packages/api.go

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -610,40 +610,46 @@ func CommonRoutes() *web.Router {
610610
}, reqPackageAccess(perm.AccessModeWrite))
611611
}, reqPackageAccess(perm.AccessModeRead))
612612
r.Group("/swift", func() {
613-
r.Group("/{scope}/{name}", func() {
614-
r.Group("", func() {
615-
r.Get("", swift.EnumeratePackageVersions)
616-
r.Get(".json", swift.EnumeratePackageVersions)
617-
}, swift.CheckAcceptMediaType(swift.AcceptJSON))
618-
r.Group("/{version}", func() {
619-
r.Get("/Package.swift", swift.CheckAcceptMediaType(swift.AcceptSwift), swift.DownloadManifest)
620-
r.Put("", reqPackageAccess(perm.AccessModeWrite), swift.CheckAcceptMediaType(swift.AcceptJSON), swift.UploadPackageFile)
621-
r.Get("", func(ctx *context.Context) {
622-
// Can't use normal routes here: https://github.com/go-chi/chi/issues/781
623-
624-
version := ctx.PathParam("version")
625-
if strings.HasSuffix(version, ".zip") {
626-
swift.CheckAcceptMediaType(swift.AcceptZip)(ctx)
627-
if ctx.Written() {
628-
return
629-
}
630-
ctx.SetPathParam("version", version[:len(version)-4])
631-
swift.DownloadPackageFile(ctx)
632-
} else {
633-
swift.CheckAcceptMediaType(swift.AcceptJSON)(ctx)
634-
if ctx.Written() {
635-
return
636-
}
637-
if strings.HasSuffix(version, ".json") {
638-
ctx.SetPathParam("version", version[:len(version)-5])
613+
r.Group("", func() { // Needs to be unauthenticated.
614+
r.Post("", swift.CheckAuthenticate)
615+
r.Post("/login", swift.CheckAuthenticate)
616+
})
617+
r.Group("", func() {
618+
r.Group("/{scope}/{name}", func() {
619+
r.Group("", func() {
620+
r.Get("", swift.EnumeratePackageVersions)
621+
r.Get(".json", swift.EnumeratePackageVersions)
622+
}, swift.CheckAcceptMediaType(swift.AcceptJSON))
623+
r.Group("/{version}", func() {
624+
r.Get("/Package.swift", swift.CheckAcceptMediaType(swift.AcceptSwift), swift.DownloadManifest)
625+
r.Put("", reqPackageAccess(perm.AccessModeWrite), swift.CheckAcceptMediaType(swift.AcceptJSON), swift.UploadPackageFile)
626+
r.Get("", func(ctx *context.Context) {
627+
// Can't use normal routes here: https://github.com/go-chi/chi/issues/781
628+
629+
version := ctx.PathParam("version")
630+
if strings.HasSuffix(version, ".zip") {
631+
swift.CheckAcceptMediaType(swift.AcceptZip)(ctx)
632+
if ctx.Written() {
633+
return
634+
}
635+
ctx.SetPathParam("version", version[:len(version)-4])
636+
swift.DownloadPackageFile(ctx)
637+
} else {
638+
swift.CheckAcceptMediaType(swift.AcceptJSON)(ctx)
639+
if ctx.Written() {
640+
return
641+
}
642+
if strings.HasSuffix(version, ".json") {
643+
ctx.SetPathParam("version", version[:len(version)-5])
644+
}
645+
swift.PackageVersionMetadata(ctx)
639646
}
640-
swift.PackageVersionMetadata(ctx)
641-
}
647+
})
642648
})
643649
})
644-
})
645-
r.Get("/identifiers", swift.CheckAcceptMediaType(swift.AcceptJSON), swift.LookupPackageIdentifiers)
646-
}, reqPackageAccess(perm.AccessModeRead))
650+
r.Get("/identifiers", swift.CheckAcceptMediaType(swift.AcceptJSON), swift.LookupPackageIdentifiers)
651+
}, reqPackageAccess(perm.AccessModeRead))
652+
})
647653
r.Group("/vagrant", func() {
648654
r.Group("/authenticate", func() {
649655
r.Get("", vagrant.CheckAuthenticate)

routers/api/packages/swift/swift.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ import (
2727
"github.com/hashicorp/go-version"
2828
)
2929

30-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#35-api-versioning
30+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#35-api-versioning
3131
const (
3232
AcceptJSON = "application/vnd.swift.registry.v1+json"
3333
AcceptSwift = "application/vnd.swift.registry.v1+swift"
3434
AcceptZip = "application/vnd.swift.registry.v1+zip"
3535
)
3636

3737
var (
38-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#361-package-scope
38+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#361-package-scope
3939
scopePattern = regexp.MustCompile(`\A[a-zA-Z0-9][a-zA-Z0-9-]{0,38}\z`)
40-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#362-package-name
40+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#362-package-name
4141
namePattern = regexp.MustCompile(`\A[a-zA-Z0-9][a-zA-Z0-9-_]{0,99}\z`)
4242
)
4343

@@ -49,7 +49,7 @@ type headers struct {
4949
Link string
5050
}
5151

52-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#35-api-versioning
52+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#35-api-versioning
5353
func setResponseHeaders(resp http.ResponseWriter, h *headers) {
5454
if h.ContentType != "" {
5555
resp.Header().Set("Content-Type", h.ContentType)
@@ -69,7 +69,7 @@ func setResponseHeaders(resp http.ResponseWriter, h *headers) {
6969
}
7070
}
7171

72-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#33-error-handling
72+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#33-error-handling
7373
func apiError(ctx *context.Context, status int, obj any) {
7474
// https://www.rfc-editor.org/rfc/rfc7807
7575
type Problem struct {
@@ -91,7 +91,7 @@ func apiError(ctx *context.Context, status int, obj any) {
9191
})
9292
}
9393

94-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#35-api-versioning
94+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#35-api-versioning
9595
func CheckAcceptMediaType(requiredAcceptHeader string) func(ctx *context.Context) {
9696
return func(ctx *context.Context) {
9797
accept := ctx.Req.Header.Get("Accept")
@@ -101,6 +101,16 @@ func CheckAcceptMediaType(requiredAcceptHeader string) func(ctx *context.Context
101101
}
102102
}
103103

104+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/PackageRegistryUsage.md#registry-authentication
105+
func CheckAuthenticate(ctx *context.Context) {
106+
if ctx.Doer == nil {
107+
apiError(ctx, http.StatusUnauthorized, nil)
108+
return
109+
}
110+
111+
ctx.Status(http.StatusOK)
112+
}
113+
104114
func buildPackageID(scope, name string) string {
105115
return scope + "." + name
106116
}
@@ -113,7 +123,7 @@ type EnumeratePackageVersionsResponse struct {
113123
Releases map[string]Release `json:"releases"`
114124
}
115125

116-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#41-list-package-releases
126+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#41-list-package-releases
117127
func EnumeratePackageVersions(ctx *context.Context) {
118128
packageScope := ctx.PathParam("scope")
119129
packageName := ctx.PathParam("name")
@@ -170,7 +180,7 @@ type PackageVersionMetadataResponse struct {
170180
Metadata *swift_module.SoftwareSourceCode `json:"metadata"`
171181
}
172182

173-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#endpoint-2
183+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#endpoint-2
174184
func PackageVersionMetadata(ctx *context.Context) {
175185
id := buildPackageID(ctx.PathParam("scope"), ctx.PathParam("name"))
176186

@@ -228,7 +238,7 @@ func PackageVersionMetadata(ctx *context.Context) {
228238
})
229239
}
230240

231-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#43-fetch-manifest-for-a-package-release
241+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#43-fetch-manifest-for-a-package-release
232242
func DownloadManifest(ctx *context.Context) {
233243
packageScope := ctx.PathParam("scope")
234244
packageName := ctx.PathParam("name")
@@ -280,7 +290,7 @@ func DownloadManifest(ctx *context.Context) {
280290
})
281291
}
282292

283-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#endpoint-6
293+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#endpoint-6
284294
func UploadPackageFile(ctx *context.Context) {
285295
packageScope := ctx.PathParam("scope")
286296
packageName := ctx.PathParam("name")
@@ -379,7 +389,7 @@ func UploadPackageFile(ctx *context.Context) {
379389
ctx.Status(http.StatusCreated)
380390
}
381391

382-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#endpoint-4
392+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#endpoint-4
383393
func DownloadPackageFile(ctx *context.Context) {
384394
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeSwift, buildPackageID(ctx.PathParam("scope"), ctx.PathParam("name")), ctx.PathParam("version"))
385395
if err != nil {
@@ -420,7 +430,7 @@ type LookupPackageIdentifiersResponse struct {
420430
Identifiers []string `json:"identifiers"`
421431
}
422432

423-
// https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#endpoint-5
433+
// https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#endpoint-5
424434
func LookupPackageIdentifiers(ctx *context.Context) {
425435
url := ctx.FormTrim("url")
426436
if url == "" {

routers/web/repo/release.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"code.gitea.io/gitea/services/context/upload"
3232
"code.gitea.io/gitea/services/forms"
3333
releaseservice "code.gitea.io/gitea/services/release"
34+
repo_service "code.gitea.io/gitea/services/repository"
3435
)
3536

3637
const (
@@ -193,6 +194,8 @@ func Releases(ctx *context.Context) {
193194
pager.SetDefaultParams(ctx)
194195
ctx.Data["Page"] = pager
195196

197+
ctx.Data["LicenseFileName"] = repo_service.LicenseFileName
198+
196199
ctx.HTML(http.StatusOK, tplReleasesList)
197200
}
198201

@@ -251,6 +254,7 @@ func TagsList(ctx *context.Context) {
251254
pager.SetDefaultParams(ctx)
252255
ctx.Data["Page"] = pager
253256
ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases)
257+
ctx.Data["LicenseFileName"] = repo_service.LicenseFileName
254258

255259
ctx.HTML(http.StatusOK, tplTagsList)
256260
}

templates/repo/find/files.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<input id="repo-file-find-input" type="text" autofocus data-url-data-link="{{.DataLink}}" data-url-tree-link="{{.TreeLink}}">
1010
</div>
1111
</div>
12-
<table id="repo-find-file-table" class="ui single line table">
12+
<table id="repo-find-file-table" class="ui single line fixed table">
1313
<tbody>
1414
</tbody>
1515
</table>

templates/user/auth/signin_inner.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
</div>
4949
</form>
5050
{{end}}{{/*if .EnablePasswordSignInForm*/}}
51-
{{if and .OAuth2Providers .EnableOpenIDSignIn .EnablePasswordSignInForm}}
51+
{{$showOAuth2Methods := or .OAuth2Providers .EnableOpenIDSignIn}}
52+
{{if and $showOAuth2Methods .EnablePasswordSignInForm}}
5253
<div class="divider divider-text">{{ctx.Locale.Tr "sign_in_or"}}</div>
5354
{{end}}
54-
{{if and .OAuth2Providers .EnableOpenIDSignIn}}
55+
{{if $showOAuth2Methods}}
5556
{{template "user/auth/oauth_container" .}}
5657
{{end}}
5758
</div>

templates/user/auth/signup_inner.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
</button>
4848
</div>
4949
{{end}}
50-
51-
{{if and .OAuth2Providers .EnableOpenIDSignIn}}
50+
{{$showOAuth2Methods := or .OAuth2Providers .EnableOpenIDSignIn}}
51+
{{if $showOAuth2Methods}}
5252
<div class="divider divider-text">{{ctx.Locale.Tr "sign_in_or"}}</div>
5353
{{template "user/auth/oauth_container" .}}
5454
{{end}}

tests/integration/api_packages_swift_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ func TestPackageSwift(t *testing.T) {
4242

4343
url := fmt.Sprintf("/api/packages/%s/swift", user.Name)
4444

45+
t.Run("CheckLogin", func(t *testing.T) {
46+
defer tests.PrintCurrentTest(t)()
47+
48+
req := NewRequestWithBody(t, "POST", url, strings.NewReader(""))
49+
MakeRequest(t, req, http.StatusUnauthorized)
50+
51+
req = NewRequestWithBody(t, "POST", url, strings.NewReader("")).
52+
AddBasicAuth(user.Name)
53+
MakeRequest(t, req, http.StatusOK)
54+
55+
req = NewRequestWithBody(t, "POST", url+"/login", strings.NewReader(""))
56+
MakeRequest(t, req, http.StatusUnauthorized)
57+
58+
req = NewRequestWithBody(t, "POST", url+"/login", strings.NewReader("")).
59+
AddBasicAuth(user.Name)
60+
MakeRequest(t, req, http.StatusOK)
61+
})
62+
4563
t.Run("CheckAcceptMediaType", func(t *testing.T) {
4664
defer tests.PrintCurrentTest(t)()
4765

web_src/js/features/repo-findfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function filterRepoFiles(filter) {
9090
const span = document.createElement('span');
9191
// safely escape by using textContent
9292
span.textContent = part;
93+
span.title = span.textContent;
9394
// if the target file path is "abc/xyz", to search "bx", then the matchResult is ['a', 'b', 'c/', 'x', 'yz']
9495
// the matchResult[odd] is matched and highlighted to red.
9596
if (index % 2 === 1) span.classList.add('ui', 'text', 'red');

0 commit comments

Comments
 (0)