Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. func main() {
  2.  
  3. client := github.NewClient(nil)
  4.  
  5. opt := &github.RepositoryListByOrgOptions{Type: "public"}
  6. // get our public repositories list to the repos variable
  7. repos, _, _ := client.Repositories.ListByOrg(context.Background(), os.Getenv("GITHUB_ORG_NAME"), opt)
  8.  
  9. // the list of repositories that are expected to be public
  10. allowedRepos := strings.Fields(os.Getenv("ALLOWED_REPOS"))
  11.  
  12. for _, repo := range repos {
  13. fmt.Printf("nChecking %sn", *repo.Name)
  14. if isAllowedRepo(*repo.Name, allowedRepos) {
  15. fmt.Printf("OK: repo %s found in Allowedn", *repo.Name)
  16. } else {
  17. fmt.Printf("ALARM: repo %s was NOT found in Allowed!n", *repo.Name)
  18. sendSlackAlarm(*repo.Name, *repo.HTMLURL)
  19. }
  20. }
  21. }
  22.  
  23. func isAllowedRepo(repoName string, allowedRepos []string) bool {
  24.  
  25. // and just iterate the repoName over the allowedRepos list
  26. for _, i := range allowedRepos {
  27. if i == repoName {
  28. return true
  29. }
  30. }
  31.  
  32. return false
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement