Skip to content

Commit 559295a

Browse files
authored
Merge branch 'main' into swift-package-manager-publishing-using-commandline-throws-error
2 parents 7af142a + bec9233 commit 559295a

File tree

14 files changed

+349
-97
lines changed

14 files changed

+349
-97
lines changed

modules/structs/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type Package struct {
2323

2424
// PackageFile represents a package file
2525
type PackageFile struct {
26-
ID int64 `json:"id"`
27-
Size int64
26+
ID int64 `json:"id"`
27+
Size int64 `json:"size"`
2828
Name string `json:"name"`
2929
HashMD5 string `json:"md5"`
3030
HashSHA1 string `json:"sha1"`

routers/api/v1/api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,14 +1544,19 @@ func Routes() *web.Router {
15441544
// NOTE: these are Gitea package management API - see packages.CommonRoutes and packages.DockerContainerRoutes for endpoints that implement package manager APIs
15451545
m.Group("/packages/{username}", func() {
15461546
m.Group("/{type}/{name}", func() {
1547+
m.Get("/", packages.ListPackageVersions)
1548+
15471549
m.Group("/{version}", func() {
15481550
m.Get("", packages.GetPackage)
15491551
m.Delete("", reqPackageAccess(perm.AccessModeWrite), packages.DeletePackage)
15501552
m.Get("/files", packages.ListPackageFiles)
15511553
})
15521554

1553-
m.Post("/-/link/{repo_name}", reqPackageAccess(perm.AccessModeWrite), packages.LinkPackage)
1554-
m.Post("/-/unlink", reqPackageAccess(perm.AccessModeWrite), packages.UnlinkPackage)
1555+
m.Group("/-", func() {
1556+
m.Get("/latest", packages.GetLatestPackageVersion)
1557+
m.Post("/link/{repo_name}", reqPackageAccess(perm.AccessModeWrite), packages.LinkPackage)
1558+
m.Post("/unlink", reqPackageAccess(perm.AccessModeWrite), packages.UnlinkPackage)
1559+
})
15551560
})
15561561

15571562
m.Get("/", packages.ListPackages)

routers/api/v1/packages/package.go

Lines changed: 141 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ func ListPackages(ctx *context.APIContext) {
5656

5757
listOptions := utils.GetListOptions(ctx)
5858

59-
packageType := ctx.FormTrim("type")
60-
query := ctx.FormTrim("q")
61-
62-
pvs, count, err := packages.SearchVersions(ctx, &packages.PackageSearchOptions{
59+
apiPackages, count, err := searchPackages(ctx, &packages.PackageSearchOptions{
6360
OwnerID: ctx.Package.Owner.ID,
64-
Type: packages.Type(packageType),
65-
Name: packages.SearchValue{Value: query},
61+
Type: packages.Type(ctx.FormTrim("type")),
62+
Name: packages.SearchValue{Value: ctx.FormTrim("q")},
6663
IsInternal: optional.Some(false),
6764
Paginator: &listOptions,
6865
})
@@ -71,22 +68,6 @@ func ListPackages(ctx *context.APIContext) {
7168
return
7269
}
7370

74-
pds, err := packages.GetPackageDescriptors(ctx, pvs)
75-
if err != nil {
76-
ctx.APIErrorInternal(err)
77-
return
78-
}
79-
80-
apiPackages := make([]*api.Package, 0, len(pds))
81-
for _, pd := range pds {
82-
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
83-
if err != nil {
84-
ctx.APIErrorInternal(err)
85-
return
86-
}
87-
apiPackages = append(apiPackages, apiPackage)
88-
}
89-
9071
ctx.SetLinkHeader(int(count), listOptions.PageSize)
9172
ctx.SetTotalCountHeader(count)
9273
ctx.JSON(http.StatusOK, apiPackages)
@@ -217,6 +198,121 @@ func ListPackageFiles(ctx *context.APIContext) {
217198
ctx.JSON(http.StatusOK, apiPackageFiles)
218199
}
219200

201+
// ListPackageVersions gets all versions of a package
202+
func ListPackageVersions(ctx *context.APIContext) {
203+
// swagger:operation GET /packages/{owner}/{type}/{name} package listPackageVersions
204+
// ---
205+
// summary: Gets all versions of a package
206+
// produces:
207+
// - application/json
208+
// parameters:
209+
// - name: owner
210+
// in: path
211+
// description: owner of the package
212+
// type: string
213+
// required: true
214+
// - name: type
215+
// in: path
216+
// description: type of the package
217+
// type: string
218+
// required: true
219+
// - name: name
220+
// in: path
221+
// description: name of the package
222+
// type: string
223+
// required: true
224+
// - name: page
225+
// in: query
226+
// description: page number of results to return (1-based)
227+
// type: integer
228+
// - name: limit
229+
// in: query
230+
// description: page size of results
231+
// type: integer
232+
// responses:
233+
// "200":
234+
// "$ref": "#/responses/PackageList"
235+
// "404":
236+
// "$ref": "#/responses/notFound"
237+
238+
listOptions := utils.GetListOptions(ctx)
239+
240+
apiPackages, count, err := searchPackages(ctx, &packages.PackageSearchOptions{
241+
OwnerID: ctx.Package.Owner.ID,
242+
Type: packages.Type(ctx.PathParam("type")),
243+
Name: packages.SearchValue{Value: ctx.PathParam("name"), ExactMatch: true},
244+
IsInternal: optional.Some(false),
245+
Paginator: &listOptions,
246+
})
247+
if err != nil {
248+
ctx.APIErrorInternal(err)
249+
return
250+
}
251+
252+
ctx.SetLinkHeader(int(count), listOptions.PageSize)
253+
ctx.SetTotalCountHeader(count)
254+
ctx.JSON(http.StatusOK, apiPackages)
255+
}
256+
257+
// GetLatestPackageVersion gets the latest version of a package
258+
func GetLatestPackageVersion(ctx *context.APIContext) {
259+
// swagger:operation GET /packages/{owner}/{type}/{name}/-/latest package getLatestPackageVersion
260+
// ---
261+
// summary: Gets the latest version of a package
262+
// produces:
263+
// - application/json
264+
// parameters:
265+
// - name: owner
266+
// in: path
267+
// description: owner of the package
268+
// type: string
269+
// required: true
270+
// - name: type
271+
// in: path
272+
// description: type of the package
273+
// type: string
274+
// required: true
275+
// - name: name
276+
// in: path
277+
// description: name of the package
278+
// type: string
279+
// required: true
280+
// responses:
281+
// "200":
282+
// "$ref": "#/responses/Package"
283+
// "404":
284+
// "$ref": "#/responses/notFound"
285+
286+
pvs, _, err := packages.SearchLatestVersions(ctx, &packages.PackageSearchOptions{
287+
OwnerID: ctx.Package.Owner.ID,
288+
Type: packages.Type(ctx.PathParam("type")),
289+
Name: packages.SearchValue{Value: ctx.PathParam("name"), ExactMatch: true},
290+
IsInternal: optional.Some(false),
291+
})
292+
if err != nil {
293+
ctx.APIErrorInternal(err)
294+
return
295+
}
296+
if len(pvs) == 0 {
297+
ctx.APIError(http.StatusNotFound, err)
298+
return
299+
}
300+
301+
pd, err := packages.GetPackageDescriptor(ctx, pvs[0])
302+
if err != nil {
303+
ctx.APIErrorInternal(err)
304+
return
305+
}
306+
307+
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
308+
if err != nil {
309+
ctx.APIErrorInternal(err)
310+
return
311+
}
312+
313+
ctx.JSON(http.StatusOK, apiPackage)
314+
}
315+
220316
// LinkPackage sets a repository link for a package
221317
func LinkPackage(ctx *context.APIContext) {
222318
// swagger:operation POST /packages/{owner}/{type}/{name}/-/link/{repo_name} package linkPackage
@@ -335,3 +431,26 @@ func UnlinkPackage(ctx *context.APIContext) {
335431
}
336432
ctx.Status(http.StatusNoContent)
337433
}
434+
435+
func searchPackages(ctx *context.APIContext, opts *packages.PackageSearchOptions) ([]*api.Package, int64, error) {
436+
pvs, count, err := packages.SearchVersions(ctx, opts)
437+
if err != nil {
438+
return nil, 0, err
439+
}
440+
441+
pds, err := packages.GetPackageDescriptors(ctx, pvs)
442+
if err != nil {
443+
return nil, 0, err
444+
}
445+
446+
apiPackages := make([]*api.Package, 0, len(pds))
447+
for _, pd := range pds {
448+
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
449+
if err != nil {
450+
return nil, 0, err
451+
}
452+
apiPackages = append(apiPackages, apiPackage)
453+
}
454+
455+
return apiPackages, count, nil
456+
}

routers/web/repo/blame.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
gotemplate "html/template"
99
"net/http"
1010
"net/url"
11+
"path"
1112
"strconv"
1213
"strings"
1314

@@ -69,7 +70,7 @@ func RefBlame(ctx *context.Context) {
6970
blob := entry.Blob()
7071
fileSize := blob.Size()
7172
ctx.Data["FileSize"] = fileSize
72-
ctx.Data["FileName"] = blob.Name()
73+
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
7374

7475
tplName := tplRepoViewContent
7576
if !ctx.FormBool("only_content") {
@@ -285,8 +286,7 @@ func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames
285286
if i != len(lines)-1 {
286287
line += "\n"
287288
}
288-
fileName := fmt.Sprintf("%v", ctx.Data["FileName"])
289-
line, lexerNameForLine := highlight.Code(fileName, language, line)
289+
line, lexerNameForLine := highlight.Code(path.Base(ctx.Repo.TreePath), language, line)
290290

291291
// set lexer name to the first detected lexer. this is certainly suboptimal and
292292
// we should instead highlight the whole file at once

routers/web/repo/commit.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,12 @@ func SearchCommits(ctx *context.Context) {
215215

216216
// FileHistory show a file's reversions
217217
func FileHistory(ctx *context.Context) {
218-
fileName := ctx.Repo.TreePath
219-
if len(fileName) == 0 {
218+
if ctx.Repo.TreePath == "" {
220219
Commits(ctx)
221220
return
222221
}
223222

224-
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefFullName.ShortName(), fileName) // FIXME: legacy code used ShortName
223+
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefFullName.ShortName(), ctx.Repo.TreePath)
225224
if err != nil {
226225
ctx.ServerError("FileCommitsCount", err)
227226
return
@@ -238,7 +237,7 @@ func FileHistory(ctx *context.Context) {
238237
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
239238
git.CommitsByFileAndRangeOptions{
240239
Revision: ctx.Repo.RefFullName.ShortName(), // FIXME: legacy code used ShortName
241-
File: fileName,
240+
File: ctx.Repo.TreePath,
242241
Page: page,
243242
})
244243
if err != nil {
@@ -253,7 +252,7 @@ func FileHistory(ctx *context.Context) {
253252

254253
ctx.Data["Username"] = ctx.Repo.Owner.Name
255254
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
256-
ctx.Data["FileName"] = fileName
255+
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
257256
ctx.Data["CommitCount"] = commitsCount
258257

259258
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)

routers/web/repo/editor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func editFile(ctx *context.Context, isNewFile bool) {
160160
defer dataRc.Close()
161161

162162
ctx.Data["FileSize"] = blob.Size()
163-
ctx.Data["FileName"] = blob.Name()
164163

165164
buf := make([]byte, 1024)
166165
n, _ := util.ReadAtMost(dataRc, buf)

routers/web/repo/view_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
5252

5353
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
5454
ctx.Data["FileIsSymlink"] = entry.IsLink()
55-
ctx.Data["FileName"] = blob.Name()
55+
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
5656
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
5757

5858
if ctx.Repo.TreePath == ".editorconfig" {

routers/web/repo/view_readme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
162162
defer dataRc.Close()
163163

164164
ctx.Data["FileIsText"] = fInfo.isTextFile
165-
ctx.Data["FileName"] = path.Join(subfolder, readmeFile.Name())
165+
ctx.Data["FileTreePath"] = path.Join(subfolder, readmeFile.Name())
166166
ctx.Data["FileSize"] = fInfo.fileSize
167167
ctx.Data["IsLFSFile"] = fInfo.isLFSFile
168168

templates/repo/blame.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</div>
1111
{{end}}
1212
{{end}}
13-
<div class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
13+
<div class="{{TabSizeClass .Editorconfig .FileTreePath}} non-diff-file-content">
1414
<h4 class="file-header ui top attached header tw-flex tw-items-center tw-justify-between tw-flex-wrap">
1515
<div class="file-header-left tw-flex tw-items-center tw-py-2 tw-pr-4">
1616
{{template "repo/file_info" .}}

templates/repo/commits_list.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
{{/* at the moment, wiki doesn't support these "view" links like "view at history point" */}}
7171
{{if not $.PageIsWiki}}
7272
{{/* view single file diff */}}
73-
{{if $.FileName}}
73+
{{if $.FileTreePath}}
7474
<a class="btn interact-bg tw-p-2 view-single-diff" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_file_diff"}}"
75-
href="{{$commitRepoLink}}/commit/{{.ID.String}}?files={{$.FileName}}"
75+
href="{{$commitRepoLink}}/commit/{{.ID.String}}?files={{$.FileTreePath}}"
7676
>{{svg "octicon-file-diff"}}</a>
7777
{{end}}
7878

7979
{{/* view at history point */}}
8080
{{$viewCommitLink := printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
81-
{{if $.FileName}}{{$viewCommitLink = printf "%s/%s" $viewCommitLink (PathEscapeSegments $.FileName)}}{{end}}
81+
{{if $.FileTreePath}}{{$viewCommitLink = printf "%s/%s" $viewCommitLink (PathEscapeSegments $.FileTreePath)}}{{end}}
8282
<a class="btn interact-bg tw-p-2 view-commit-path" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}" href="{{$viewCommitLink}}">{{svg "octicon-file-code"}}</a>
8383
{{end}}
8484
</td>

templates/repo/home_sidebar_top.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{{end}}
4646

4747
{{if .ReadmeExist}}
48-
<a class="flex-text-block muted" href="{{.TreeLink}}/{{.FileName}}">
48+
<a class="flex-text-block muted" href="{{.RepoLink}}/src/{{.RefTypeNameSubURL}}/{{PathEscapeSegments .FileTreePath}}">
4949
{{svg "octicon-book"}} {{ctx.Locale.Tr "readme"}}
5050
</a>
5151
{{end}}

templates/repo/view_file.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div {{if .ReadmeInList}}id="readme" {{end}}class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
1+
<div {{if .ReadmeInList}}id="readme" {{end}}class="{{TabSizeClass .Editorconfig .FileTreePath}} non-diff-file-content">
22
{{- if .FileError}}
33
<div class="ui error message">
44
<div class="text left tw-whitespace-pre">{{.FileError}}</div>
@@ -27,7 +27,7 @@
2727
<div class="file-header-left tw-flex tw-items-center tw-py-2 tw-pr-4">
2828
{{if .ReadmeInList}}
2929
{{svg "octicon-book" 16 "tw-mr-2"}}
30-
<strong><a class="muted" href="#readme">{{.FileName}}</a></strong>
30+
<strong><a class="muted" href="#readme">{{.FileTreePath}}</a></strong>
3131
{{else}}
3232
{{template "repo/file_info" .}}
3333
{{end}}
@@ -78,7 +78,7 @@
7878
<button class="ui mini basic button escape-button tw-mr-1">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
7979
{{end}}
8080
{{if and .ReadmeInList .CanEditReadmeFile}}
81-
<a class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.editor.edit_this_file"}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}/{{PathEscapeSegments .FileName}}">{{svg "octicon-pencil"}}</a>
81+
<a class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.editor.edit_this_file"}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .FileTreePath}}">{{svg "octicon-pencil"}}</a>
8282
{{end}}
8383
</div>
8484
</h4>

0 commit comments

Comments
 (0)