From 04c1683a1ed7695832da14614589ce83af40a2f9 Mon Sep 17 00:00:00 2001 From: zhangjianjun_code <7844966+zhangjianjun_code@user.noreply.gitee.com> Date: Wed, 18 Nov 2020 18:33:29 +0800 Subject: [PATCH] 1. Fail to identify the current file; 2. Optimize the code --- controllers/hook.go | 54 +++++++++---------------- cve-py/downloadtask/downloadfiletask.py | 2 +- go.mod | 2 +- taskhandler/cve.go | 46 ++++++++++++++++++--- 4 files changed, 62 insertions(+), 42 deletions(-) diff --git a/controllers/hook.go b/controllers/hook.go index af79746..40819ee 100644 --- a/controllers/hook.go +++ b/controllers/hook.go @@ -543,7 +543,7 @@ func paraAffectBrandBool(affectedVersion string) bool { brandList := strings.Split(brand, ":") if len(brandList) > 1 { prams := strings.Replace(brandList[1], " ", "", -1) - if prams == "受影响" || prams == "不受影响"{ + if prams == "受影响" || prams == "不受影响" { unaffectedBranchList = append(unaffectedBranchList, brandList[0]) } } else { @@ -772,6 +772,7 @@ func handleIssueComment(payload models.CommentPayload) { token := os.Getenv("GITEE_TOKEN") owner := beego.AppConfig.String("gitee::owner") fixed := beego.AppConfig.String("labelFixed") + unfixed := beego.AppConfig.String("labelUnFix") approveFlag := true if issueTmp.OpenEulerScore != issueTmp.NVDScore && issueTmp.OpAuditFlag != 1 && issueTmp.OpenEulerScore > 0 { @@ -798,9 +799,6 @@ func handleIssueComment(payload models.CommentPayload) { if approveFlag { mtAuditFlag := false // Analysis command belongs to the time period - //if issueTmp.MtAuditFlag == 0 { - // - //} maintainerList, mainOk := models.QueryRepoAllMaintainer(issueTmp.Repo) if mainOk && len(maintainerList) > 0 { for _, v := range maintainerList { @@ -829,10 +827,12 @@ func handleIssueComment(payload models.CommentPayload) { if err != nil { return } - issueTmp.IssueLabel = fixed - issueTmp.StatusName = "closed" + issueTmp.IssueLabel = unfixed + issueTmp.StatusName = "open" issuePrFlag := VerifyIssueAsPr(&issueTmp, cveCenter, true) if issuePrFlag { + issueTmp.IssueLabel = fixed + issueTmp.StatusName = "closed" taskhandler.AddCommentToIssue(fmt.Sprintf(`@%v 你已审核模板内容,cve-manager 将关闭issue!`, cuAccount), issueTmp.IssueNum, owner, issueTmp.Repo, token) _, issueErr := taskhandler.UpdateIssueToGit(token, owner, issueTmp.Repo, @@ -905,10 +905,12 @@ func handleIssueComment(payload models.CommentPayload) { if err != nil { return } - issueTmp.IssueLabel = fixed - issueTmp.StatusName = "closed" + issueTmp.IssueLabel = unfixed + issueTmp.StatusName = "open" issuePrFlag := VerifyIssueAsPr(&issueTmp, cveCenter, false) if issuePrFlag { + issueTmp.IssueLabel = fixed + issueTmp.StatusName = "closed" taskhandler.AddCommentToIssue(fmt.Sprintf(`@%v 你已审核模板内容,cve-manager 将关闭issue!`, cuAccount), issueTmp.IssueNum, owner, issueTmp.Repo, token) _, issueErr := taskhandler.UpdateIssueToGit(token, owner, issueTmp.Repo, @@ -1003,22 +1005,6 @@ func handleIssueComment(payload models.CommentPayload) { } } else { cBody = strings.ReplaceAll(cBody, ":", ":") - //hookTimeout, hookoutOk := beego.AppConfig.Int64("hook::hook_timeout") - //if hookoutOk != nil { - // hookTimeout = 3600 - //} - //unixTime := common.PraseTimeInt(payload.Comment.UpdateAt) - //timeStamp := common.CurTimestamp() - //logs.Info("unixTime: ", unixTime, ", timeStamp: ", timeStamp, - // ", hookTimeout: ", hookTimeout) - //if unixTime > 0 && timeStamp > 0 { - // if timeStamp-unixTime > hookTimeout { - // logs.Error("The time that the hook receives is timed out, "+ - // "discarded, and not processed, unixTime: ", unixTime, ", timeStamp: ", timeStamp, - // ", hookTimeout: ", hookTimeout, ",created_at: ", payload.Comment.UpdateAt) - // return - // } - //} analysisComment(issueNum, cuAccount, cBody, &payload) } } @@ -1041,14 +1027,13 @@ func analysisComment(issueNum string, cuAccount string, cBody string, payload *m return } canVerfy := false - if issueTmp.MtAuditFlag != 1 { - maintainerList, mainOk := models.QueryRepoAllMaintainer(issueTmp.Repo) - if mainOk && len(maintainerList) > 0 { - for _, v := range maintainerList { - if cuAccount == v.MemberName { - issueTmp.MtAuditFlag = 1 - break - } + issueTmp.MtAuditFlag = 0 + maintainerList, mainOk := models.QueryRepoAllMaintainer(issueTmp.Repo) + if mainOk && len(maintainerList) > 0 { + for _, v := range maintainerList { + if cuAccount == v.MemberName { + issueTmp.MtAuditFlag = 1 + break } } } @@ -1163,7 +1148,6 @@ func analysisComment(issueNum string, cuAccount string, cBody string, payload *m na = "\n**因OpenEulerScore与NvdScore不一致,分析内容需审核,请等待安全组审核!**" //Notify the responsible person for review notifyAuditorReview(payload, issueTmp) - //issueTmp.MtAuditFlag = 0 } else { if issueTmp.MtAuditFlag == 0 { maintainerList, mainOk := models.QueryRepoAllMaintainer(issueTmp.Repo) @@ -1182,11 +1166,11 @@ func analysisComment(issueNum string, cuAccount string, cBody string, payload *m } else { assignee = "@" + issueTmp.Assignee } - na = "\n**请确认模板分析内容的准确性与完整性,确认无误后,请在评论区输入: /approve, 否则无法关闭当前issue.**" + na = "\n**请确认模板分析内容的准确性与完整性, 确认无误后,请在评论区输入: /approve, 否则无法关闭当前issue.**" cc := fmt.Sprintf(ContentReview, assignee) + tb + na taskhandler.AddCommentToIssue(cc, issueTmp.IssueNum, owner, path, accessToken) } else { - na = "\n**请确认分析内容的准确性,确认无误后,您可以进行后续步骤,否则您可以继续分析.**" + na = "\n**请确认分析内容的准确性, 确认无误后, 您可以进行后续步骤, 否则您可以继续分析.**" cc := fmt.Sprintf(AnalysisComplete, issueTmp.Assignee) + tb + na taskhandler.AddCommentToIssue(cc, issueTmp.IssueNum, owner, path, accessToken) } diff --git a/cve-py/downloadtask/downloadfiletask.py b/cve-py/downloadtask/downloadfiletask.py index 9f2899b..b2667a3 100644 --- a/cve-py/downloadtask/downloadfiletask.py +++ b/cve-py/downloadtask/downloadfiletask.py @@ -96,7 +96,7 @@ def handle_three(): """ if os.listdir("./import_excels"): shutil.rmtree("./import_excels") - os.mkdir("./mappingexcels") + os.mkdir("./import_excels") url = 'https://gitee.com/openeuler/cve-manager/tree/master/cve-py/import_excels' try: r = requests.get(url) diff --git a/go.mod b/go.mod index 4cea6a2..4205ccc 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/spf13/viper v1.7.1 // indirect go.starlark.net v0.0.0-20201113214410-e292e66a28cd // indirect golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff // indirect - golang.org/x/sys v0.0.0-20201116194326-cc9327a14d48 // indirect + golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7 // indirect golang.org/x/text v0.3.4 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect diff --git a/taskhandler/cve.go b/taskhandler/cve.go index 372f642..90e0d1b 100644 --- a/taskhandler/cve.go +++ b/taskhandler/cve.go @@ -1305,11 +1305,17 @@ func UpdateIssueCveGroups(cveData models.GiteOriginIssue, lop models.Loophole, c if nvdError == nil && nvdScore > 0 { issueTemp.NVDScore = nvdScore } - issueTemp.OpenEulerVector = lop.OpVector + if lop.OpVector != "" && len(lop.OpVector) > 1 { + issueTemp.OpenEulerVector = lop.OpVector + } issueTemp.CveBrief = RemoveSubstring(lop.BriefIntroduction, specCharList) - issueTemp.CveAnalysis = lop.Influences + if lop.Influences != "" && len(lop.Influences) > 1 { + issueTemp.CveAnalysis = lop.Influences + } issueTemp.PrincipleAnalysis = lop.Principle - issueTemp.AffectedVersion = lop.InfVersion + if paraAffectBrandBool(lop.InfVersion) { + issueTemp.AffectedVersion = lop.InfVersion + } issueTemp.Solution = lop.AvoidScheme issueTemp.IssueId = cveData.IssueId issueTemp.IssueNum = cveData.Number @@ -1324,6 +1330,7 @@ func UpdateIssueCveGroups(cveData models.GiteOriginIssue, lop models.Loophole, c } else if strings.ToLower(cveData.State) == "closed" || cveData.State == "已完成" { issueTemp.Status = 3 issueTemp.IssueStatus = 2 + issueTemp.MtAuditFlag = 1 } else if strings.ToLower(cveData.State) == "rejected" || cveData.State == "已拒绝" { issueTemp.Status = 4 issueTemp.IssueStatus = 6 @@ -1402,8 +1409,6 @@ func UpdateIssueCveGroups(cveData models.GiteOriginIssue, lop models.Loophole, c issueTemp.IssueType = cveData.IssueType issueTemp.CveLevel = vul.CveLevel } - //issueTemp.MtAuditFlag = 1 - //issueTemp.SaAuditFlag = 1 // Store issue data issTempId, issError := models.CreateIssueTemplate(&issueTemp) if issError != nil { @@ -1415,6 +1420,37 @@ func UpdateIssueCveGroups(cveData models.GiteOriginIssue, lop models.Loophole, c return true, nil } +func paraAffectBrandBool(affectedVersion string) bool { + unaffectedBranchList := []string{} + brandsGroup := strings.Split(affectedVersion, ",") + if len(brandsGroup) > 0 { + for _, brand := range brandsGroup { + if brand == "" || len(brand) < 2 { + continue + } + brandList := strings.Split(brand, ":") + if len(brandList) > 1 { + prams := strings.Replace(brandList[1], " ", "", -1) + if prams == "受影响" || prams == "不受影响"{ + unaffectedBranchList = append(unaffectedBranchList, brandList[0]) + } + } else { + brandList = strings.Split(brand, ":") + if len(brandList) > 1 { + prams := strings.Replace(brandList[1], " ", "", -1) + if prams == "受影响" || prams == "不受影响" { + unaffectedBranchList = append(unaffectedBranchList, brandList[0]) + } + } + } + } + } + if len(unaffectedBranchList) > 0 { + return true + } + return false +} + func GenCveVulerByIssue(cveData models.GiteOriginIssue, cveRef string, openeulernum int, owner string) (bool, error) { defer common.Catchs() hole, err := cveData.ParseToLoophole() -- Gitee