aboutsummaryrefslogtreecommitdiffstats
path: root/services/webhook/matrix.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/webhook/matrix.go')
-rw-r--r--services/webhook/matrix.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go
index 5e9f808d8b..3e9163f78c 100644
--- a/services/webhook/matrix.go
+++ b/services/webhook/matrix.go
@@ -15,6 +15,7 @@ import (
"strings"
webhook_model "code.gitea.io/gitea/models/webhook"
+ "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
@@ -24,6 +25,10 @@ import (
webhook_module "code.gitea.io/gitea/modules/webhook"
)
+func init() {
+ RegisterWebhookRequester(webhook_module.MATRIX, newMatrixRequest)
+}
+
func newMatrixRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &MatrixMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
@@ -52,7 +57,7 @@ func newMatrixRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_mo
}
req.Header.Set("Content-Type", "application/json")
- return req, body, addDefaultHeaders(req, []byte(w.Secret), t, body) // likely useless, but has always been sent historially
+ return req, body, addDefaultHeaders(req, []byte(w.Secret), w, t, body) // likely useless, but has always been sent historially
}
const matrixPayloadSizeLimit = 1024 * 64
@@ -240,6 +245,25 @@ func (m matrixConvertor) Package(p *api.PackagePayload) (MatrixPayload, error) {
return m.newPayload(text)
}
+func (m matrixConvertor) Status(p *api.CommitStatusPayload) (MatrixPayload, error) {
+ refLink := htmlLinkFormatter(p.TargetURL, fmt.Sprintf("%s [%s]", p.Context, base.ShortSha(p.SHA)))
+ text := fmt.Sprintf("Commit Status changed: %s - %s", refLink, p.Description)
+
+ return m.newPayload(text)
+}
+
+func (m matrixConvertor) WorkflowRun(p *api.WorkflowRunPayload) (MatrixPayload, error) {
+ text, _ := getWorkflowRunPayloadInfo(p, htmlLinkFormatter, true)
+
+ return m.newPayload(text)
+}
+
+func (m matrixConvertor) WorkflowJob(p *api.WorkflowJobPayload) (MatrixPayload, error) {
+ text, _ := getWorkflowJobPayloadInfo(p, htmlLinkFormatter, true)
+
+ return m.newPayload(text)
+}
+
var urlRegex = regexp.MustCompile(`<a [^>]*?href="([^">]*?)">(.*?)</a>`)
func getMessageBody(htmlText string) string {