contributors.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "context"
  4. "runtime/debug"
  5. "strings"
  6. "go-common/app/tool/saga/model"
  7. "go-common/library/log"
  8. "github.com/pkg/errors"
  9. )
  10. // HandleBuildContributors ...
  11. func (s *Service) HandleBuildContributors(c context.Context, repo *model.RepoInfo) (err error) {
  12. if strings.TrimSpace(repo.Group) == "" {
  13. err = errors.Errorf("repo Group is not valid")
  14. return
  15. }
  16. if strings.TrimSpace(repo.Name) == "" {
  17. err = errors.Errorf("repo Name is not valid")
  18. return
  19. }
  20. if strings.TrimSpace(repo.Branch) == "" {
  21. err = errors.Errorf("repo Branch is not valid")
  22. return
  23. }
  24. go func() {
  25. defer func() {
  26. if x := recover(); x != nil {
  27. log.Error("BuildContributor: %+v %s", x, debug.Stack())
  28. }
  29. }()
  30. if err = s.cmd.BuildContributor(repo); err != nil {
  31. log.Error("BuildContributor %+v", err)
  32. }
  33. }()
  34. return
  35. }
  36. // BuildContributors ...
  37. func (s *Service) BuildContributors(repos []*model.Repo) (err error) {
  38. var (
  39. repo *model.Repo
  40. branch string
  41. )
  42. log.Info("BuildContributors start ...")
  43. for _, repo = range repos {
  44. for _, branch = range repo.Config.AuthBranches {
  45. repoInfo := &model.RepoInfo{
  46. Group: repo.Config.Group,
  47. Name: repo.Config.Name,
  48. Branch: branch,
  49. }
  50. log.Info("BuildContributors project [%s], group [%s], Name [%s], branch [%s]", repo.Config.URL, repo.Config.Group, repo.Config.Name, branch)
  51. if err = s.HandleBuildContributors(context.TODO(), repoInfo); err != nil {
  52. log.Error("BuildContributors err (%+v)", err)
  53. }
  54. }
  55. }
  56. return
  57. }