1
0
Fork 0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-12-22 20:21:19 +00:00

Add make-jenkins filter to find Makefiles with jenkins target

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-17 10:49:32 +02:00
parent ce33916809
commit 5122350026
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 34 additions and 5 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
repo-template

View file

@ -2,7 +2,9 @@ package main
import ( import (
"context" "context"
"strings"
"github.com/Luzifer/go_helpers/str"
"github.com/google/go-github/github" "github.com/google/go-github/github"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -11,8 +13,9 @@ type filterFunc func(*github.Repository) bool
var filters = map[string]filterFunc{ var filters = map[string]filterFunc{
"archived": filterArchived, "archived": filterArchived,
"fork": filterFork,
"dockerfile": filterDockerfile, "dockerfile": filterDockerfile,
"fork": filterFork,
"make-jenkins": filterMakeJenkins,
"public": filterPublic, "public": filterPublic,
} }
@ -34,4 +37,29 @@ func filterDockerfile(repo *github.Repository) bool {
} }
func filterFork(repo *github.Repository) bool { return repo.Fork != nil && *repo.Fork } 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
}
func filterPublic(repo *github.Repository) bool { return repo.Private != nil && !*repo.Private } func filterPublic(repo *github.Repository) bool { return repo.Private != nil && !*repo.Private }