aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-09-09 14:41:35 +0200
committerMax Magorsch <arzano@gentoo.org>2020-09-09 14:41:35 +0200
commit527c1e69e674388acf16cefb423f9b8baad84a67 (patch)
tree19e38e675138dea536bc9f2e3aa3f31d3c4b3a80
parentHandle empty restricts correctly (diff)
downloadsoko-527c1e69e674388acf16cefb423f9b8baad84a67.tar.gz
soko-527c1e69e674388acf16cefb423f9b8baad84a67.tar.bz2
soko-527c1e69e674388acf16cefb423f9b8baad84a67.zip
Add links to upstream remotes
Thanks to sbraz for the suggestion. Closes: https://bugs.gentoo.org/657018 Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/app/handler/packages/utils.go37
-rw-r--r--pkg/models/package.go6
-rw-r--r--pkg/portage/repository/package.go21
-rw-r--r--web/templates/packages/metadata.tmpl20
4 files changed, 84 insertions, 0 deletions
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index d4f8752..fc5f904 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -200,6 +200,7 @@ func GetFuncMap() template.FuncMap {
"getReverse": getReverse,
"tolower": strings.ToLower,
"formatRestricts": FormatRestricts,
+ "RemoteIdLink": RemoteIdLink,
"isMasked": isMasked,
"getMask": getMask,
"showRemovalNotice": showRemovalNotice,
@@ -354,6 +355,42 @@ func FormatRestricts(restricts []string) string {
return strings.Join(result, ", ")
}
+// RemoteIdLink returns a link to the homepage of a given remote id
+func RemoteIdLink(remoteId models.RemoteId) string {
+ switch remoteId.Type {
+ case "cpan-module":
+ return "https://metacpan.org/pod/" + remoteId.Id
+ case "cpan":
+ return "https://metacpan.org/release/" + remoteId.Id
+ case "github":
+ return "https://github.com/" + remoteId.Id
+ case "sourceforge":
+ return "https://sourceforge.net/projects/" + remoteId.Id + "/"
+ case "google-code":
+ return "https://code.google.com/archive/p/" + remoteId.Id + "/"
+ case "bitbucket":
+ return "https://bitbucket.org/" + remoteId.Id
+ case "pypi":
+ return "https://pypi.org/project/" + remoteId.Id + "/"
+ case "launchpad":
+ return "https://launchpad.net/" + remoteId.Id
+ case "cpe":
+ return "https://nvd.nist.gov/products/cpe/search/results?keyword=" + remoteId.Id
+ case "sourceforge-jp":
+ return "https://sourceforge.net/projects/" + remoteId.Id + "/"
+ case "rubygems":
+ return "https://rubygems.org/gems/" + remoteId.Id + "/"
+ case "pear":
+ return "https://pear.php.net/package/" + remoteId.Id
+ case "freshmeat":
+ return "http://freshmeat.sourceforge.net/projects/" + remoteId.Id
+ case "gitlab":
+ return "https://gitlab.com/" + remoteId.Id
+ default:
+ return ""
+ }
+}
+
// isMasked returns true if any version is masked
func isMasked(versions []*models.Version) bool {
for _, version := range versions {
diff --git a/pkg/models/package.go b/pkg/models/package.go
index 5605145..ffd83d5 100644
--- a/pkg/models/package.go
+++ b/pkg/models/package.go
@@ -9,6 +9,7 @@ type Package struct {
Versions []*Version `pg:",fk:atom"`
Longdescription string
Maintainers []*Maintainer
+ Upstream []RemoteId
Commits []*Commit `pg:"many2many:commit_to_packages,joinFK:commit_id"`
PrecedingCommits int `pg:",use_zero"`
PkgCheckResults []*PkgCheckResult `pg:",fk:atom"`
@@ -33,6 +34,11 @@ type MaintainerPackagesInformation struct {
SecurityBugs int
}
+type RemoteId struct {
+ Type string
+ Id string
+}
+
func (p Package) BuildRevDepMap() map[string]map[string]string {
var data = map[string]map[string]string{}
diff --git a/pkg/portage/repository/package.go b/pkg/portage/repository/package.go
index 468da06..9b1aec2 100644
--- a/pkg/portage/repository/package.go
+++ b/pkg/portage/repository/package.go
@@ -88,12 +88,21 @@ func updateModifiedPackage(changedFile string) {
}
}
+ remoteIds := []models.RemoteId{}
+ for _, r := range pkgmetadata.Upstream.RemoteIds {
+ remoteIds = append(remoteIds, models.RemoteId{
+ Type: r.Type,
+ Id: r.Content,
+ })
+ }
+
gpackage := &models.Package{
Atom: atom,
Category: category,
Name: packagename,
Longdescription: longDescription,
Maintainers: maintainers,
+ Upstream: remoteIds,
}
_, err := database.DBCon.Model(gpackage).OnConflict("(atom) DO UPDATE").
@@ -131,6 +140,7 @@ type Pkgmetadata struct {
XMLName xml.Name `xml:"pkgmetadata"`
MaintainerList []Maintainer `xml:"maintainer"`
LongdescriptionList []LongdescriptionItem `xml:"longdescription"`
+ Upstream Upstream `xml:"upstream"`
}
type Maintainer struct {
@@ -146,3 +156,14 @@ type LongdescriptionItem struct {
Content string `xml:",chardata"`
Language string `xml:"lang,attr"`
}
+
+type Upstream struct {
+ XMLName xml.Name `xml:"upstream"`
+ RemoteIds []RemoteId `xml:"remote-id"`
+}
+
+type RemoteId struct {
+ XMLName xml.Name `xml:"remote-id"`
+ Type string `xml:"type,attr"`
+ Content string `xml:",chardata"`
+}
diff --git a/web/templates/packages/metadata.tmpl b/web/templates/packages/metadata.tmpl
index bd13395..78b3128 100644
--- a/web/templates/packages/metadata.tmpl
+++ b/web/templates/packages/metadata.tmpl
@@ -20,6 +20,26 @@
</li>
{{end}}
+ {{ if .Package.Upstream }}
+ <li class="kk-metadata-item list-group-item">
+ <div class="row">
+ <div class="col-xs-12 col-md-3 kk-metadata-key">
+ <span class="fa fa-fw fa-code-fork"></span>
+ Upstream
+ </div>
+ <div class="col-xs-12 col-md-9">
+ {{range $k, $v := .Package.Upstream}}
+ {{ $link := RemoteIdLink . }}
+ {{if not (eq $link "")}}
+ <a href="{{ $link}}">{{ $link }}</a>
+ {{if not (eq $k (len $.Package.Upstream))}}<br/>{{end}}
+ {{end}}
+ {{end}}
+ </div>
+ </div>
+ </li>
+ {{end}}
+
{{ if .Package.Longdescription }}
<li class="kk-metadata-item list-group-item">
<div class="row">