diff --git a/conf/app.conf b/conf/app.conf index 6d76eb4e23a07a18a4c0a714e258f9ff12b75fd0..598f275fdddc9ff3be58d9420aadcf682b5e1873 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -88,8 +88,8 @@ urgenttask = 0 51 9-20 * * * #email = 1499273991@qq.com #redirect_uri = http://119.8.126.102:80/v1/issue/oauth/callback # -------jianjun gitee 配置 -------- -owner = src-openeuler -#owner = cve-test +#owner = src-openeuler +owner = cve-test path = jasper email = 7844966+zhangjianjun_code@user.noreply.gitee.com redirect_uri = http://159.138.2.2:80/v1/issue/oauth/callback diff --git a/controllers/hook.go b/controllers/hook.go index 71e0cce296cd9ac423fd4c926b5dc374a818decf..84465347da094bead4cb25f9846b882040618a77 100644 --- a/controllers/hook.go +++ b/controllers/hook.go @@ -2131,9 +2131,9 @@ func DelOrgIssue(issueHook *models.IssuePayload) { // Entry function for handling issue status func gitAddIssueProc(issueHook *models.IssuePayload) error { - token := beego.AppConfig.String("gitee::git_token") + token := os.Getenv("GITEE_TOKEN") owner := beego.AppConfig.String("gitee::owner") - path := issueHook.Issue.Repository.Path + path := issueHook.Repository.Path // The amount of data processed at a time prcNum, err := beego.AppConfig.Int("crontab::prcnum") if err != nil { @@ -2168,9 +2168,53 @@ func gitAddIssueProc(issueHook *models.IssuePayload) error { if createErr != nil { logs.Error("Failed to synchronize issue data of cve, err: ", createErr) } + comErr := AddIssueComment(token, owner, path, issueHook.Issue.Number, + issueHook.Issue.User.Login, issueHook.Issue.Id) + logs.Info("CreateIssueToGit, Issue comment creation result, err: ", comErr) return createErr } +func AddIssueComment(token, owner, path, issueNum, assignee string, issueId int64) error { + // Create the first comment + branchList := []string{} + errBrands := errors.New("") + // Get branch information + branchList, errBrands = taskhandler.GetBranchesInfo(token, owner, path) + if branchList == nil || len(branchList) == 0 { + logs.Error("gitAddIssueProc, Failed to obtain the branch information of the repo, ", path, ", err: ", errBrands) + return errors.New("Failed to obtain branch information") + } + // Create issue comment + affectedVersion := "" + if len(branchList) > 0 { + for i, brand := range branchList { + if brand == "" || len(brand) < 2 { + continue + } + affectedVersion = affectedVersion + strconv.Itoa(i+1) + "." + brand + ":\n" + } + } else { + affectedVersion = affectedVersion + "\n" + } + issueTmp := models.IssueTemplate{} + issueTmp.IssueId = issueId + issueTmp.IssueNum = issueNum + issueTmp.OwnedComponent = path + issueErr := models.GetIssueTemplateByColName(&issueTmp, "issue_num", "owned_component", "issue_id") + if issueErr != nil { + logs.Error("GetIssueTemplateByColName, err: ", issueErr, ", issue: ", issueTmp) + return issueErr + } + cveCenter := models.VulnCenter{CveId: issueTmp.CveId, CveNum: issueTmp.CveNum, PackName: path} + cveErr := models.GetVulnCenterByCid(&cveCenter, "cve_id", "cve_num", "pack_name") + if cveErr != nil { + return cveErr + } + errx := taskhandler.CreateIssueComment(token, owner, path, assignee, + cveCenter, issueNum, affectedVersion) + return errx +} + func gitDelIssueProc(issueHook *models.IssuePayload) error { DelOrgIssue(issueHook) return nil diff --git a/models/modeldb.go b/models/modeldb.go index ce1ed275c5411c4057612a473dc5e81f5fbc8676..cf2056208ca6434f91068f4904c4735314119871 100644 --- a/models/modeldb.go +++ b/models/modeldb.go @@ -150,7 +150,7 @@ type IssueTemplate struct { AffectedVersion string `orm:"size(256);column(affected_version)" description:"受影响的版本"` Solution string `orm:"size(1024);column(solution)" description:"规避方案或消减措施"` IssueId int64 `orm:"column(issue_id)" description:"issue的id"` - IssueNum string `orm:"size(64);column(issue_num);index" description:"issue编号"` + IssueNum string `orm:"size(64);column(issue_num)" description:"issue编号"` Assignee string `orm:"size(128);column(issue_assignee)" description:"issue所属责任人"` Status int8 `orm:"default(1);column(status)" description:"1:待办的;2:进行中;3:已完成;4:已拒绝;5: 已挂起; 6:已删除"` StatusName string `orm:"size(128);column(status_name)" description:"issue状态名称"` diff --git a/taskhandler/assist.go b/taskhandler/assist.go index 986523274e66099e2303f453dc00ca99cd2ea3de..2fad138cfeb926521309b596cf7b7e0a3d796fa5 100644 --- a/taskhandler/assist.go +++ b/taskhandler/assist.go @@ -88,6 +88,7 @@ func GetBranchesInfo(accessToken string, owner string, path string) ([]string, e continue } mapValue := value["name"].(string) + logs.Info(mapValue) if mapValue != "" && len(mapValue) > 3 { if mapValue == "openEuler-20.03-LTS" || mapValue == "openEuler-20.09" || diff --git a/taskhandler/createissue.go b/taskhandler/createissue.go index cdc4a1694571a3067ad9964aab724ba61140bfae..27519deb82037307ab1e2e764036c0bfb2c0e9e6 100644 --- a/taskhandler/createissue.go +++ b/taskhandler/createissue.go @@ -266,12 +266,13 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, } else { affectedVersion = affectedVersion + "\n" } - errx := CreateIssueComment(accessToken, owner, path, assignee, cve, resp, affectedVersion) + issueNum := resp["number"].(string) + errx := CreateIssueComment(accessToken, owner, path, assignee, cve, issueNum, affectedVersion) logs.Info("CreateIssueToGit, Issue comment creation result, err: ", errx) // Send gitee private message content := fmt.Sprintf("%v 仓库有新的CVE和安全问题的ISSUE被 cve-manager 创建,CVE编号: %v, 请及时处理.", path, cve.CveNum) SendPrivateLetters(accessToken, content, assignee) - issueNum := resp["number"].(string) + //issueNum := resp["number"].(string) issueID := int64(resp["id"].(float64)) err = CreateDepositHooks(accessToken, owner, path, cve, issueNum, issueID) if err != nil { @@ -589,8 +590,8 @@ func CreateDepositHooks(accessToken string, owner string, path string, } func CreateIssueComment(accessToken, owner, path, assignee string, - cve models.VulnCenter, issResp map[string]interface{}, affectedVersion string) error { - issueNum := issResp["number"].(string) + cve models.VulnCenter, issueNum, affectedVersion string) error { + //issueNum := issResp["number"].(string) if accessToken != "" && owner != "" && path != "" { url := "https://gitee.com/api/v5/repos/" + owner + "/" + path + "/issues/" + issueNum + "/comments" BConfig, err := config.NewConfig("ini", "conf/app.conf") diff --git a/taskhandler/hook.go b/taskhandler/hook.go index 44e3d915257da81585346983f8a54d6955f88dad..eb81912569c0e110efef04c8c99d3a9a57c66895 100644 --- a/taskhandler/hook.go +++ b/taskhandler/hook.go @@ -49,6 +49,26 @@ func ProcHookEvent(hookurl, owner, accessToken, pwd, gaussOwner, gitGaussToken s break } } + // Check whether the warehouse is missing + dbRepo := models.QueryOrgAllRepo(owner) + if len(dbRepo) > 0 { + for _, v := range dbRepo { + var hd []HookData + GetDepositHooks(accessToken, owner, v.Path, &hd) + if len(hd) > 0 { + for _, hdx := range hd { + if hdx.HookUrl == hookurl && pwd == hdx.Password { + var localIh models.IssueHooks + localIh.HookUrl = hookurl + localIh.Repo = v.Path + localIh.HookId = hdx.Id + localIh.Owner = owner + PrcMutDepositHooks(accessToken, pwd, localIh, hd, deleteHook, gaussOwner) + } + } + } + } + } return nil } diff --git a/util/http.go b/util/http.go index fc8d02378fe39f0834d7daac6eac272ba788fd07..74c91f57d997fc732a6d78ee22efed61344f3f57 100644 --- a/util/http.go +++ b/util/http.go @@ -188,7 +188,7 @@ func HTTPGet(url string) ([]map[string]interface{}, error) { var col []map[string]interface{} err = json.Unmarshal(body, &col) if err != nil { - logs.Error(err) + logs.Error("HTTPGet,err: ", err, "url: ", url) } return col, nil } @@ -210,7 +210,7 @@ func HTTPGetCom(urls string) ([]byte, error) { return body, nil } -func HTTPDelCom(url, requestBody string) (map[string]interface{}, error) { +func HTTPDelCom(url, requestBody string) ([]map[string]interface{}, error) { req, err := http.NewRequest("DELETE", url, bytes.NewBuffer([]byte(requestBody))) defer common.Catchs() if err != nil { @@ -239,7 +239,7 @@ func HTTPDelCom(url, requestBody string) (map[string]interface{}, error) { return nil, err } logs.Info("DELETE successed!, body: ", string(body)) - var iss map[string]interface{} + var iss []map[string]interface{} err = json.Unmarshal(body, &iss) if err != nil { logs.Error(err, string(body))