From d2ecbfb81e296b5d859303d127713223f6e0e934 Mon Sep 17 00:00:00 2001 From: georgecao Date: Tue, 28 Apr 2020 12:44:34 +0800 Subject: [PATCH 1/3] make a new project obs file automaticly while someone change the 'src-openeuler.yaml' in community repository. --- _service | 6 + config.yaml | 7 + go.mod | 2 +- go.sum | 6 + pkg/cibot/config/config.go | 7 + pkg/cibot/inithandler.go | 2 +- pkg/cibot/pullrequest.go | 177 +++++++++ pkg/cibot/repohandler.go | 2 +- pkg/cibot/utils.go | 2 + .../go-gitee/gitee/api_pull_requests.go | 367 ++++++++++++++---- .../go-gitee/gitee/api_repositories.go | 60 +-- .../go-gitee/gitee/hook_event_types.go | 4 +- .../openeuler/go-gitee/gitee/model_branch.go | 8 +- .../go-gitee/gitee/model_branch_commit.go | 16 + .../go-gitee/gitee/model_complete_branch.go | 2 +- .../gitee/model_create_pull_request_param.go | 35 ++ .../go-gitee/gitee/model_new_file_param.go | 29 ++ .../model_pull_request_assignee_post_param.go | 18 + .../gitee/model_pull_request_comments.go | 2 +- .../gitee/model_pull_request_file_path.go | 23 ++ .../gitee/model_pull_request_files.go | 16 +- .../model_pull_request_label_post_param.go | 18 + vendor/modules.txt | 2 +- 23 files changed, 678 insertions(+), 133 deletions(-) create mode 100644 _service create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_branch_commit.go create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_create_pull_request_param.go create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_new_file_param.go create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_assignee_post_param.go create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_file_path.go create mode 100644 vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_label_post_param.go diff --git a/_service b/_service new file mode 100644 index 0000000..8b69a1e --- /dev/null +++ b/_service @@ -0,0 +1,6 @@ + + + repo + next/openEuler/#projectname# + + diff --git a/config.yaml b/config.yaml index 1967f7b..56c6a59 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,10 @@ communityName: openEuler claLink: https://openeuler.org/en/cla.html commandLink: https://gitee.com/openeuler/community/blob/master/en/sig-infrastructure/command.md contactEmail: contact@openeuler.org +accordingfile: "src-openeuler.yaml" +newfileowner: "src-openeuler" +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/go.mod b/go.mod index b85ab54..92a62c7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitee.com/openeuler/ci-bot go 1.13 require ( - gitee.com/openeuler/go-gitee v0.0.0-20200320051710-5687412fb922 + gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179 github.com/antihax/optional v1.0.0 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/golang/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index 2292421..7edc2d7 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,12 @@ cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU= cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= gitee.com/openeuler/go-gitee v0.0.0-20200320051710-5687412fb922 h1:tH5xYCmBLUEgqr8QaplXvk7ciguomHNPY5sJVHFtsBI= gitee.com/openeuler/go-gitee v0.0.0-20200320051710-5687412fb922/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= +gitee.com/openeuler/go-gitee v0.0.0-20200407034142-9d0d3521129a h1:uakoqruiLVLw8UphAQWbu1L4wEUq4cbt+sK7WxrNeVw= +gitee.com/openeuler/go-gitee v0.0.0-20200421085606-b5c14af251af h1:anPYokl5XfI3WdFQB5OUzsbY+EvkG77gO1FU6vaiptI= +gitee.com/openeuler/go-gitee v0.0.0-20200423030551-27093fdcaf21 h1:IVayS8PZbOQQ8Cu8Y3wdG2lMaqVT7Zrt8OErhsxPiHE= +gitee.com/openeuler/go-gitee v0.0.0-20200423113229-786eaacbb974 h1:wlwVb3CNYOf/5yo+ZCwopBGyQNJfh9KypIbuopSKiyY= +gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179 h1:7bHzennVUJlv27Gljny95CyXknEBrfmHL6KdHCuHumM= +gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= diff --git a/pkg/cibot/config/config.go b/pkg/cibot/config/config.go index 875d15b..060eb2d 100644 --- a/pkg/cibot/config/config.go +++ b/pkg/cibot/config/config.go @@ -21,6 +21,13 @@ type Config struct { CommandLink string `yaml:"commandLink"` ContactEmail string `yaml:"contactEmail"` LgtmCountsRequired int `yaml:"lgtmCountsRequired"` + AccordingFile string `yaml:"accordingfile"` + NewFileOwner string `yaml:"newfileowner"` + NewFileRepo string `yaml:"newfilerepo"` + NewFileBranch string `yaml:"newfilebranch"` + ServiceFile string `yaml:"tmpservicefile"` + ServicePath string `yaml:"tmpservicepath"` + GuideURL string `yaml:"guideurl"` } type WatchProjectFile struct { diff --git a/pkg/cibot/inithandler.go b/pkg/cibot/inithandler.go index 8050793..be406d0 100644 --- a/pkg/cibot/inithandler.go +++ b/pkg/cibot/inithandler.go @@ -971,7 +971,7 @@ func (handler *InitHandler) addBranchProtections(c Community, r Repository, mapB } // If branch has alreay been protected, no need for protection - if branchObj.Protected == "true" { + if branchObj.Protected == true { glog.Errorf("branch %s has been protected already, no need for protection", v) continue } diff --git a/pkg/cibot/pullrequest.go b/pkg/cibot/pullrequest.go index 8fb12f1..ac3f6fc 100644 --- a/pkg/cibot/pullrequest.go +++ b/pkg/cibot/pullrequest.go @@ -1,7 +1,9 @@ package cibot import ( + "encoding/base64" "fmt" + "io/ioutil" "strings" "gitee.com/openeuler/go-gitee/gitee" @@ -64,7 +66,182 @@ func (s *Server) HandlePullRequestEvent(event *gitee.PullRequestEvent) { return } } + case "merge": + glog.Info("Received a pull request merge event") + + diff := s.CheckSpecialFileHasModified(event, s.Config.AccordingFile) + if diff == "" { + return + } + prjnames := ParseDiffInfoAndGetProjectName(diff) + if 0 == len(prjnames) { + glog.Infof("No project file need to add.") + return + } + + newfilerepo := s.Config.NewFileRepo + newfilebranch := s.Config.NewFileBranch + newowner := s.Config.NewFileOwner + for _, prjn := range prjnames { + exist := s.CheckWetherNewItemInObsProjects(event, prjn, newfilebranch, newfilerepo, newowner) + if true == exist { + 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) { + if strings.Contains(diff, "+- name:") { + difs := strings.Fields(diff) + for idx, str := range difs { + // glog.Infof(str) + if idx+2 >= len(difs) { + break + } + if (str == "+-") && (difs[idx+1] == "name:") { + prjnames = append(prjnames, difs[idx+2]) + glog.Infof(prjnames[0]) + } + } + } + return +} + +// Get the diff info with merge and choose projects to be added +func (s *Server) CheckSpecialFileHasModified(event *gitee.PullRequestEvent, specialfile string) (diff string) { + diff = "" + if event == nil { + return } + // get pr commit file list, community repo + owner := event.Repository.Namespace + repo := event.Repository.Name + number := event.PullRequest.Number + lvos := &gitee.GetV5ReposOwnerRepoPullsNumberFilesOpts{} + lvos.AccessToken = optional.NewString(s.Config.GiteeToken) + fls, _, err := s.GiteeClient.PullRequestsApi.GetV5ReposOwnerRepoPullsNumberFiles(s.Context, owner, repo, number, lvos) + if err != nil { + glog.Errorf("unable to get pr file list. err: %v", err) + return + } + // check special file has modified and get diff + for _, file := range fls { + if strings.Contains(file.Filename, specialfile) { + glog.Infof("%v has been modified", specialfile) + diff = file.Patch.Diff + break + } + } + return +} + +// Check whether the new item in src-openeuler.yaml is in project +func (s *Server) CheckWetherNewItemInObsProjects(event *gitee.PullRequestEvent, prjname string, branch string, repo string, owner string) (exist bool) { + exist = false + if event == nil { + return + } + + // get the sha of branch + lvosbranch := &gitee.GetV5ReposOwnerRepoBranchesBranchOpts{} + lvosbranch.AccessToken = optional.NewString(s.Config.GiteeToken) + bdetail, _, err := s.GiteeClient.RepositoriesApi.GetV5ReposOwnerRepoBranchesBranch(s.Context, owner, repo, branch, lvosbranch) + if err != nil { + glog.Errorf("Get branch(%v) repo(%v) detail info failed: %v", branch, repo, err) + return + } + + // look up the obs project in infrastructure + treesha := bdetail.Commit.Sha + lvostree := &gitee.GetV5ReposOwnerRepoGitTreesShaOpts{} + lvostree.AccessToken = optional.NewString(s.Config.GiteeToken) + lvostree.Recursive = optional.NewInt32(1) + tree, _, err := s.GiteeClient.GitDataApi.GetV5ReposOwnerRepoGitTreesSha(s.Context, owner, repo, treesha, lvostree) + if err != nil { + glog.Errorf("Get menu tree of branch(%v) repo(%v) failed: %v", branch, repo, err) + return + } + for _, dir := range tree.Tree { + if strings.Contains(dir.Path, "/"+prjname+"/") { + glog.Infof("Find the project path:%v, sha:%v", dir.Path, dir.Sha) + exist = true + } + } + return +} + +// Fill file _service path and content +func (s *Server) FillServicePathAndContentWithProjectName(prjname string) (_servicepath string, _service string) { + _servicepath = strings.Replace(s.Config.ServicePath, "#projectname#", prjname, 1) + glog.Infof("service path:%v", _servicepath) + + // read template file info + filebuf, err := ioutil.ReadFile(s.Config.ServiceFile) + if err != nil { + glog.Errorf("Read template service file failed: %v.", err) + return + } + str := string(filebuf) + _service = strings.Replace(str, "#projectname#", prjname, 1) + glog.Infof("service file:%v", _service) + /* + _servicepath = "obs/team_usage/obs_meta/projects/openEuler:Mainline/" + prjname + "/_service" + _service = "\n" + + " \n" + + " repo\n" + + " next/openEuler/" + prjname + "\n" + + " \n" + + "" + */ + return +} + +// New project with name in pull +func (s *Server) NewFileWithPathAndContentInPullRequest(event *gitee.PullRequestEvent, path string, content string, branch string, repo string, owner string) { + if event == nil { + return + } + newfbody := gitee.NewFileParam{} + newfbody.AccessToken = s.Config.GiteeToken + newfbody.AuthorName = event.PullRequest.User.Login + newfbody.AuthorEmail = event.PullRequest.User.Email + newfbody.CommitterName = event.PullRequest.User.Login + newfbody.CommitterEmail = event.PullRequest.User.Email + newfbody.Branch = branch + newfbody.Message = "add project according to src-openeuler.yaml in repo community." + + glog.Infof("Begin to write template fil(%v) autoly.", path) + contentbase64 := base64.StdEncoding.EncodeToString([]byte(content)) + newfbody.Content = contentbase64 + s.GiteeClient.RepositoriesApi.PostV5ReposOwnerRepoContentsPath(s.Context, owner, repo, path, newfbody) + return } // RemoveAssigneesInPullRequest remove assignees in pull request diff --git a/pkg/cibot/repohandler.go b/pkg/cibot/repohandler.go index caf1742..22eb8d2 100644 --- a/pkg/cibot/repohandler.go +++ b/pkg/cibot/repohandler.go @@ -498,7 +498,7 @@ func (handler *RepoHandler) addBranchProtections(community string, r Repository, } // If branch has alreay been protected, no need for protection - if branchObj.Protected == "true" { + if branchObj.Protected == true { glog.Errorf("branch %s has been protected already, no need for protection", v) continue } 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 ( diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/api_pull_requests.go b/vendor/gitee.com/openeuler/go-gitee/gitee/api_pull_requests.go index 8eb1c32..01845a8 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/api_pull_requests.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/api_pull_requests.go @@ -109,6 +109,91 @@ func (a *PullRequestsApiService) DeleteV5ReposOwnerRepoPullsCommentsId(ctx conte return localVarHttpResponse, nil } +/* +PullRequestsApiService 删除 Pull Request 标签 +删除 Pull Request 标签 + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param owner 仓库所属空间地址(企业、组织或个人的地址path) + * @param repo 仓库路径(path) + * @param number 第几个PR,即本仓库PR的序数 + * @param name 标签名称 + * @param optional nil or *DeleteV5ReposOwnerRepoPullsLabelOpts - Optional Parameters: + * @param "AccessToken" (optional.String) - 用户授权码 + + +*/ + +type DeleteV5ReposOwnerRepoPullsLabelOpts struct { + AccessToken optional.String +} + +func (a *PullRequestsApiService) DeleteV5ReposOwnerRepoPullsLabel(ctx context.Context, owner string, repo string, number int32, name string, localVarOptionals *DeleteV5ReposOwnerRepoPullsLabelOpts) (*http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v5/repos/{owner}/{repo}/pulls/{number}/labels/{name}" + localVarPath = strings.Replace(localVarPath, "{"+"owner"+"}", fmt.Sprintf("%v", owner), -1) + localVarPath = strings.Replace(localVarPath, "{"+"repo"+"}", fmt.Sprintf("%v", repo), -1) + localVarPath = strings.Replace(localVarPath, "{"+"number"+"}", fmt.Sprintf("%v", number), -1) + localVarPath = strings.Replace(localVarPath, "{"+"name"+"}", fmt.Sprintf("%v", name), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { + localVarQueryParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + + return localVarHttpResponse, newErr + } + + return localVarHttpResponse, nil +} + /* PullRequestsApiService 取消用户审查 Pull Request 取消用户审查 Pull Request @@ -1116,6 +1201,119 @@ func (a *PullRequestsApiService) GetV5ReposOwnerRepoPullsNumberFiles(ctx context return localVarReturnValue, localVarHttpResponse, nil } +/* +PullRequestsApiService 获取某个 Pull Request 的所有标签 +获取某个 Pull Request 的所有标签 + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param owner 仓库所属空间地址(企业、组织或个人的地址path) + * @param repo 仓库路径(path) + * @param number 第几个PR,即本仓库PR的序数 + * @param optional nil or *GetV5ReposOwnerRepoPullsNumberLabelsOpts - Optional Parameters: + * @param "AccessToken" (optional.String) - 用户授权码 + * @param "Page" (optional.Int32) - 当前的页码 + * @param "PerPage" (optional.Int32) - 每页的数量,最大为 100 + +@return []Label +*/ + +type GetV5ReposOwnerRepoPullsNumberLabelsOpts struct { + AccessToken optional.String + Page optional.Int32 + PerPage optional.Int32 +} + +func (a *PullRequestsApiService) GetV5ReposOwnerRepoPullsNumberLabels(ctx context.Context, owner string, repo string, number int32, localVarOptionals *GetV5ReposOwnerRepoPullsNumberLabelsOpts) ([]Label, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue []Label + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v5/repos/{owner}/{repo}/pulls/{number}/labels" + localVarPath = strings.Replace(localVarPath, "{"+"owner"+"}", fmt.Sprintf("%v", owner), -1) + localVarPath = strings.Replace(localVarPath, "{"+"repo"+"}", fmt.Sprintf("%v", repo), -1) + localVarPath = strings.Replace(localVarPath, "{"+"number"+"}", fmt.Sprintf("%v", number), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { + localVarQueryParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) + } + if localVarOptionals != nil && localVarOptionals.Page.IsSet() { + localVarQueryParams.Add("page", parameterToString(localVarOptionals.Page.Value(), "")) + } + if localVarOptionals != nil && localVarOptionals.PerPage.IsSet() { + localVarQueryParams.Add("per_page", parameterToString(localVarOptionals.PerPage.Value(), "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + + if localVarHttpResponse.StatusCode == 200 { + var v []Label + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} + /* PullRequestsApiService 判断Pull Request是否已经合并 判断Pull Request是否已经合并 @@ -1514,34 +1712,11 @@ PullRequestsApiService 创建Pull Request * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param owner 仓库所属空间地址(企业、组织或个人的地址path) * @param repo 仓库路径(path) - * @param title 必填。Pull Request 标题 - * @param head 必填。Pull Request 提交的源分支。格式:branch 或者:username:branch - * @param base 必填。Pull Request 提交目标分支的名称 - * @param optional nil or *PostV5ReposOwnerRepoPullsOpts - Optional Parameters: - * @param "AccessToken" (optional.String) - 用户授权码 - * @param "Body" (optional.String) - 可选。Pull Request 内容 - * @param "MilestoneNumber" (optional.Int32) - 可选。里程碑序号(id) - * @param "Labels" (optional.String) - 用逗号分开的标签,名称要求长度在 2-20 之间且非特殊字符。如: bug,performance - * @param "Issue" (optional.String) - 可选。Pull Request的标题和内容可以根据指定的Issue Id自动填充 - * @param "Assignees" (optional.String) - 可选。审查人员username,可多个,半角逗号分隔,如:(username1,username2) - * @param "Testers" (optional.String) - 可选。测试人员username,可多个,半角逗号分隔,如:(username1,username2) - * @param "PruneSourceBranch" (optional.Bool) - 可选。合并PR后是否删除源分支,默认false(不删除) + * @param body pr的信息 @return PullRequest */ - -type PostV5ReposOwnerRepoPullsOpts struct { - AccessToken optional.String - Body optional.String - MilestoneNumber optional.Int32 - Labels optional.String - Issue optional.String - Assignees optional.String - Testers optional.String - PruneSourceBranch optional.Bool -} - -func (a *PullRequestsApiService) PostV5ReposOwnerRepoPulls(ctx context.Context, owner string, repo string, title string, head string, base string, localVarOptionals *PostV5ReposOwnerRepoPullsOpts) (PullRequest, *http.Response, error) { +func (a *PullRequestsApiService) PostV5ReposOwnerRepoPulls(ctx context.Context, owner string, repo string, body CreatePullRequestParam) (PullRequest, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Post") localVarPostBody interface{} @@ -1576,33 +1751,8 @@ func (a *PullRequestsApiService) PostV5ReposOwnerRepoPulls(ctx context.Context, if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } - if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { - localVarFormParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) - } - localVarFormParams.Add("title", parameterToString(title, "")) - localVarFormParams.Add("head", parameterToString(head, "")) - localVarFormParams.Add("base", parameterToString(base, "")) - if localVarOptionals != nil && localVarOptionals.Body.IsSet() { - localVarFormParams.Add("body", parameterToString(localVarOptionals.Body.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.MilestoneNumber.IsSet() { - localVarFormParams.Add("milestone_number", parameterToString(localVarOptionals.MilestoneNumber.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.Labels.IsSet() { - localVarFormParams.Add("labels", parameterToString(localVarOptionals.Labels.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.Issue.IsSet() { - localVarFormParams.Add("issue", parameterToString(localVarOptionals.Issue.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.Assignees.IsSet() { - localVarFormParams.Add("assignees", parameterToString(localVarOptionals.Assignees.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.Testers.IsSet() { - localVarFormParams.Add("testers", parameterToString(localVarOptionals.Testers.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.PruneSourceBranch.IsSet() { - localVarFormParams.Add("prune_source_branch", parameterToString(localVarOptionals.PruneSourceBranch.Value(), "")) - } + // body params + localVarPostBody = &body r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err @@ -1657,18 +1807,11 @@ PullRequestsApiService 指派用户审查 Pull Request * @param owner 仓库所属空间地址(企业、组织或个人的地址path) * @param repo 仓库路径(path) * @param number 第几个PR,即本仓库PR的序数 - * @param assignees 用户的个人空间地址, 以 , 分隔 - * @param optional nil or *PostV5ReposOwnerRepoPullsNumberAssigneesOpts - Optional Parameters: - * @param "AccessToken" (optional.String) - 用户授权码 + * @param body 必选,标签的内容 @return PullRequest */ - -type PostV5ReposOwnerRepoPullsNumberAssigneesOpts struct { - AccessToken optional.String -} - -func (a *PullRequestsApiService) PostV5ReposOwnerRepoPullsNumberAssignees(ctx context.Context, owner string, repo string, number int32, assignees string, localVarOptionals *PostV5ReposOwnerRepoPullsNumberAssigneesOpts) (PullRequest, *http.Response, error) { +func (a *PullRequestsApiService) PostV5ReposOwnerRepoPullsNumberAssignees(ctx context.Context, owner string, repo string, number int32, body PullRequestAssigneePostParam) (PullRequest, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Post") localVarPostBody interface{} @@ -1704,10 +1847,8 @@ func (a *PullRequestsApiService) PostV5ReposOwnerRepoPullsNumberAssignees(ctx co if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } - if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { - localVarFormParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) - } - localVarFormParams.Add("assignees", parameterToString(assignees, "")) + // body params + localVarPostBody = &body r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err @@ -1851,6 +1992,102 @@ func (a *PullRequestsApiService) PostV5ReposOwnerRepoPullsNumberComments(ctx con return localVarReturnValue, localVarHttpResponse, nil } +/* +PullRequestsApiService 创建 Pull Request 标签 +创建 Pull Request 标签 + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param owner 仓库所属空间地址(企业、组织或个人的地址path) + * @param repo 仓库路径(path) + * @param number 第几个PR,即本仓库PR的序数 + * @param body 必选,标签的内容 + +@return Label +*/ +func (a *PullRequestsApiService) PostV5ReposOwnerRepoPullsNumberLabels(ctx context.Context, owner string, repo string, number int32, body PullRequestLabelPostParam) (Label, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue Label + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v5/repos/{owner}/{repo}/pulls/{number}/labels" + localVarPath = strings.Replace(localVarPath, "{"+"owner"+"}", fmt.Sprintf("%v", owner), -1) + localVarPath = strings.Replace(localVarPath, "{"+"repo"+"}", fmt.Sprintf("%v", repo), -1) + localVarPath = strings.Replace(localVarPath, "{"+"number"+"}", fmt.Sprintf("%v", number), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body.Body // This shoud be &body because the gitee api is not normalized. + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + + if localVarHttpResponse.StatusCode == 201 { + var v Label + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} + /* PullRequestsApiService 指派用户测试 Pull Request 指派用户测试 Pull Request diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go b/vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go index 6df47f6..ccdffbb 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go @@ -1182,20 +1182,20 @@ RepositoriesApiService 获取单个分支 * @param optional nil or *GetV5ReposOwnerRepoBranchesBranchOpts - Optional Parameters: * @param "AccessToken" (optional.String) - 用户授权码 -@return CompleteBranch +@return Branch */ type GetV5ReposOwnerRepoBranchesBranchOpts struct { AccessToken optional.String } -func (a *RepositoriesApiService) GetV5ReposOwnerRepoBranchesBranch(ctx context.Context, owner string, repo string, branch string, localVarOptionals *GetV5ReposOwnerRepoBranchesBranchOpts) (CompleteBranch, *http.Response, error) { +func (a *RepositoriesApiService) GetV5ReposOwnerRepoBranchesBranch(ctx context.Context, owner string, repo string, branch string, localVarOptionals *GetV5ReposOwnerRepoBranchesBranchOpts) (Branch, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Get") localVarPostBody interface{} localVarFileName string localVarFileBytes []byte - localVarReturnValue CompleteBranch + localVarReturnValue Branch ) // create path and map variables @@ -1259,7 +1259,7 @@ func (a *RepositoriesApiService) GetV5ReposOwnerRepoBranchesBranch(ctx context.C } if localVarHttpResponse.StatusCode == 200 { - var v CompleteBranch + var v Branch err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -1284,20 +1284,20 @@ RepositoriesApiService 获取仓库的所有成员 * @param optional nil or *GetV5ReposOwnerRepoCollaboratorsOpts - Optional Parameters: * @param "AccessToken" (optional.String) - 用户授权码 -@return ProjectMember +@return []ProjectMember */ type GetV5ReposOwnerRepoCollaboratorsOpts struct { AccessToken optional.String } -func (a *RepositoriesApiService) GetV5ReposOwnerRepoCollaborators(ctx context.Context, owner string, repo string, localVarOptionals *GetV5ReposOwnerRepoCollaboratorsOpts) (ProjectMember, *http.Response, error) { +func (a *RepositoriesApiService) GetV5ReposOwnerRepoCollaborators(ctx context.Context, owner string, repo string, localVarOptionals *GetV5ReposOwnerRepoCollaboratorsOpts) ([]ProjectMember, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Get") localVarPostBody interface{} localVarFileName string localVarFileBytes []byte - localVarReturnValue ProjectMember + localVarReturnValue []ProjectMember ) // create path and map variables @@ -1360,7 +1360,7 @@ func (a *RepositoriesApiService) GetV5ReposOwnerRepoCollaborators(ctx context.Co } if localVarHttpResponse.StatusCode == 200 { - var v ProjectMember + var v []ProjectMember err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -4638,29 +4638,11 @@ RepositoriesApiService 新建文件 * @param owner 仓库所属空间地址(企业、组织或个人的地址path) * @param repo 仓库路径(path) * @param path 文件的路径 - * @param content 文件内容, 要用 base64 编码 - * @param message 提交信息 - * @param optional nil or *PostV5ReposOwnerRepoContentsPathOpts - Optional Parameters: - * @param "AccessToken" (optional.String) - 用户授权码 - * @param "Branch" (optional.String) - 分支名称。默认为仓库对默认分支 - * @param "CommitterName" (optional.String) - Committer的名字,默认为当前用户的名字 - * @param "CommitterEmail" (optional.String) - Committer的邮箱,默认为当前用户的邮箱 - * @param "AuthorName" (optional.String) - Author的名字,默认为当前用户的名字 - * @param "AuthorEmail" (optional.String) - Author的邮箱,默认为当前用户的邮箱 + * @param body 描述文件信息 @return CommitContent */ - -type PostV5ReposOwnerRepoContentsPathOpts struct { - AccessToken optional.String - Branch optional.String - CommitterName optional.String - CommitterEmail optional.String - AuthorName optional.String - AuthorEmail optional.String -} - -func (a *RepositoriesApiService) PostV5ReposOwnerRepoContentsPath(ctx context.Context, owner string, repo string, path string, content string, message string, localVarOptionals *PostV5ReposOwnerRepoContentsPathOpts) (CommitContent, *http.Response, error) { +func (a *RepositoriesApiService) PostV5ReposOwnerRepoContentsPath(ctx context.Context, owner string, repo string, path string, body NewFileParam) (CommitContent, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Post") localVarPostBody interface{} @@ -4696,26 +4678,8 @@ func (a *RepositoriesApiService) PostV5ReposOwnerRepoContentsPath(ctx context.Co if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } - if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { - localVarFormParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) - } - localVarFormParams.Add("content", parameterToString(content, "")) - localVarFormParams.Add("message", parameterToString(message, "")) - if localVarOptionals != nil && localVarOptionals.Branch.IsSet() { - localVarFormParams.Add("branch", parameterToString(localVarOptionals.Branch.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.CommitterName.IsSet() { - localVarFormParams.Add("committer[name]", parameterToString(localVarOptionals.CommitterName.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.CommitterEmail.IsSet() { - localVarFormParams.Add("committer[email]", parameterToString(localVarOptionals.CommitterEmail.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.AuthorName.IsSet() { - localVarFormParams.Add("author[name]", parameterToString(localVarOptionals.AuthorName.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.AuthorEmail.IsSet() { - localVarFormParams.Add("author[email]", parameterToString(localVarOptionals.AuthorEmail.Value(), "")) - } + // body params + localVarPostBody = &body r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/hook_event_types.go b/vendor/gitee.com/openeuler/go-gitee/gitee/hook_event_types.go index 1081a75..2a12e7f 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/hook_event_types.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/hook_event_types.go @@ -82,9 +82,9 @@ type PullRequestEvent struct { MergeCommitSha *string `json:"merge_commit_sha,omitempty"` URL *string `json:"url,omitempty"` SourceBranch *string `json:"source_branch,omitempty"` - SourceRepo *ProjectHook `json:"source_repo,omitempty"` + SourceRepo *RepoInfo `json:"source_repo,omitempty"` TargetBranch *string `json:"target_branch,omitempty"` - TargetRepo *ProjectHook `json:"target_repo,omitempty"` + TargetRepo *RepoInfo `json:"target_repo,omitempty"` Project *ProjectHook `json:"project,omitempty"` Repository *ProjectHook `json:"repository,omitempty"` Author *UserHook `json:"author,omitempty"` diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch.go index 98b8e66..926af4d 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch.go @@ -11,8 +11,8 @@ package gitee // 获取所有分支 type Branch struct { - Name string `json:"name,omitempty"` - Commit string `json:"commit,omitempty"` - Protected string `json:"protected,omitempty"` - ProtectionUrl string `json:"protection_url,omitempty"` + Name string `json:"name,omitempty"` + Commit *BranchCommit `json:"commit,omitempty"` + Protected bool `json:"protected,omitempty"` + ProtectionUrl string `json:"protection_url,omitempty"` } diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch_commit.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch_commit.go new file mode 100644 index 0000000..247a836 --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_branch_commit.go @@ -0,0 +1,16 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +// 分支commit info +type BranchCommit struct { + Url string `json:"url,omitempty"` + Sha string `json:"sha,omitempty"` +} diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_complete_branch.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_complete_branch.go index df48bc0..bbe31f0 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/model_complete_branch.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_complete_branch.go @@ -12,7 +12,7 @@ package gitee // 创建分支 type CompleteBranch struct { Name string `json:"name,omitempty"` - Commit string `json:"commit,omitempty"` + Commit *BranchCommit `json:"commit,omitempty"` Links string `json:"_links,omitempty"` Protected string `json:"protected,omitempty"` ProtectionUrl string `json:"protection_url,omitempty"` diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_create_pull_request_param.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_create_pull_request_param.go new file mode 100644 index 0000000..a87c795 --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_create_pull_request_param.go @@ -0,0 +1,35 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +type CreatePullRequestParam struct { + // 用户授权码 + AccessToken string `json:"access_token,omitempty"` + // 必填。Pull Request 标题 + Title string `json:"title,omitempty"` + // 必填。Pull Request 提交的源分支。格式:branch 或者:username:branch + Head string `json:"head,omitempty"` + // 必填。Pull Request 提交目标分支的名称 + Base string `json:"base,omitempty"` + // 可选。Pull Request 内容 + Body string `json:"body,omitempty"` + // 可选。里程碑序号(id) + MilestoneNumber int32 `json:"milestone_number,omitempty"` + // 用逗号分开的标签,名称要求长度在 2-20 之间且非特殊字符。如: bug,performance + Labels string `json:"labels,omitempty"` + // 可选。Pull Request的标题和内容可以根据指定的Issue Id自动填充 + Issue string `json:"issue,omitempty"` + // 可选。审查人员username,可多个,半角逗号分隔,如:(username1,username2) + Assignees string `json:"assignees,omitempty"` + // 可选。测试人员username,可多个,半角逗号分隔,如:(username1,username2) + Testers string `json:"testers,omitempty"` + // 可选。合并PR后是否删除源分支,默认false(不删除) + PruneSourceBranch bool `json:"prune_source_branch,omitempty"` +} diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_new_file_param.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_new_file_param.go new file mode 100644 index 0000000..2beb129 --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_new_file_param.go @@ -0,0 +1,29 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +type NewFileParam struct { + // 用户授权码 + AccessToken string `json:"access_token,omitempty"` + // 文件内容, 要用 base64 编码 + Content string `json:"content,omitempty"` + // 提交信息 + Message string `json:"message,omitempty"` + // 分支名称。默认为仓库对默认分支 + Branch string `json:"branch,omitempty"` + // Committer的名字,默认为当前用户的名字 + CommitterName string `json:"committer[name],omitempty"` + // Committer的邮箱,默认为当前用户的邮箱 + CommitterEmail string `json:"committer[email],omitempty"` + // Author的名字,默认为当前用户的名字 + AuthorName string `json:"author[name],omitempty"` + // Author的邮箱,默认为当前用户的邮箱 + AuthorEmail string `json:"author[email],omitempty"` +} diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_assignee_post_param.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_assignee_post_param.go new file mode 100644 index 0000000..95dddda --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_assignee_post_param.go @@ -0,0 +1,18 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +// assign pull request +type PullRequestAssigneePostParam struct { + // 用户授权码 + AccessToken string `json:"access_token,omitempty"` + // 用户的个人空间地址, 以 , 分隔 + Assignees string `json:"assignees,omitempty"` +} diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_comments.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_comments.go index 546e0e9..f2ddf45 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_comments.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_comments.go @@ -12,7 +12,7 @@ package gitee // 编辑评论 type PullRequestComments struct { Url string `json:"url,omitempty"` - Id string `json:"id,omitempty"` + Id int32 `json:"id,omitempty"` Path string `json:"path,omitempty"` Position string `json:"position,omitempty"` OriginalPosition string `json:"original_position,omitempty"` diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_file_path.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_file_path.go new file mode 100644 index 0000000..33b6926 --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_file_path.go @@ -0,0 +1,23 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +// 单个文件的patch信息 +type PullRequestFilePath struct { + Diff string `json:"diff,omitempty"` + NewPath string `json:"new_path,omitempty"` + OldPath string `json:"old_path,omitempty"` + AMode string `json:"a_mode,omitempty"` + BMode string `json:"b_mode,omitempty"` + NewFile bool `json:"new_file,omitempty"` + RenamedFile bool `json:"renamed_file,omitempty"` + DeletedFile bool `json:"deleted_file,omitempty"` + TooLarge bool `json:"too_large,omitempty"` +} diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_files.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_files.go index 538698f..bff3c4e 100644 --- a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_files.go +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_files.go @@ -11,12 +11,12 @@ package gitee // Pull Request Commit文件列表。最多显示300条diff type PullRequestFiles struct { - Sha string `json:"sha,omitempty"` - Filename string `json:"filename,omitempty"` - Status string `json:"status,omitempty"` - Additions string `json:"additions,omitempty"` - Deletions string `json:"deletions,omitempty"` - BlobUrl string `json:"blob_url,omitempty"` - RawUrl string `json:"raw_url,omitempty"` - Patch string `json:"patch,omitempty"` + Sha string `json:"sha,omitempty"` + Filename string `json:"filename,omitempty"` + Status string `json:"status,omitempty"` + Additions string `json:"additions,omitempty"` + Deletions string `json:"deletions,omitempty"` + BlobUrl string `json:"blob_url,omitempty"` + RawUrl string `json:"raw_url,omitempty"` + Patch *PullRequestFilePath `json:"patch,omitempty"` } diff --git a/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_label_post_param.go b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_label_post_param.go new file mode 100644 index 0000000..85fd3f2 --- /dev/null +++ b/vendor/gitee.com/openeuler/go-gitee/gitee/model_pull_request_label_post_param.go @@ -0,0 +1,18 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +// create pull request label +type PullRequestLabelPostParam struct { + // 用户授权码 + AccessToken string `json:"access_token,omitempty"` + // 标签名数组,如: [\"feat\", \"bug\"] + Body []string `json:"body,omitempty"` +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ca28922..99412ab 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/go-gitee v0.0.0-20200320051710-5687412fb922 +# gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179 gitee.com/openeuler/go-gitee/gitee # github.com/antihax/optional v1.0.0 github.com/antihax/optional -- Gitee From dcd2a5970c66b20b49162d043a1f25bd1d48df34 Mon Sep 17 00:00:00 2001 From: georgecao Date: Tue, 28 Apr 2020 16:04:42 +0800 Subject: [PATCH 2/3] modify pr callback message and send it at pr open status. --- pkg/cibot/pullrequest.go | 41 +++++++++++++++++++++++++++------------- pkg/cibot/utils.go | 2 +- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/pkg/cibot/pullrequest.go b/pkg/cibot/pullrequest.go index ac3f6fc..6232c2c 100644 --- a/pkg/cibot/pullrequest.go +++ b/pkg/cibot/pullrequest.go @@ -41,6 +41,29 @@ func (s *Server) HandlePullRequestEvent(event *gitee.PullRequestEvent) { if err != nil { glog.Errorf("failed to check cla by pull request event: %v", err) } + + diff := s.CheckSpecialFileHasModified(event, s.Config.AccordingFile) + if diff == "" { + return + } + prjnames := ParseDiffInfoAndGetProjectName(diff) + if 0 == len(prjnames) { + glog.Infof("No project file need to add.") + return + } + + newfilerepo := s.Config.NewFileRepo + newfilebranch := s.Config.NewFileBranch + newowner := s.Config.NewFileOwner + for _, prjn := range prjnames { + exist := s.CheckWetherNewItemInObsProjects(event, prjn, newfilebranch, newfilerepo, newowner) + if true == exist { + glog.Infof("Project(%v) is in obs already.", prjn) + continue + } + // send note + s.SendNote4AutomaticNewFile(event) + } case "update": glog.Info("received a pull request update event") @@ -88,8 +111,6 @@ 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) @@ -211,15 +232,6 @@ func (s *Server) FillServicePathAndContentWithProjectName(prjname string) (_serv str := string(filebuf) _service = strings.Replace(str, "#projectname#", prjname, 1) glog.Infof("service file:%v", _service) - /* - _servicepath = "obs/team_usage/obs_meta/projects/openEuler:Mainline/" + prjname + "/_service" - _service = "\n" + - " \n" + - " repo\n" + - " next/openEuler/" + prjname + "\n" + - " \n" + - "" - */ return } @@ -237,10 +249,13 @@ func (s *Server) NewFileWithPathAndContentInPullRequest(event *gitee.PullRequest newfbody.Branch = branch newfbody.Message = "add project according to src-openeuler.yaml in repo community." - glog.Infof("Begin to write template fil(%v) autoly.", path) + glog.Infof("Begin to write template file (%v) autoly.", path) contentbase64 := base64.StdEncoding.EncodeToString([]byte(content)) newfbody.Content = contentbase64 - s.GiteeClient.RepositoriesApi.PostV5ReposOwnerRepoContentsPath(s.Context, owner, repo, path, newfbody) + _, _, err := s.GiteeClient.RepositoriesApi.PostV5ReposOwnerRepoContentsPath(s.Context, owner, repo, path, newfbody) + if err != nil { + glog.Errorf("New service file failed: %v.", err) + } return } diff --git a/pkg/cibot/utils.go b/pkg/cibot/utils.go index a91ab45..e9c5972 100644 --- a/pkg/cibot/utils.go +++ b/pkg/cibot/utils.go @@ -25,7 +25,7 @@ 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. + 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: ` ) -- Gitee From b6ef6faffa399a3ce154a4aea29bc2d2756a3c43 Mon Sep 17 00:00:00 2001 From: georgecao Date: Thu, 30 Apr 2020 10:11:13 +0800 Subject: [PATCH 3/3] add a copy command in DockerFile. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 4409e3d..9cdfccd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ RUN mkdir -p /bot WORKDIR /bot +COPY ./_service /bot + EXPOSE 8888 ENTRYPOINT ["ci-bot"] -- Gitee