MCPcopy Create free account
hub / github.com/bytebase/bytebase / postMessage

Function postMessage

backend/plugin/webhook/slack/slack.go:215–251  ·  view source on GitHub ↗
(context webhook.Context)

Source from the content-addressed store, hash-verified

213}
214
215func postMessage(context webhook.Context) error {
216 post := BuildMessage(context)
217 body, err := json.Marshal(post)
218 if err != nil {
219 return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
220 }
221 req, err := http.NewRequest("POST",
222 context.URL, bytes.NewBuffer(body))
223 if err != nil {
224 return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
225 }
226
227 req.Header.Set("Content-Type", "application/json")
228 client := &http.Client{
229 Timeout: webhook.Timeout,
230 }
231 resp, err := client.Do(req)
232 if err != nil {
233 return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
234 }
235
236 b, err := io.ReadAll(resp.Body)
237 if err != nil {
238 return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)
239 }
240 defer resp.Body.Close()
241
242 if resp.StatusCode != http.StatusOK {
243 return errors.Errorf("failed to POST webhook to %s, status code: %d, response body: %s", context.URL, resp.StatusCode, b)
244 }
245
246 if string(b) != "ok" {
247 return errors.Errorf("%.100s", string(b))
248 }
249
250 return nil
251}
252
253func postDirectMessage(webhookCtx webhook.Context) bool {
254 ctx := context.Background()

Callers 1

PostMethod · 0.70

Calls 5

DoMethod · 0.80
ErrorfMethod · 0.80
BuildMessageFunction · 0.70
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected