Skip to content

Commit 660bab9

Browse files
authored
Merge pull request #50 from achilleas-k/repolist-split
Nice and pretty
2 parents 4a8fb2a + d107dd6 commit 660bab9

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

internal/resources/templates/generic_results.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const GenericResults = `
2424
<div class="ui tabs divider"></div>
2525
</div>
2626
<div class="ui container">
27-
<hr>
28-
<div>
29-
<pre>
30-
{{.Content}}
31-
</pre>
27+
<hr>
28+
<div>
29+
<pre>{{.Content}}</pre>
30+
</div>
31+
</div>
3232
</div>
3333
{{end}}
3434
`

internal/resources/templates/repolist.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const RepoList = `
66
77
<div class="explore repositories">
88
<div class="ui container repository list">
9-
{{range .}}
9+
{{range .Active}}
1010
{{$repopath := .FullName}}
1111
<div class="item">
1212
<div class="ui grid">
@@ -31,6 +31,25 @@ const RepoList = `
3131
</div>
3232
</div>
3333
{{end}}
34+
<hr>
35+
<h2>Inactive repositories</h2>
36+
{{range .Inactive}}
37+
{{$repopath := .FullName}}
38+
<div class="item">
39+
<div class="ui grid">
40+
<div class="ui two wide column middle aligned center">
41+
<i class="mega-octicon octicon-repo"></i>
42+
</div>
43+
<div class="ui fourteen wide column">
44+
<div class="ui header">
45+
<a class="name" href="/repos/{{$repopath}}/hooks">{{$repopath}}</a>
46+
</div>
47+
<p class="has-emoji">{{.Description}}</p>
48+
<a href="{{.HTMLURL}}">Repository on GIN</a> | <a href="{{.HTMLURL}}/settings/hooks">Repository hooks</a>
49+
</div>
50+
</div>
51+
</div>
52+
{{end}}
3453
</div>
3554
</div>
3655
{{end}}

internal/web/user.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,41 @@ func ListRepos(w http.ResponseWriter, r *http.Request) {
264264
fail(w, http.StatusInternalServerError, "something went wrong")
265265
return
266266
}
267-
repos := make([]repoHooksInfo, len(userrepos))
267+
reposActive := make([]repoHooksInfo, 0, len(userrepos))
268+
reposInactive := make([]repoHooksInfo, 0, len(userrepos))
269+
270+
checkActive := func(rhinfo repoHooksInfo) bool {
271+
// If at least one hook is not hooknone, return true
272+
for _, hook := range rhinfo.Hooks {
273+
if hook.State != hooknone {
274+
return true
275+
}
276+
}
277+
return false
278+
}
268279

269280
// TODO: Enum for hook states (see issue #5)
270-
for idx, rinfo := range userrepos {
281+
for _, rinfo := range userrepos {
271282
repohooks, err := getRepoHooks(cl, rinfo.FullName)
272283
if err != nil {
273284
// simply initialise the map for now
274285
repohooks = make(map[string]ginhook)
275286
}
276-
repos[idx] = repoHooksInfo{rinfo, repohooks}
287+
rhinfo := repoHooksInfo{rinfo, repohooks}
288+
if checkActive(rhinfo) {
289+
reposActive = append(reposActive, rhinfo)
290+
} else {
291+
reposInactive = append(reposInactive, rhinfo)
292+
}
293+
}
294+
allrepos := struct {
295+
Active []repoHooksInfo
296+
Inactive []repoHooksInfo
297+
}{
298+
reposActive,
299+
reposInactive,
277300
}
278-
tmpl.Execute(w, &repos)
301+
tmpl.Execute(w, &allrepos)
279302
}
280303

281304
// matchValidator receives a URL path from a GIN hook and returns the validator
@@ -362,7 +385,7 @@ func getRepoHooks(cl *ginclient.Client, repopath string) (map[string]ginhook, er
362385
hooks[validator] = ginhook{validator, hook.ID, state}
363386
// TODO: Check if the same validator is found twice
364387
}
365-
// add supported validators that were not found and mark them disabled
388+
// add supported validators that were not found and mark them hooknone
366389
supportedValidators := config.Read().Settings.Validators
367390
for _, validator := range supportedValidators {
368391
if _, ok := hooks[validator]; !ok {

0 commit comments

Comments
 (0)