Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit db0b389

Browse files
committed
feat: branch and tag filters
1 parent 53c02f0 commit db0b389

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ files:
8585

8686
In the `display` section you can define how the frontend should look like.
8787

88-
You may change the `order` of tags or hide the tag date in `tags` subsection.
89-
90-
You can also toggle the display of branches or tags for the index page in the `index` subsection.
91-
9288
```yaml
9389
---
9490
display:
91+
branches:
92+
filter:
93+
- master
94+
- develop
95+
- /feature/.*/ # regex: any feature branches
9596
tags:
97+
filter: []
9698
order: desc
9799
show_date: true
98100
virtual_tags:
@@ -102,19 +104,34 @@ display:
102104
show_tags: true
103105
```
104106

107+
You may change the `order` of tags or hide the tag date in `tags` subsection.
108+
109+
You can also toggle the display of branches or tags for the index page in the `index` subsection.
110+
105111
#### Virtual tags
106112

107113
Virtual major tags will always point to the latest version inside a major release.
108114
They can be enabled by setting `display.tags.virtual_tags.enable_semver_major` to true.
109115

110116
This only will consider semantic versions.
111117

112-
_Example:_ Given the versions v1.0.0, v1.1.0, v2.0.0, two virtual tags "v1" and "v2" will be displayed.
118+
_Example:_ Given the tags v1.0.0, v1.1.0, v2.0.0, two virtual tags "v1" and "v2" will be displayed.
113119
"v1" links to "v1.1.0" and "v2" links to "v2.0.0".
114120
Pushing a release "v2.0.1" will make "v2" automatically refer to "v2.0.1".
115121

116122
This also works when you don't use the "v" prefix in your tags. The virtual tag will then also not have a "v" prefix.
117123

124+
#### Filters
125+
126+
Using the `filter` settings in _branches_ and _tags_ subsection you can filter which branches or tags should be displayed.
127+
Wrap the string in / to evaluate the inside as Golang regular expression.
128+
129+
Note that the filters apply before the virtual tags.
130+
Given the repostory has two tags v1.0.0 and v1.1.0.
131+
For some reason, you exclude v1.1.0 via a filter.
132+
The virtual tag will then point to v1.0.0, not v1.1.0!
133+
134+
118135
## Mirroring with Webhooks
119136

120137
If you want to update the repository whenever something is pushed or tagged in your repository, you can use GitHub webhooks.

config.yml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ git:
1212
files:
1313
- "**/*.json"
1414
display:
15+
branches:
16+
filter:
17+
- master
18+
- develop
19+
- /feature/.*/ # regex: any feature branches
1520
tags:
1621
order: desc
1722
show_date: true

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ type Config struct {
3131
}
3232
}
3333
Display struct {
34+
Branches struct {
35+
Filter []string
36+
}
3437
Tags struct {
38+
Filter []string
3539
Order string `default:"desc" yaml:"order"`
3640
ShowDate bool `default:"true" yaml:"show_date"`
3741
VirtualTags struct {

git/repo.go

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7+
"regexp"
78
"strconv"
89
"strings"
910
"time"
@@ -53,6 +54,62 @@ func (g *GitHandler) IsUpToDate() bool {
5354
return time.Now().Unix() <= (g.GetUpdatedTime() + int64(g.Cfg.Git.Update.Cache.Time))
5455
}
5556

57+
func (g *GitHandler) filterBranches(references []string) []string {
58+
filters := g.Cfg.Display.Branches.Filter
59+
if len(filters) == 0 {
60+
return references
61+
}
62+
var output []string
63+
for _, v := range references {
64+
valid := false
65+
for _, f := range filters {
66+
if strings.HasPrefix(f, "/") && strings.HasSuffix(f, "/") {
67+
// RegEx
68+
expression := strings.Trim(f, "/")
69+
valid = regexp.MustCompile(expression).MatchString(v)
70+
} else {
71+
valid = f == v
72+
}
73+
if valid {
74+
break
75+
}
76+
}
77+
if !valid {
78+
continue
79+
}
80+
output = append(output, v)
81+
}
82+
return output
83+
}
84+
85+
func (g *GitHandler) filterTags(references []GitTag) []GitTag {
86+
filters := g.Cfg.Display.Tags.Filter
87+
if len(filters) == 0 {
88+
return references
89+
}
90+
var output []GitTag
91+
for _, v := range references {
92+
valid := false
93+
for _, f := range filters {
94+
if strings.HasPrefix(f, "/") && strings.HasSuffix(f, "/") {
95+
// RegEx
96+
expression := strings.Trim(f, "/")
97+
valid = regexp.MustCompile(expression).MatchString(v.Tag)
98+
} else {
99+
valid = f == v.Tag
100+
}
101+
if valid {
102+
break
103+
}
104+
}
105+
if !valid {
106+
continue
107+
}
108+
output = append(output, v)
109+
}
110+
return output
111+
}
112+
56113
func (g *GitHandler) GetBranches() []string {
57114
output, _ := g.runGitCommand("branch", "-l", "-r", "--no-color")
58115
var branches []string
@@ -61,7 +118,7 @@ func (g *GitHandler) GetBranches() []string {
61118
v = strings.TrimPrefix(v, "origin/")
62119
branches = append(branches, v)
63120
}
64-
return branches
121+
return g.filterBranches(branches)
65122
}
66123

67124
type GitTag struct {
@@ -83,5 +140,6 @@ func (g *GitHandler) GetTags() []GitTag {
83140
Date: intDate,
84141
})
85142
}
86-
return tags
143+
144+
return g.filterTags(tags)
87145
}

0 commit comments

Comments
 (0)