Skip to content

Commit a19bb1f

Browse files
committed
convert pullrequest object to a generic one
this is in preparation to codeberg prs support Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 3deeacf commit a19bb1f

File tree

11 files changed

+403
-358
lines changed

11 files changed

+403
-358
lines changed

pkg/app/handler/categories/show.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ func ShowPullRequests(w http.ResponseWriter, r *http.Request) {
9494
return
9595
}
9696

97-
var pullRequests []*models.GithubPullRequest
97+
var pullRequests []*models.PullRequest
9898
err = database.DBCon.Model(&pullRequests).
99-
Join("JOIN package_to_github_pull_requests ON package_to_github_pull_requests.github_pull_request_id = github_pull_request.id").
100-
Where("package_to_github_pull_requests.package_atom LIKE ?", categoryName+"/%").
101-
Group("github_pull_request.id").
102-
Order("github_pull_request.created_at DESC").
99+
Join("JOIN package_to_pull_requests ON package_to_pull_requests.pull_request_id = pull_request.id").
100+
Where("package_to_pull_requests.package_atom LIKE ?", categoryName+"/%").
101+
Group("pull_request.id").
102+
Order("pull_request.created_at DESC").
103103
Select()
104104
if err != nil {
105105
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)

pkg/app/handler/maintainer/show.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ func ShowPullRequests(w http.ResponseWriter, r *http.Request) {
159159
if err != nil {
160160
return
161161
}
162-
var pullRequests []*models.GithubPullRequest
162+
var pullRequests []*models.PullRequest
163163
err = database.DBCon.Model(&pullRequests).
164-
DistinctOn("github_pull_request.id").
165-
OrderExpr("github_pull_request.id DESC").
166-
Join("JOIN package_to_github_pull_requests").JoinOn("github_pull_request.id = package_to_github_pull_requests.github_pull_request_id").
164+
DistinctOn("pull_request.id").
165+
OrderExpr("pull_request.id DESC").
166+
Join("JOIN package_to_pull_requests").JoinOn("pull_request.id = package_to_pull_requests.pull_request_id").
167167
Where("package_atom IN (?)", query).
168168
Select()
169169
if err != nil {

pkg/app/handler/packages/components/pullrequests.templ

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package components
44
import (
55
"soko/pkg/models"
66
"strconv"
7+
"strings"
78
)
89

910
css badgeColor(color string) {
@@ -15,7 +16,11 @@ func isDarkBadgeColor(color string) bool {
1516
return color == "5319e7" || color == "0052cc" || color == "b60205"
1617
}
1718

18-
templ PullRequests(pullRequests []*models.GithubPullRequest) {
19+
var prTypeToURL = map[string]string{
20+
"github": "https://github.com/gentoo/gentoo/pull/",
21+
}
22+
23+
templ PullRequests(pullRequests []*models.PullRequest) {
1924
<div class="row">
2025
<div class="col-md-9">
2126
if len(pullRequests) > 0 {
@@ -26,7 +31,8 @@ templ PullRequests(pullRequests []*models.GithubPullRequest) {
2631
<div class="row">
2732
<div class="col-md-11">
2833
<span class="octicon octicon-git-pull-request opticon-resource-icon ml-1" style="color:SeaGreen;"></span>
29-
<a href={ templ.URL("https://github.com/gentoo/gentoo/pull/" + pr.Id) } class="text-dark">
34+
{{ prType, id, _ := strings.Cut(pr.Id, "/") }}
35+
<a href={ templ.URL(prTypeToURL[prType] + id) } class="text-dark">
3036
<b>{ pr.Title }</b>
3137
</a>
3238
<a href={ templ.URL(pr.CiStateLink) }>
@@ -50,14 +56,14 @@ templ PullRequests(pullRequests []*models.GithubPullRequest) {
5056
}
5157
</div>
5258
<div class="col-md-1 text-right">
53-
<a href={ templ.URL("https://github.com/gentoo/gentoo/pull/" + pr.Id) } class="text-muted">
59+
<a href={ templ.URL(prTypeToURL[prType] + id) } class="text-muted">
5460
<i class="fa fa-comment-o" aria-hidden="true"></i>
5561
{ strconv.Itoa(pr.Comments) }
5662
</a>
5763
</div>
5864
<div class="col-md-12 text-muted">
5965
<span style="font-size: 90%;">
60-
#{ pr.Id } opened { pr.CreatedAt } by { pr.Author }
66+
#{ id } opened { pr.CreatedAt } by { pr.Author }
6167
</span>
6268
</div>
6369
</div>

pkg/database/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func CreateSchema() error {
3131
(*models.CommitToVersion)(nil),
3232
(*models.PackageToBug)(nil),
3333
(*models.VersionToBug)(nil),
34-
(*models.PackageToGithubPullRequest)(nil),
34+
(*models.PackageToPullRequest)(nil),
3535
(*models.MaskToVersion)(nil),
3636
(*models.DeprecatedToVersion)(nil),
3737
(*models.Package)(nil),
@@ -48,7 +48,7 @@ func CreateSchema() error {
4848
(*models.Project)(nil),
4949
(*models.MaintainerToProject)(nil),
5050
(*models.PkgCheckResult)(nil),
51-
(*models.GithubPullRequest)(nil),
51+
(*models.PullRequest)(nil),
5252
(*models.Bug)(nil),
5353
(*models.ReverseDependency)(nil),
5454
(*models.Maintainer)(nil),

pkg/models/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Package struct {
2323
PkgCheckResults []*PkgCheckResult `pg:",fk:atom,rel:has-many"`
2424
Outdated []*OutdatedPackages `pg:",fk:atom,rel:has-many"`
2525
Bugs []*Bug `pg:"many2many:package_to_bugs,join_fk:bug_id"`
26-
PullRequests []*GithubPullRequest `pg:"many2many:package_to_github_pull_requests,join_fk:github_pull_request_id"`
26+
PullRequests []*PullRequest `pg:"many2many:package_to_pull_requests,join_fk:pull_request_id"`
2727
ReverseDependencies []*ReverseDependency `pg:",fk:atom,rel:has-many"`
2828
}
2929

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
package models
33

4-
type GithubPullRequest struct {
4+
import "iter"
5+
6+
type PullRequest struct {
57
Id string `pg:",pk"`
68
Closed bool
79
Url string
@@ -10,18 +12,23 @@ type GithubPullRequest struct {
1012
UpdatedAt string
1113
CiState string
1214
CiStateLink string
13-
Labels []GitHubPullRequestLabelNode
15+
Labels []PullRequestLabel
1416
Comments int
1517
Author string
1618
}
1719

18-
type PackageToGithubPullRequest struct {
19-
Id string `pg:",pk"`
20-
PackageAtom string
21-
GithubPullRequestId string
20+
type PackageToPullRequest struct {
21+
Id string `pg:",pk"`
22+
PackageAtom string
23+
PullRequestId string
2224
}
2325

24-
type GitHubPullRequestLabelNode struct {
26+
type PullRequestLabel struct {
2527
Name string `json:"name"`
2628
Color string `json:"color"`
2729
}
30+
31+
type PullRequestProvider interface {
32+
ToPullRequest() *PullRequest
33+
GetFiles() iter.Seq[string]
34+
}

0 commit comments

Comments
 (0)