diff --git a/pkg/cibot/issue.go b/pkg/cibot/issue.go index 04e7d9e3792dc6a76c24ca82de43acbba1e99103..97d9d02d3596f4ed5a2b66bdb15b1b2c8981f2db 100644 --- a/pkg/cibot/issue.go +++ b/pkg/cibot/issue.go @@ -2,7 +2,8 @@ package cibot import ( "fmt" - + "strings" + "gitee.com/openeuler/ci-bot/pkg/cibot/database" "gitee.com/openeuler/go-gitee/gitee" "github.com/golang/glog" ) @@ -18,32 +19,55 @@ func (s *Server) HandleIssueEvent(event *gitee.IssueEvent) { case "open": glog.Info("received a issue open event") + owner := event.Repository.Namespace + repo := event.Repository.Path + number := event.Issue.Number + // get sig name add a tag to describe the sig name of the repo. + sigName := s.getSigNameFromRepo(event.Repository.FullName) + if len(sigName) > 0 { + label := []string{fmt.Sprintf("sig/%s", sigName)} + labelops := gitee.PullRequestLabelPostParam{s.Config.GiteeToken, label} + _, _, error := s.GiteeClient.LabelsApi.PostV5ReposOwnerRepoIssuesNumberLabels(s.Context, owner, repo, number, labelops) + if error != nil { + glog.Errorf("unable to add label in issue: %v", error) + } + } + + //get committor list: + var ps []database.Privileges + err := database.DBConnection.Model(&database.Privileges{}). + Where("owner = ? and repo = ? and type = ?", owner, repo, PrivilegeDeveloper).Find(&ps).Error + if err != nil { + glog.Errorf("unable to get members: %v", err) + } + var committors []string + if len(ps) > 0 { + for _, p := range ps { + if len(committors) < 10 { + committor := fmt.Sprintf("***@%s***", p.User) + committors = append(committors, committor) + } + } + } + committor_list := strings.Join(committors, ", ") + if len(committor_list) > 0 { + sigPath := fmt.Sprintf(SigPath, sigName) + proInfo := fmt.Sprintf(DisplayCommittors, sigName, sigPath) + committor_list = proInfo + committor_list + "." + } + // add comment body := gitee.IssueCommentPostParam{} body.AccessToken = s.Config.GiteeToken - body.Body = fmt.Sprintf(tipBotMessage, event.Sender.Login, s.Config.CommunityName, s.Config.CommunityName, - s.Config.BotName, s.Config.CommandLink) + body.Body = fmt.Sprintf(tipBotMessage, event.Sender.Login, s.Config.CommunityName, s.Config.CommandLink, committor_list) //Issue could exists without belonging to any repo. if event.Repository == nil { glog.Warningf("Issue is not created on repo, skip posting issue comment.") return } - owner := event.Repository.Namespace - repo := event.Repository.Path - number := event.Issue.Number - _, _, err := s.GiteeClient.IssuesApi.PostV5ReposOwnerRepoIssuesNumberComments(s.Context, owner, repo, number, body) + _, _, err = s.GiteeClient.IssuesApi.PostV5ReposOwnerRepoIssuesNumberComments(s.Context, owner, repo, number, body) if err != nil { glog.Errorf("unable to add comment in issue: %v", err) } - - sigName := s.getSigNameFromRepo(event.Repository.FullName) - if len(sigName) > 0 { - label := []string{fmt.Sprintf("sig/%s", sigName)} - labelops := gitee.PullRequestLabelPostParam{s.Config.GiteeToken, label} - _, _, err = s.GiteeClient.LabelsApi.PostV5ReposOwnerRepoIssuesNumberLabels(s.Context, owner, repo, number, labelops) - if err != nil { - glog.Errorf("unable to add label in issue: %v", err) - } - } } } diff --git a/pkg/cibot/lgtm.go b/pkg/cibot/lgtm.go index b9f10d48cad80bb9b623272f7a90bab9550d9bff..308a53817342731d3c3377bb142ed70a039172fd 100644 --- a/pkg/cibot/lgtm.go +++ b/pkg/cibot/lgtm.go @@ -11,9 +11,9 @@ import ( ) const ( - lgtmSelfOwnMessage = `***lgtm*** can not be added in your self-own pull request. :astonished: ` - lgtmAddedMessage = `***lgtm*** is added in this pull request by: ***%s***. :wave: -**NOTE:**: If you find this pull request unmerged while all conditions meets, you are encouraged use command: "/check-pr" to try it again. :smile: ` + lgtmSelfOwnMessage = `Sorry, you cannot add ***lgtm*** to the pull request you created. :astonished:` + lgtmAddedMessage = `***lgtm*** was added to this pull request by: ***%s***. :wave: +**NOTE:**: If this pull request is not merged while all conditions are met, comment "/check-pr" to try again. :smile: ` lgtmRemovedMessage = `***lgtm*** is removed in this pull request by: ***%s***. :flushed: ` lgtmAddNoPermissionMessage = `Thanks for your review, ***%s***, your opinion is very important to us.:wave: The maintainers will consider your advice carefully.` diff --git a/pkg/cibot/pullrequest.go b/pkg/cibot/pullrequest.go index 603be48b72026c2a385f51986707bb998ec12a83..487701c461b2123cb11f4af29c09a078fca005e1 100644 --- a/pkg/cibot/pullrequest.go +++ b/pkg/cibot/pullrequest.go @@ -237,7 +237,7 @@ func (s *Server) UpdateLabelsBySourceBranchChange(delLabels, updateLabels []stri glog.Infof("remove labels successfully: %v", strDelLabel) } // add comment for update labels - commentContent := `new changes are detected. ***%s*** is removed in this pull request by: ***%s***. :flushed: ` + commentContent := `Changes detected. ***%s*** was removed from this pull request by: ***%s***. :flushed: ` cBody := gitee.PullRequestCommentPostParam{} cBody.AccessToken = s.Config.GiteeToken cBody.Body = fmt.Sprintf(commentContent, strDelLabel, s.Config.BotName) diff --git a/pkg/cibot/utils.go b/pkg/cibot/utils.go index a20a60c05847cb34b89c5e5ee1fdd983a17e9948..64bcff1c7233bfbc03eb316d91b454bc2c77552d 100644 --- a/pkg/cibot/utils.go +++ b/pkg/cibot/utils.go @@ -21,10 +21,11 @@ const ( LabelLgtmWithCommenter = "lgtm-%s" LabelNameApproved = "approved" LabelHiddenValue = "" - tipBotMessage = `Hey ***%s***, Welcome to %s Community. -You can follow the instructions at <%s> to interact with the Bot. + tipBotMessage = `Hey ***%s***, welcome to the %s Community. +I'm the Bot here serving you. You can find the instructions on how to interact with me at +<%s>. %s` - DisplayCommittors = `If you have any questions, you could contact SIG: [%s](%s), and maintainers: ` + DisplayCommittors = `If you have any questions, please contact the SIG: [%s](%s), and any of the maintainers: ` SigPath = `https://gitee.com/openeuler/community/tree/master/sig/%s` AutoAddPrjMsg = `Since you have added a item to the src-openeuler.yaml file, we will automatically generate a default package in project openEuler:Factory on OBS cluster for you. If you need a more customized configuration, you can configure it according to the following instructions: `