(context webhook.Context)
| 59 | } |
| 60 | |
| 61 | func getMessageCard(context webhook.Context) *WebhookMarkdown { |
| 62 | metaStrList := []string{} |
| 63 | for _, meta := range context.GetMetaList() { |
| 64 | metaStrList = append(metaStrList, fmt.Sprintf("**%s**: %s", meta.Name, meta.Value)) |
| 65 | } |
| 66 | if context.ActorName != "" { |
| 67 | metaStrList = append(metaStrList, fmt.Sprintf("**Actor**: %s (%s)", context.ActorName, context.ActorEmail)) |
| 68 | } |
| 69 | |
| 70 | status := "" |
| 71 | switch context.Level { |
| 72 | case webhook.WebhookSuccess: |
| 73 | status = "<font color=\"green\">Success</font> " |
| 74 | case webhook.WebhookWarn: |
| 75 | status = "<font color=\"yellow\">Warn</font> " |
| 76 | case webhook.WebhookError: |
| 77 | status = "<font color=\"red\">Error</font> " |
| 78 | default: |
| 79 | // For any other level (including WebhookInfo), use no special formatting |
| 80 | status = "" |
| 81 | } |
| 82 | content := fmt.Sprintf("# %s%s\n\n%s\n[View in Bytebase](%s)", status, context.Title, strings.Join(metaStrList, "\n"), context.Link) |
| 83 | if context.Description != "" { |
| 84 | content = fmt.Sprintf("# %s%s\n> %s\n\n%s\n[View in Bytebase](%s)", status, context.Title, context.Description, strings.Join(metaStrList, "\n"), context.Link) |
| 85 | } |
| 86 | return &WebhookMarkdown{ |
| 87 | Content: content, |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func (r *Receiver) Post(context webhook.Context) error { |
| 92 | if context.DirectMessage && len(context.MentionEndUsers) > 0 { |
no test coverage detected