From 94182c43774957149b37e0d0cf46b4715313c92a Mon Sep 17 00:00:00 2001 From: georgecao Date: Tue, 6 Apr 2021 17:48:00 +0800 Subject: [PATCH] Add a tag to describe the sig name that the repo belong to. --- pkg/cibot/pullrequest.go | 13 +++++++++++++ pkg/cibot/sighandler.go | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pkg/cibot/pullrequest.go b/pkg/cibot/pullrequest.go index ffd49b1..e93c145 100644 --- a/pkg/cibot/pullrequest.go +++ b/pkg/cibot/pullrequest.go @@ -58,6 +58,19 @@ func (s *Server) HandlePullRequestEvent(actionDesc string, event *gitee.PullRequ } } } + // add a tag to describe the sig name of the repo. + sigName := s.getSigNameFromRepo(event.Repository.FullName) + if len(sigName) > 0{ + addlabel := &gitee.NoteEvent{} + addlabel.PullRequest = event.PullRequest + addlabel.Repository = event.Repository + addlabel.Comment = &gitee.NoteHook{} + err = s.AddSpecifyLabelsInPulRequest(addlabel, []string{fmt.Sprintf("sig/%s", sigName)}, true) + if err != nil { + glog.Errorf("Add special label sig info failed: %v", err) + return + } + } if s.Config.AutoDetectCla { err = s.CheckCLAByPullRequestEvent(event) diff --git a/pkg/cibot/sighandler.go b/pkg/cibot/sighandler.go index b9144e7..6d70c93 100644 --- a/pkg/cibot/sighandler.go +++ b/pkg/cibot/sighandler.go @@ -439,3 +439,25 @@ func (handler *SigHandler) addSigRepos(sig Sig, mapSigRepos, mapSigReposInDB map return nil } + +// get Sig name by Repo name +func (s *Server) getSigNameFromRepo(repoName string) (sigName string) { + sigName = "" + if len(repoName) == 0 || len(repoName) > 128 { + glog.Errorf("Repo name is invalid.") + return + } + // get sig repos from DB + glog.Infof("Repo name is:%s .", repoName) + var srs database.SigRepositories + err := database.DBConnection.Model(&database.SigRepositories{}). + Where("repo_name = ?", repoName).Find(&srs).Error + if err != nil { + glog.Errorf("unable to get sig repos: %v", err) + return + } + sigName = srs.Name + glog.Infof("end to add sig repos for %s", sigName) + return +} + -- Gitee