Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func main() {
http.HandleFunc(fmt.Sprintf("/webhook/%s/botkube", os.Getenv("WEBHOOK_SECRET")), api.TransformBotKube)
http.HandleFunc(fmt.Sprintf("/webhook/%s/devguard", os.Getenv("WEBHOOK_SECRET")), api.TransformDevGuard)
http.HandleFunc(fmt.Sprintf("/webhook/%s/github", os.Getenv("WEBHOOK_SECRET")), api.TransformGithub)
http.HandleFunc(fmt.Sprintf("/webhook/%s/documentationassignment", os.Getenv("WEBHOOK_SECRET")), api.TransformDocumentationAssigment)
addr := fmt.Sprintf("0.0.0.0:%d", Port)
log.Printf("Listening at %s", addr)
log.Fatal(http.ListenAndServe(addr, nil))
Expand Down
13 changes: 13 additions & 0 deletions pkg/api/models/documentationassignment.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local input = std.parseJson(std.extVar("input"));

local message = if std.objectHas(input, "message") then input.message else "No message provided";
local link = if std.objectHas(input, "link") then input.link else "";

local plain = if link != "" then message + " " + link else message;

local html = if link != "" then message + " <a href=\"" + link + "\">"+link+"</a>" else message;

{
plain: plain,
html: html
}
16 changes: 12 additions & 4 deletions pkg/api/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
type AppModel string

const (
GlitchTip AppModel = "glitchtip"
Botkube AppModel = "botkube"
DevGuard AppModel = "devguard"
Github AppModel = "github"
GlitchTip AppModel = "glitchtip"
Botkube AppModel = "botkube"
DevGuard AppModel = "devguard"
Github AppModel = "github"
DocumentationAssigment AppModel = "documentationassignment"
)

//go:embed models/glitchtip.libsonnet
Expand All @@ -34,6 +35,9 @@ var mappingCodeDevGuard string
//go:embed models/github.libsonnet
var mappingCodeGithub string

//go:embed models/documentationassignment.libsonnet
var mappingCodeDocumentationAssigment string

func TransformGlitchTip(res http.ResponseWriter, req *http.Request) {
transform(res, req, GlitchTip, mappingCodeGlitchTip)
}
Expand All @@ -50,6 +54,10 @@ func TransformGithub(res http.ResponseWriter, req *http.Request) {
transform(res, req, Github, mappingCodeGithub)
}

func TransformDocumentationAssigment(res http.ResponseWriter, req *http.Request) {
transform(res, req, DocumentationAssigment, mappingCodeDocumentationAssigment)
}

func bodyToString(req *http.Request) (*string, error) {
defer req.Body.Close()
body, err := io.ReadAll(req.Body)
Expand Down
24 changes: 24 additions & 0 deletions pkg/api/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,27 @@ func TestDevGuardMultipleVulnerabilitiesMessage(t *testing.T) {
Html: expectedHtml,
}, msg)
}

func TestTransformDocumentationAssigment(t *testing.T) {
// Input JSON for the custom message
jsonStr := `{
"message": "Time to review the documentation page",
"link": "https://example.com/docs-page"
}`

// Call your custom message function
msg, err := convertRawJsonToMatrixMessage(jsonStr, DocumentationAssigment, mappingCodeDocumentationAssigment)
assert.NoError(t, err)

// Expected plain text output
expectedPlain := "Time to review the documentation page https://example.com/docs-page"

// Expected HTML output
expectedHtml := `Time to review the documentation page <a href="https://example.com/docs-page">link</a>`

// Compare the outputs
assert.Equal(t, &MatrixMessage{
Plain: expectedPlain,
Html: expectedHtml,
}, msg)
}