-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename event to rule * rename event to rule * Test * Trst * Test * Test * Test * Test * Rename trigger * Refactor ctx * refactor config * Rename processing templazes * simplified * new structure * refactored * implmented github comment * compiling * fix compile errors * fix api * added event logging * refactored plugins * fix actions * added debug * fix github hook * update github action * implemented github comments
- Loading branch information
Showing
36 changed files
with
513 additions
and
998 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This configuration file was automatically generated by Gitpod. | ||
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) | ||
# and commit this file to your remote git repository to share the goodness with others. | ||
|
||
tasks: | ||
- init: go get && go build ./... && go test ./... && make | ||
command: go run | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
rules: | ||
- if: | ||
trigger: github_comment | ||
when: | ||
contains: /cat | ||
then: | ||
action: github_comment | ||
with: | ||
comment: Grumpy cat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package info | ||
|
||
//overwritten by CI | ||
var Version = "0.1" | ||
var Commit = "undefined" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package config | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
pkg/piper/config/template_test.go → pkg/common/util/template_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package config | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cheld/miniprow/pkg/common/util" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type Configuration struct { | ||
Rules []Rule | ||
} | ||
|
||
type Rule struct { | ||
If Trigger | ||
Then Action | ||
} | ||
|
||
type Trigger struct { | ||
Trigger string | ||
When map[string]string | ||
} | ||
|
||
type Action struct { | ||
Action string | ||
With map[string]interface{} | ||
} | ||
|
||
func (config *Configuration) Filter(event *Event) []Rule { | ||
matchingRules := []Rule{} | ||
for _, rule := range config.Rules { | ||
if rule.If.Trigger == event.Type { | ||
resolved, err := util.ProcessAllTemplates(rule, event) | ||
if err != nil { | ||
event.Err("Template for rule %v cannot be processed: %v", rule.If.Trigger, err) | ||
return matchingRules | ||
} | ||
matchingRules = append(matchingRules, resolved.(Rule)) | ||
event.Log("Rule configuration %v found", rule.If.Trigger) | ||
} | ||
} | ||
if len(matchingRules) == 0 { | ||
event.Log("No matching rule found") | ||
} | ||
return matchingRules | ||
} | ||
|
||
func Load(cfg *[]byte) (Configuration, error) { | ||
var yamlConfig Configuration | ||
err := yaml.Unmarshal(*cfg, &yamlConfig) | ||
if err != nil { | ||
return Configuration{}, fmt.Errorf("Error parsing YAML file: %s", err) | ||
} | ||
return yamlConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package model | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type Event struct { | ||
Type string | ||
Data interface{} | ||
status status | ||
} | ||
|
||
type status struct { | ||
logs []string | ||
err string | ||
} | ||
|
||
func (event *Event) Err(message string, params ...interface{}) { | ||
txt := fmt.Sprintf("ERROR: "+message, params...) | ||
event.status.err = txt | ||
event.status.logs = append(event.status.logs, txt) | ||
} | ||
|
||
func (event *Event) Log(message string, params ...interface{}) { | ||
txt := fmt.Sprintf(message, params...) | ||
event.status.logs = append(event.status.logs, txt) | ||
} | ||
|
||
func (event *Event) Trail() string { | ||
s, _ := json.MarshalIndent(event.status.logs, "", "\t") | ||
return string(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package model | ||
|
||
|
||
type Tenant struct { | ||
Config Configuration | ||
Environ map[string]string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pluginimports | ||
|
||
// We need to empty import all enabled plugins so that they will be linked into | ||
// any hook binary. | ||
import ( | ||
|
||
// triggers | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/triggers/github" // Import all enabled plugins. | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/triggers/http" | ||
|
||
// actions | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/actions/debug" | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/actions/github" | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/actions/http" | ||
_ "github.com/cheld/miniprow/pkg/hook/plugins/actions/misc" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package actions | ||
|
||
import config "github.com/cheld/miniprow/pkg/hook/model" | ||
|
||
var ( | ||
handlers = map[string]ActionHandler{} | ||
) | ||
|
||
// TriggerHandler defines the function contract for all triggers. | ||
type ActionHandler func(map[string]interface{}, *config.Event) | ||
|
||
func RegisterHandler(name string, fn ActionHandler) { | ||
handlers[name] = fn | ||
} | ||
|
||
func GetHandler(name string) ActionHandler { | ||
return handlers[name] | ||
} | ||
|
||
func Handle(triggeredRules []config.Rule, event *config.Event, tenant config.Tenant) { | ||
for _, rule := range triggeredRules { | ||
actionName := rule.Then.Action | ||
event.Log("Action is %v", actionName) | ||
handler := handlers[actionName] | ||
if handler == nil { | ||
event.Log("No action handler implementation for %v", rule.Then.Action) | ||
return | ||
} | ||
handler(rule.Then.With, event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package debug | ||
|
||
import ( | ||
"github.com/cheld/miniprow/pkg/hook/model" | ||
"github.com/cheld/miniprow/pkg/hook/plugins/actions" | ||
) | ||
|
||
const ( | ||
HANDLER_ID = "debug" | ||
) | ||
|
||
func init() { | ||
actions.RegisterHandler(HANDLER_ID, handleAction) | ||
} | ||
|
||
func handleAction(params map[string]interface{}, event *model.Event) { | ||
event.Log("Debug action executed") | ||
} |
Oops, something went wrong.