main.go 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. */
  6. package main
  7. import (
  8. "context"
  9. "fmt"
  10. "log"
  11. "os"
  12. "os/signal"
  13. "golang.org/x/sys/unix"
  14. )
  15. func main() {
  16. ctx, cancel := context.WithCancel(context.Background())
  17. // Catch signals
  18. go func() {
  19. sigChan := make(chan os.Signal, 1)
  20. signal.Notify(sigChan, unix.SIGINT, unix.SIGTERM)
  21. _ = <-sigChan
  22. log.Println("caught signal")
  23. cancel()
  24. }()
  25. accessToken, ok := os.LookupEnv("GITLAB_ACCESS_TOKEN")
  26. if !ok {
  27. log.Fatal("environment variable GITLAB_ACCESS_TOKEN is not set")
  28. }
  29. client := NewGitLabClient(ctx, accessToken)
  30. pager := FetchGitLabProjects(client)
  31. for p := range pager.Iter() {
  32. fmt.Printf("%s (%s)\n", p.HTTPURLToRepo, p.Visibility)
  33. }
  34. if err := pager.LastErr(); err != nil {
  35. log.Fatal(fmt.Sprintf("fetch gitlab projects: %v", err))
  36. }
  37. }