2018-02-07 21:20:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-04-11 11:44:58 +00:00
|
|
|
"errors"
|
2018-02-07 21:20:28 +00:00
|
|
|
"strings"
|
|
|
|
|
2021-04-11 11:44:58 +00:00
|
|
|
"github.com/flosch/pongo2/v4"
|
|
|
|
"github.com/google/go-github/v34/github"
|
2018-02-07 21:20:28 +00:00
|
|
|
"github.com/gosimple/slug"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-04-15 18:39:24 +00:00
|
|
|
pongo2.RegisterFilter("has_topic", tplRepoHasTopic)
|
2018-02-07 21:20:28 +00:00
|
|
|
pongo2.RegisterFilter("groovy_save", tplGroovyFileSave)
|
|
|
|
pongo2.RegisterFilter("slugify", tplSlugify)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tplSlugify(in, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
|
|
|
return pongo2.AsValue(slug.Make(in.String())), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func tplGroovyFileSave(in, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
|
|
|
return pongo2.AsValue(strings.Replace(in.String(), "-", "_", -1)), nil
|
|
|
|
}
|
2019-04-15 18:39:24 +00:00
|
|
|
|
|
|
|
func tplRepoHasTopic(in, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
|
|
|
repo, ok := in.Interface().(*github.Repository)
|
|
|
|
if !ok {
|
|
|
|
return nil, &pongo2.Error{
|
2021-04-11 11:44:58 +00:00
|
|
|
Sender: "filter:has_topic",
|
|
|
|
OrigError: errors.New("Input was no github.Repository"),
|
2019-04-15 18:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
topic := param.String()
|
|
|
|
|
|
|
|
for _, t := range repo.Topics {
|
|
|
|
if t == topic {
|
|
|
|
return pongo2.AsValue(true), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pongo2.AsValue(false), nil
|
|
|
|
}
|