aboutsummaryrefslogtreecommitdiff
blob: fa3b33f77b06496285e24c2cd6ec6ca9d499b84d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package packages

import "strconv"
import "soko/pkg/app/handler/packages/components"
import "soko/pkg/app/layout"
import "soko/pkg/models"

func showViewTabs(pkg *models.Package) []layout.SubTab {
	securityBugs, nonSecurityBugs := countBugs(pkg)
	return []layout.SubTab{
		{
			Name: "Overview",
			Link: templ.URL("/packages/" + pkg.Atom),
			Icon: "fa fa-info mr-1",
		},
		{
			Name: "Dependencies",
			Link: templ.URL("/packages/" + pkg.Atom + "/dependencies"),
			Icon: "fa fa-link",
		},
		{
			Name: "QA report",
			Link: templ.URL("/packages/" + pkg.Atom + "/qa-report"),
			Icon: "fa fa-fw fa-chain-broken",
		},
		{
			Name:       "Pull requests",
			Link:       templ.URL("/packages/" + pkg.Atom + "/pull-requests"),
			Icon:       "octicon octicon-git-pull-request opticon-resource-icon ml-1",
			BadgeValue: strconv.Itoa(len(pkg.PullRequests)),
		},
		{
			Name:       "Bugs",
			Link:       templ.URL("/packages/" + pkg.Atom + "/bugs"),
			Icon:       "fa fa-bug",
			BadgeValue: strconv.Itoa(nonSecurityBugs),
		},
		{
			Name:       "Security",
			Link:       templ.URL("/packages/" + pkg.Atom + "/security"),
			Icon:       "fa fa-shield",
			BadgeValue: strconv.Itoa(securityBugs),
		},
		{
			Name: "Changelog",
			Link: templ.URL("/packages/" + pkg.Atom + "/changelog"),
			Icon: "fa fa-fw fa-history",
		},
	}
}

templ tabbedHeader(pkg *models.Package, currentSubTab string) {
	<div class="kk-header-container">
		<div class="container">
			<div class="row">
				<div class="col-12">
					<div class="row mt-3">
						<div class="col-md-5">
							<h1 class="stick-top kk-package-title" id="package-title" data-atom={ pkg.Atom } data-category={ pkg.Category } data-name={ pkg.Name }>
								<small class="kk-package-cat">
									<a href={ templ.URL("/categories/" + pkg.Category) } class="text-dark">{ pkg.Category }</a>/
								</small>
								<div>
									<svg height="32" class="octicon octicon-package right left kk-package-icon" aria-label="Package icon" viewBox="0 0 16 16" version="1.1" width="32" role="img"><path fill-rule="evenodd" d="M1 4.27v7.47c0 .45.3.84.75.97l6.5 1.73c.16.05.34.05.5 0l6.5-1.73c.45-.13.75-.52.75-.97V4.27c0-.45-.3-.84-.75-.97l-6.5-1.74a1.4 1.4 0 0 0-.5 0L1.75 3.3c-.45.13-.75.52-.75.97zm7 9.09l-6-1.59V5l6 1.61v6.75zM2 4l2.5-.67L11 5.06l-2.5.67L2 4zm13 7.77l-6 1.59V6.61l2-.55V8.5l2-.53V5.53L15 5v6.77zm-2-7.24L6.5 2.8l2-.53L15 4l-2 .53z"></path></svg>
									<div class="kk-package-name">{ pkg.Name }</div>
								</div>
							</h1>
						</div>
						<div class="col-md-7">
							<p class="lead kk-package-maindesc">{ pkg.Description() }</p>
							if len(pkg.Versions[0].Homepage) > 0 {
								<p class="kk-package-homepage">
									<a href={ templ.URL(pkg.Versions[0].Homepage[0]) }>{ pkg.Versions[0].Homepage[0] }</a>
								</p>
							}
						</div>
						<div class="col-md-12 pt-4 mt-1">
							<nav class="nav kk-package-nav">
								for _, tab := range showViewTabs(pkg) {
									<a class={ "nav-link", templ.KV("active", tab.Name == currentSubTab) } href={ tab.Link }>
										<i class={ tab.Icon } aria-hidden="true"></i> { tab.Name }
										if tab.BadgeValue != "" {
											<span class="ml-1 badge badge-pill kk-misc-badge">{ tab.BadgeValue }</span>
										}
									</a>
								}
							</nav>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
}

func collectAllBugs(pkg *models.Package) (atom string, generalCount, stabilizationCount, keywordingCount int, bugs []*models.Bug) {
	atom = pkg.Atom
	bugs = make([]*models.Bug, 0, len(pkg.Bugs))
	handled := make(map[string]struct{}, len(pkg.Bugs))
	for _, bug := range pkg.Bugs {
		if bug.Component == "Current packages" {
			generalCount++
			bugs = append(bugs, bug)
			handled[bug.Id] = struct{}{}
		}
	}
	for _, ver := range pkg.Versions {
		for _, bug := range ver.Bugs {
			if _, found := handled[bug.Id]; found {
				continue
			}
			if bug.Component == "Stabilization" {
				stabilizationCount++
				bugs = append(bugs, bug)
			} else if bug.Component == "Keywording" {
				keywordingCount++
				bugs = append(bugs, bug)
			}
			handled[bug.Id] = struct{}{}
		}
	}
	return
}

func collectSecurityBugs(pkg *models.Package) (string, []*models.Bug) {
	bugs := make([]*models.Bug, 0, len(pkg.Bugs))
	for _, bug := range pkg.Bugs {
		if bug.Component == "Vulnerabilities" {
			bugs = append(bugs, bug)
		}
	}
	return pkg.Atom, bugs
}

templ show(pkg *models.Package, currentSubTab string, userPreferences models.UserPreferences) {
	if currentSubTab == "Reverse Dependencies" {
		@tabbedHeader(pkg, "Dependencies")
	} else {
		@tabbedHeader(pkg, currentSubTab)
	}
	<div class="tab-content" id="myTabContent">
		<div class="container mb-5 tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
			switch currentSubTab {
				case "QA report":
					@qaReport(pkg)
				case "Pull requests":
					@components.PullRequests(pkg.PullRequests)
				case "Bugs":
					@components.Bugs(collectAllBugs(pkg))
				case "Security":
					@components.SecurityBugs(collectSecurityBugs(pkg))
				case "Changelog":
					@components.Changelog(pkg.Atom, pkg.Commits)
				case "Dependencies":
					@dependencies(pkg)
				case "Reverse Dependencies":
					@reverseDependencies(pkg)
				default:
					@overview(pkg, &userPreferences)
			}
		</div>
	</div>
}