From 29db0354457a5de88b6aa815c1937ad00d3cbf28 Mon Sep 17 00:00:00 2001 From: georgecao Date: Mon, 27 Apr 2020 15:15:51 +0800 Subject: [PATCH 1/2] add notify message --- config.yaml | 1 + pkg/cibot/config/config.go | 1 + pkg/cibot/pullrequest.go | 22 ++++++++++++++++++++++ pkg/cibot/utils.go | 2 ++ 4 files changed, 26 insertions(+) diff --git a/config.yaml b/config.yaml index ea80f7f..8a14c10 100644 --- a/config.yaml +++ b/config.yaml @@ -19,3 +19,4 @@ newfilerepo: "obs_meta" newfilebranch: "master" tmpservicefile: "_service" tmpservicepath: "projects/openEuler:Factory/#projectname#/_service" +guideurl: "https://gitee.com/openeuler/community/tree/master/zh/contributors" diff --git a/pkg/cibot/config/config.go b/pkg/cibot/config/config.go index b2ee112..060eb2d 100644 --- a/pkg/cibot/config/config.go +++ b/pkg/cibot/config/config.go @@ -27,6 +27,7 @@ type Config struct { NewFileBranch string `yaml:"newfilebranch"` ServiceFile string `yaml:"tmpservicefile"` ServicePath string `yaml:"tmpservicepath"` + GuideURL string `yaml:"guideurl"` } type WatchProjectFile struct { diff --git a/pkg/cibot/pullrequest.go b/pkg/cibot/pullrequest.go index 5c1fd7b..5628564 100644 --- a/pkg/cibot/pullrequest.go +++ b/pkg/cibot/pullrequest.go @@ -75,6 +75,7 @@ func (s *Server) HandlePullRequestEvent(event *gitee.PullRequestEvent) { } prjnames := ParseDiffInfoAndGetProjectName(diff) if 0 == len(prjnames) { + glog.Infof("No project file need to add.") return } @@ -87,12 +88,33 @@ func (s *Server) HandlePullRequestEvent(event *gitee.PullRequestEvent) { glog.Infof("Project(%v) is in obs already.", prjn) continue } + // send note + s.SendNote4AutomaticNewFile(event) + // new a project file automaticly glog.Infof("Begin to create new project file, project name:%v.", prjn) _servicepath, _servicecontent := s.FillServicePathAndContentWithProjectName(prjn) s.NewFileWithPathAndContentInPullRequest(event, _servicepath, _servicecontent, newfilebranch, newfilerepo, newowner) } } } +func (s *Server) SendNote4AutomaticNewFile(event *gitee.PullRequestEvent) { + if event == nil { + return + } + + owner := event.Repository.Namespace + repo := event.Repository.Name + number := event.PullRequest.Number + body := gitee.PullRequestCommentPostParam{} + body.AccessToken = s.Config.GiteeToken + body.Body = AutoAddPrjMsg + s.Config.GuideURL + glog.Infof("Send notify info: %v.", body.Body) + _, _, err := s.GiteeClient.PullRequestsApi.PostV5ReposOwnerRepoPullsNumberComments(s.Context, owner, repo, number, body) + if err != nil { + glog.Errorf("unable to add comment in pull request: %v", err) + } + return +} // parse diff info func ParseDiffInfoAndGetProjectName(diff string) (prjnames []string) { diff --git a/pkg/cibot/utils.go b/pkg/cibot/utils.go index 446d117..a91ab45 100644 --- a/pkg/cibot/utils.go +++ b/pkg/cibot/utils.go @@ -25,6 +25,8 @@ const ( All of the projects in %s Community are maintained by ***@%s***. That means the developers can comment below every pull request or issue to trigger Bot Commands. Please follow instructions at <%s> to find the details.` + AutoAddPrjMsg = `Since you have added a item to the src-openeuler.yaml file, we will automatically generate a default project for you in the src-openeuler repository. +If you need a more customized configuration, you can configure it according to the following instructions: ` ) var ( -- Gitee From 46af394fc5808acd75c55d26d40a1aa7b392c436 Mon Sep 17 00:00:00 2001 From: "George.Cao" Date: Thu, 29 Feb 2024 03:45:19 +0000 Subject: [PATCH 2/2] update README.md. Signed-off-by: George.Cao --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0529443..5328075 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,5 @@ See the [Command Help](https://gitee.com/openeuler/community/blob/master/en/sig- ## License See the [LICENSE](LICENSE) file for details. + +2024-02-29 11-37 -- Gitee