Skip to content

Commit

Permalink
Fix schemas for gh-events and flux, fix render in gh-events
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Sep 1, 2023
1 parent 6a97a68 commit 43f59aa
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 44 deletions.
42 changes: 7 additions & 35 deletions internal/executor/flux/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package flux

import (
"context"
_ "embed"
"fmt"

"github.com/MakeNowJust/heredoc"
"github.com/allegro/bigcache/v3"

"github.com/kubeshop/botkube/internal/executor/flux/commands"
Expand All @@ -17,6 +17,9 @@ import (
"github.com/kubeshop/botkube/pkg/pluginx"
)

//go:embed jsonschema.json
var jsonschema string

const (
PluginName = "flux"
description = "Run the Flux CLI commands directly from your favorite communication platform."
Expand All @@ -43,7 +46,9 @@ func (d *Executor) Metadata(context.Context) (api.MetadataOutput, error) {
Version: d.pluginVersion,
Description: description,
Dependencies: getPluginDependencies(),
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: jsonschema,
},
}, nil
}

Expand Down Expand Up @@ -168,36 +173,3 @@ func (d *Executor) Help(context.Context) (api.Message, error) {

return out.Message, nil
}

// jsonSchema returns JSON schema for the executor.
func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Flux",
"description": "%s",
"type": "object",
"properties": {
"github": {
"title": "GitHub",
"type": "object",
"properties": {
"auth": {
"title": "Auth",
"type": "object",
"properties": {
"accessToken": {
"title": "Access Token",
"description": "The GitHub access token. When not provided, some functionality may not work. For example, adding a comment under a pull request.",
"type": "string"
}
}
}
}
}
},
"required": []
}
`, description),
}
}
36 changes: 36 additions & 0 deletions internal/executor/flux/jsonschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Flux",
"description": "Run the Flux CLI commands directly from your favorite communication platform.",
"type": "object",
"uiSchema": {
"github": {
"auth": {
"accessToken": {
"ui:widget": "password",
"ui:help": "Hint: Make it strong!"
}
}
}
},
"properties": {
"github": {
"title": "GitHub",
"type": "object",
"properties": {
"auth": {
"title": "Auth",
"type": "object",
"properties": {
"accessToken": {
"title": "Access Token",
"description": "Instructions for token creation: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/#creating-a-token.\n\nLack of token may limit functionality, e.g., adding comments to pull requests or approving them.",
"type": "string"
}
}
}
}
}
},
"required": []
}
3 changes: 2 additions & 1 deletion internal/source/github_events/github_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func (w *Watcher) emitMatchingEvent(ctx context.Context, stream *source.StreamOu
continue // let's check other events
}
stream.Event <- source.Event{
Message: msg,
Message: msg,
RawObject: payload,
}
}
}
Expand Down
49 changes: 42 additions & 7 deletions internal/source/github_events/jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,47 @@
"description": "GitHub Events configuration parameters",
"type": "object",
"uiSchema": {
"github": {
"auth": {
"accessToken": {
"ui:widget": "password"
}
}
},
"repositories": {
"on": {
"pullRequests": {
"notificationTemplate": {
"extraButtons": {
"displayName": {
"ui:widget": "textarea"
},
"commandTpl": {
"ui:widget": "textarea"
}
}
},
"paths": {
"include": {
"ui:classNames": "non-orderable",
"ui:widget": "textarea",
"ui:options": {
"orderable": false
},
"items": {
"ui:widget": "textarea",
"ui:options": {
"label": false
}
}
},
"exclude": {
"ui:widget": "textarea",
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:widget": "textarea",
"ui:options": {
"label": false
}
Expand Down Expand Up @@ -146,21 +166,21 @@
"type": "array",
"items": {
"type": "string",
"title": "File path"
"title": "Label"
}
},
"exclude": {
"title": "Exclude",
"type": "array",
"items": {
"type": "string",
"title": "File path"
"title": "Label"
}
}
},
"notificationTemplate": {
"$ref": "#/definitions/notificationTemplate"
}
},
"notificationTemplate": {
"$ref": "#/definitions/notificationTemplate"
}
}
}
Expand Down Expand Up @@ -242,7 +262,22 @@
},
"style": {
"title": "Style",
"type": "string"
"type": "string",
"default": "",
"oneOf": [
{
"const": "",
"title": "Default"
},
{
"const": "primary",
"title": "Primary"
},
{
"const": "danger",
"title": "Danger"
}
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/source/github_events/render_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func renderActionButton(tpl ExtraButton, e any) (api.Button, error) {
return btns.ForURL(tpl.DisplayName, value, api.ButtonStyle(tpl.Style)), nil
}

value, err := RenderGoTpl(tpl.URL, e)
value, err := RenderGoTpl(tpl.CommandTpl, e)
if err != nil {
return api.Button{}, err
}
Expand Down

0 comments on commit 43f59aa

Please sign in to comment.