aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-07-08 01:27:00 +0000
committerMax Magorsch <arzano@gentoo.org>2020-07-08 01:27:00 +0000
commita75c412644372d9c588f29c83127e865fc4e4b6c (patch)
tree7c575e1f3ea7401719b02890fed9f73c8d043503
parentGo fmt the project (diff)
downloadsoko-a75c412644372d9c588f29c83127e865fc4e4b6c.tar.gz
soko-a75c412644372d9c588f29c83127e865fc4e4b6c.tar.bz2
soko-a75c412644372d9c588f29c83127e865fc4e4b6c.zip
Fix duplicatedly displayed pull requests
So far pull requests were displayed multiple times on the maintianer page if they affected more than one package. This has been fixed in this commit. Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/app/handler/maintainer/utils.go14
-rw-r--r--pkg/portage/maintainers/update.go20
-rw-r--r--web/templates/maintainer/components/pullrequests.tmpl56
3 files changed, 58 insertions, 32 deletions
diff --git a/pkg/app/handler/maintainer/utils.go b/pkg/app/handler/maintainer/utils.go
index 336550b..336f936 100644
--- a/pkg/app/handler/maintainer/utils.go
+++ b/pkg/app/handler/maintainer/utils.go
@@ -102,5 +102,19 @@ func GetFuncMap() template.FuncMap {
})
return commits
},
+ "getPullRequests": func(packages []*models.Package) []*models.GithubPullRequest{
+ pullrequestsMap := map[string]*models.GithubPullRequest{}
+ for _, gpackage := range packages {
+ for _, pr := range gpackage.PullRequests {
+ pullrequestsMap[pr.Id] = pr
+ }
+ }
+
+ var pullrequests []*models.GithubPullRequest
+ for _, pr := range pullrequestsMap {
+ pullrequests = append(pullrequests, pr)
+ }
+ return pullrequests
+ },
}
}
diff --git a/pkg/portage/maintainers/update.go b/pkg/portage/maintainers/update.go
index b1a3854..66a4a33 100644
--- a/pkg/portage/maintainers/update.go
+++ b/pkg/portage/maintainers/update.go
@@ -3,6 +3,7 @@ package maintainers
import (
"soko/pkg/database"
"soko/pkg/models"
+ "soko/pkg/utils"
"strings"
)
@@ -41,8 +42,8 @@ func FullImport() {
for _, maintainer := range maintainers {
outdated := 0
- pullRequests := 0
securityBugs := 0
+ pullrequestIds := []string{}
nonSecurityBugs := 0
for _, gpackage := range gpackages {
@@ -55,7 +56,11 @@ func FullImport() {
if found {
outdated = outdated + len(gpackage.Outdated)
- pullRequests = pullRequests + len(gpackage.PullRequests)
+
+ for _, pullRequest := range gpackage.PullRequests {
+ pullrequestIds = append(pullrequestIds, string(pullRequest.Id))
+ }
+
for _, bug := range gpackage.Bugs {
if bug.Component == "Vulnerabilities" {
securityBugs++
@@ -69,7 +74,7 @@ func FullImport() {
maintainer.PackagesInformation = models.MaintainerPackagesInformation{
Outdated: outdated,
- PullRequests: pullRequests,
+ PullRequests: len(utils.Deduplicate(pullrequestIds)),
Bugs: nonSecurityBugs,
SecurityBugs: securityBugs,
}
@@ -103,3 +108,12 @@ func deleteAllMaintainers() {
database.DBCon.Model(maintainer).WherePK().Delete()
}
}
+
+func contains(element string, elements []string) bool {
+ for _, el := range elements {
+ if element == el {
+ return true
+ }
+ }
+ return false
+}
diff --git a/web/templates/maintainer/components/pullrequests.tmpl b/web/templates/maintainer/components/pullrequests.tmpl
index 1c786bc..3cf8d8e 100644
--- a/web/templates/maintainer/components/pullrequests.tmpl
+++ b/web/templates/maintainer/components/pullrequests.tmpl
@@ -8,38 +8,36 @@
<h3 class="mb-4">Pull Requests</h3>
<ul class="list-group">
- {{range .Packages}}
- {{range .PullRequests}}
+ {{range getPullRequests .Packages}}
- <li class="list-group-item">
- <div class="row">
- <div class="col-md-11">
- <span class="octicon octicon-git-pull-request opticon-resource-icon ml-1" style="color:SeaGreen;"></span>
- <a href="https://github.com/gentoo/gentoo/pull/{{.Id}}" class="text-dark"><b>{{.Title}}</b></a>
- {{if eq .CiState "SUCCESS"}}
- <a href="{{.CiStateLink}}"><i class="fa fa-check mx-1" aria-hidden="true" style="color: SeaGreen;"></i></a>
- {{else}}
- <a href="{{.CiStateLink}}"><i class="fa fa-times mx-1" aria-hidden="true" style="color: #b60205;"></i></a>
- {{end}}
- {{range .Labels}}
- <span class="badge badge-pill badge-light p-1" style="font-weight: normal; {{if eq .Color "5319e7" "0052cc" "b60205"}}color:#FFF;{{end}} background-color: #{{.Color}}!important;">{{.Name}}</span>
- {{end}}
- </div>
- <div class="col-md-1 text-right">
- <a href="https://github.com/gentoo/gentoo/pull/{{.Id}}" class="text-muted">
- <i class="fa fa-comment-o" aria-hidden="true"></i>
- {{.Comments}}
- </a>
- </div>
- <div class="col-md-12 text-muted">
- <span style="font-size: 90%;">
- #{{.Id}} opened {{.CreatedAt}} by {{.Author}}
- </span>
- </div>
+ <li class="list-group-item">
+ <div class="row">
+ <div class="col-md-11">
+ <span class="octicon octicon-git-pull-request opticon-resource-icon ml-1" style="color:SeaGreen;"></span>
+ <a href="https://github.com/gentoo/gentoo/pull/{{.Id}}" class="text-dark"><b>{{.Title}}</b></a>
+ {{if eq .CiState "SUCCESS"}}
+ <a href="{{.CiStateLink}}"><i class="fa fa-check mx-1" aria-hidden="true" style="color: SeaGreen;"></i></a>
+ {{else}}
+ <a href="{{.CiStateLink}}"><i class="fa fa-times mx-1" aria-hidden="true" style="color: #b60205;"></i></a>
+ {{end}}
+ {{range .Labels}}
+ <span class="badge badge-pill badge-light p-1" style="font-weight: normal; {{if eq .Color "5319e7" "0052cc" "b60205"}}color:#FFF;{{end}} background-color: #{{.Color}}!important;">{{.Name}}</span>
+ {{end}}
</div>
- </li>
+ <div class="col-md-1 text-right">
+ <a href="https://github.com/gentoo/gentoo/pull/{{.Id}}" class="text-muted">
+ <i class="fa fa-comment-o" aria-hidden="true"></i>
+ {{.Comments}}
+ </a>
+ </div>
+ <div class="col-md-12 text-muted">
+ <span style="font-size: 90%;">
+ #{{.Id}} opened {{.CreatedAt}} by {{.Author}}
+ </span>
+ </div>
+ </div>
+ </li>
- {{end}}
{{end}}
</ul>