diff --git a/controllers/hook.go b/controllers/hook.go index 84465347da094bead4cb25f9846b882040618a77..f21e8d57a91e2b5ba416dc9d4a0431bea03ad1e6 100644 --- a/controllers/hook.go +++ b/controllers/hook.go @@ -31,9 +31,9 @@ var ( //NoteHookType type of comment NoteHookType = "Note Hook" //PullReqHookType type of pull request - PullReqHookType = "merge_request_hooks" + PullReqHookType = "Merge Request Hook" //PushTagHookType type of push or tag - PushTagHookType = "push_hooks/tag_push_hooks" + PushTagHookType = "Tag Push Hook" //IssueHookType type of issue IssueHookType = "Issue Hook" ) @@ -92,6 +92,7 @@ func (c *HookEventControllers) Post() { eventType := c.Ctx.Request.Header.Get(XGIteeEventType) c.Ctx.ResponseWriter.WriteHeader(200) c.Ctx.WriteString("Event received: " + eventType) + logs.Info("Event received: ", eventType) switch eventType { case NoteHookType: //handle comment hook data c.handleNoteDate() @@ -125,15 +126,17 @@ func (c *HookEventControllers) isLegitimateHookEvent() (ok bool) { } func (c *HookEventControllers) handleNoteDate() { + logs.Info(string(c.Ctx.Input.RequestBody)) var hookNote models.CommentPayload err := json.Unmarshal(c.Ctx.Input.RequestBody, &hookNote) if err != nil { logs.Error(err) return } + logs.Info(string(c.Ctx.Input.RequestBody)) hookPwd := beego.AppConfig.String("hook::hookpwd") if hookNote.Action == "comment" && hookNote.NoteableType == "Issue" && hookNote.Password == hookPwd { - logs.Info(string(c.Ctx.Input.RequestBody)) + //logs.Info(string(c.Ctx.Input.RequestBody)) //handle issue comment go handleIssueComment(hookNote) } diff --git a/models/hookevent.go b/models/hookevent.go index 83f5c65e7ed777eb86870780cb05e1b8e17ccd46..14ed1233cf9bfb950bfc8b815a06d820c98be400 100644 --- a/models/hookevent.go +++ b/models/hookevent.go @@ -72,12 +72,12 @@ type HookComment struct { type CommentPayload struct { Action string // Action comment HookName string `json:"hook_name"` - Password string //The password of the hook + Password string `json:"password"` //The password of the hook HookId int64 `json:"hook_id"` //Hook ID HookUrl string `json:"hook_url"` //Hook routing Timestamp string Sign string //The signature calculated by the hook based on the key - Comment *HookComment //Comment data + Comment *HookComment `json:"comment"`//Comment data Note string //Comment data of the commented target NoteableType string `json:"noteable_type"` //Target type being reviewed NoteableId int64 `json:"noteable_id"` //ID of the target being reviewed diff --git a/models/issue.go b/models/issue.go index d2e4da5040734c23ee8eea3c6071d7d1eebc9a1f..e6ac991d2e694c09daf9ce61d183554eb111d357 100644 --- a/models/issue.go +++ b/models/issue.go @@ -328,6 +328,12 @@ func GetAllIssueHook(hookId int64, count, status int) (localh []IssueHooks, valu } } +func UpdateIssueHook(id int64, status int8) { + o := orm.NewOrm() + _ = o.Raw("UPDATE cve_issue_hooks SET status = ? WHERE id = ?", status, id).QueryRow() + return +} + func GetIssueHook(ih *IssueHooks) (localh []IssueHooks, value bool) { o := orm.NewOrm() var localIh []IssueHooks diff --git a/taskhandler/hook.go b/taskhandler/hook.go index eb81912569c0e110efef04c8c99d3a9a57c66895..9b862445595eb20fe17f5a49e27dc34605802a92 100644 --- a/taskhandler/hook.go +++ b/taskhandler/hook.go @@ -93,11 +93,12 @@ func GetDepositHooks(accessToken, owner, repo string, hd *[]HookData) { } } -func PrcMutDepositHooks(accessToken, pwd string, ihk models.IssueHooks, hd []HookData, deleteHook int, gaussOwner string) { +func PrcMutDepositHooks(accessToken, pwd string, ihk models.IssueHooks, + hd []HookData, deleteHook int, gaussOwner string) { for _, hdk := range hd { if ihk.HookUrl == hdk.HookUrl && hdk.Password == pwd { if deleteHook == 2 && ihk.Owner != gaussOwner { - go DeleteDepositHooks(accessToken, ihk.Owner, ihk.Repo, hdk.Id) + go DeleteRepoHooks(accessToken, ihk.Owner, ihk.Repo, hdk.Id, ihk.Id) } else { if hdk.Id != ihk.HookId && ihk.HookId > 0 { go DeleteDepositHooks(accessToken, ihk.Owner, ihk.Repo, hdk.Id) @@ -107,6 +108,11 @@ func PrcMutDepositHooks(accessToken, pwd string, ihk models.IssueHooks, hd []Hoo } } +func DeleteRepoHooks(accessToken, owner, repo string, hookId, ihkId int64) { + DeleteDepositHooks(accessToken, owner, repo, hookId) + models.UpdateIssueHook(ihkId, 2) +} + func DeleteDepositHooks(accessToken, owner, repo string, hookId int64) { url := fmt.Sprintf("https://gitee.com/api/v5/repos/%v/%v/hooks/%v", owner, repo, hookId) requestBody := fmt.Sprintf(`{