Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work wechat webhook #5252

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 24 additions & 5 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ func (w *Webhook) GetDiscordHook() *DiscordMeta {
return s
}

// GetWorkwechatHook returns work wechat metadata
func (w *Webhook) GetWorkwechatHook() *WorkwechatMeta {
s := &WorkwechatMeta{}

if err := json.Unmarshal([]byte(w.Meta), s); err != nil {
log.Error(4, "webhook.GetWorkwechatMetaHook(%d): %v", w.ID, err)
}
return s
}

// History returns history of webhook by given conditions.
func (w *Webhook) History(page int) ([]*HookTask, error) {
return HookTasks(w.ID, page)
Expand Down Expand Up @@ -382,14 +392,16 @@ const (
GITEA
DISCORD
DINGTALK
WORKWECHAT
)

var hookTaskTypes = map[string]HookTaskType{
"gitea": GITEA,
"gogs": GOGS,
"slack": SLACK,
"discord": DISCORD,
"dingtalk": DINGTALK,
"gitea": GITEA,
"gogs": GOGS,
"slack": SLACK,
"discord": DISCORD,
"dingtalk": DINGTALK,
"workwechat": WORKWECHAT,
}

// ToHookTaskType returns HookTaskType by given name.
Expand All @@ -410,6 +422,8 @@ func (t HookTaskType) Name() string {
return "discord"
case DINGTALK:
return "dingtalk"
case WORKWECHAT:
return "workwechat"
}
return ""
}
Expand Down Expand Up @@ -579,6 +593,11 @@ func prepareWebhook(e Engine, w *Webhook, repo *Repository, event HookEventType,
if err != nil {
return fmt.Errorf("GetDingtalkPayload: %v", err)
}
case WORKWECHAT:
payloader, err = GetWorkwechatPayload(p, event, w.Meta)
if err != nil {
return fmt.Errorf("GetWorkwechatPayload: %v", err)
}
default:
p.SetSecret(w.Secret)
payloader = p
Expand Down