1
0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-09-20 09:32:58 +00:00
repo-template/filters.go

66 lines
1.5 KiB
Go
Raw Normal View History

2018-02-07 09:02:13 +00:00
package main
import (
"context"
"strings"
2018-02-07 09:02:13 +00:00
"github.com/Luzifer/go_helpers/str"
2018-02-07 09:02:13 +00:00
"github.com/google/go-github/github"
log "github.com/sirupsen/logrus"
)
type filterFunc func(*github.Repository) bool
var filters = map[string]filterFunc{
"archived": filterArchived,
"dockerfile": filterDockerfile,
"fork": filterFork,
"make-jenkins": filterMakeJenkins,
"public": filterPublic,
2018-02-07 09:02:13 +00:00
}
func filterArchived(repo *github.Repository) bool { return repo.Archived != nil && *repo.Archived }
2018-02-07 09:02:13 +00:00
func filterDockerfile(repo *github.Repository) bool {
ctx := context.Background()
_, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, "Dockerfile", nil)
if err != nil {
if resp.StatusCode == 404 {
return false
}
log.WithError(err).Error("Error while looking for Dockerfile")
return false
}
return true
}
func filterFork(repo *github.Repository) bool { return repo.Fork != nil && *repo.Fork }
func filterMakeJenkins(repo *github.Repository) bool {
ctx := context.Background()
fc, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, "Makefile", nil)
if err != nil {
if resp.StatusCode == 404 {
return false
}
log.WithError(err).Error("Error while looking for Dockerfile")
return false
}
if fc.Content == nil {
log.Error("File content had no content")
return false
}
if str.StringInSlice("jenkins:", strings.Split(*fc.Content, "\n")) {
return true
}
return false
}
2018-02-07 09:02:13 +00:00
func filterPublic(repo *github.Repository) bool { return repo.Private != nil && !*repo.Private }