Skip to content

Commit a991026

Browse files
oklopferook37
andauthored
fix(api): recipe + maintainer repology endpoints (#1344)
Co-authored-by: ook37 <oren+12345@taumoda.com>
1 parent 6915287 commit a991026

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

client/public/api-spec.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,17 @@ components:
443443
type: string
444444
example: '16.0.1'
445445
maintainer:
446-
type: object
447-
properties:
448-
name:
449-
type: string
450-
example: 'John Doe'
451-
email:
452-
type: string
453-
nullable: true
454-
example: 'john.doe@pacstall.dev'
446+
type: array
447+
description: 'Note that this array can be empty, indicating an orphaned package.'
448+
items:
449+
type: object
450+
properties:
451+
name:
452+
type: string
453+
example: 'John Doe'
454+
email:
455+
type: string
456+
example: 'john.doe@pacstall.dev'
455457
description:
456458
type: string
457459
example: 'Helper application for Linux distributions.'

server/server/api/repology/types.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
)
99

1010
type maintainerDetails struct {
11-
Name *string `json:"name"`
12-
Email *string `json:"email"`
11+
Name *string `json:"name,omitempty"`
12+
Email *string `json:"email,omitempty"`
1313
}
1414

1515
type repologyPackage struct {
1616
Name string `json:"name"`
1717
VisibleName string `json:"visibleName"`
1818
Description string `json:"description"`
19-
Maintainer maintainerDetails `json:"maintainer"`
19+
Maintainer []maintainerDetails `json:"maintainer"`
2020
Version string `json:"version"`
2121
URL []pac.ArchDistroString `json:"url"`
2222
RecipeURL string `json:"recipeUrl"`
@@ -29,33 +29,31 @@ func newRepologyPackage(p *pac.Script) repologyPackage {
2929
Name: p.PackageName,
3030
VisibleName: p.PrettyName,
3131
Description: p.Description,
32-
Maintainer: getMaintainer(p),
32+
Maintainer: getMaintainers(p),
3333
Version: p.Version,
3434
URL: p.Source,
3535
Type: string(p.Type()),
36-
RecipeURL: fmt.Sprintf("https://raw.githubusercontent.com/pacstall/pacstall-programs/master/packages/%s/%s.pacscript", p.PackageName, p.PackageName),
36+
RecipeURL: fmt.Sprintf("https://raw.githubusercontent.com/pacstall/pacstall-programs/master/packages/%s/%s.pacscript", p.PackageBase, p.PackageBase),
3737
PackageDetailsURL: fmt.Sprintf("https://pacstall.dev/packages/%s", p.PackageName),
3838
}
3939
}
4040

41-
func getMaintainer(p *pac.Script) maintainerDetails {
42-
maintainer := ""
43-
if len(p.Maintainers) > 0 {
44-
maintainer = p.Maintainers[0]
45-
}
41+
func getMaintainers(p *pac.Script) []maintainerDetails {
42+
maintainers := make([]maintainerDetails, 0, len(p.Maintainers))
4643

47-
if !strings.Contains(maintainer, "<") {
48-
return maintainerDetails{
49-
Name: &maintainer,
44+
for _, m := range p.Maintainers {
45+
var name, email string
46+
if i := strings.Index(m, "<"); i != -1 && strings.HasSuffix(m, ">") {
47+
name = strings.TrimSpace(m[:i])
48+
email = strings.TrimSpace(m[i+1 : len(m)-1])
49+
} else {
50+
name = strings.TrimSpace(m)
5051
}
52+
maintainers = append(maintainers, maintainerDetails{
53+
Name: &name,
54+
Email: &email,
55+
})
5156
}
5257

53-
parts := strings.Split(maintainer, "<")
54-
name := strings.TrimSpace(parts[0])
55-
email := strings.TrimSpace(strings.Replace(parts[1], ">", "", -1))
56-
57-
return maintainerDetails{
58-
Name: &name,
59-
Email: &email,
60-
}
58+
return maintainers
6159
}

0 commit comments

Comments
 (0)