From 60178eb51c5b908b871ab60d29a4dc6cdd52ee09 Mon Sep 17 00:00:00 2001 From: Riley Snyder Date: Mon, 9 Jan 2023 12:59:30 -0600 Subject: [PATCH 1/2] feat: expose actor argument --- cmd/main.go | 6 ++++++ plugin.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index 93b7be6..3a00475 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -81,6 +81,11 @@ func main() { Usage: "Webhook event payload", EnvVar: "PLUGIN_EVENT_PAYLOAD", }, + cli.StringFlag{ + Name: "actor", + Usage: "User that triggered the event", + EnvVar: "PLUGIN_ACTOR", + }, // daemon flags cli.StringFlag{ @@ -179,6 +184,7 @@ func run(c *cli.Context) error { Verbose: c.Bool("action-verbose"), Image: c.String("action-image"), EventPayload: c.String("event-payload"), + Actor: c.String("actor"), }, Daemon: daemon.Daemon{ Registry: c.String("docker.registry"), diff --git a/plugin.go b/plugin.go index f5f405f..b8c0d44 100644 --- a/plugin.go +++ b/plugin.go @@ -30,6 +30,7 @@ type ( Env map[string]string Image string EventPayload string // Webhook event payload + Actor string Verbose bool } @@ -63,6 +64,8 @@ func (p Plugin) Exec() error { secretFile, "--env-file", envFile, + "--actor", + p.Action.Actor, "-b", "--detect-event", } From b18291d15ada2cc232d29939f0f7c526e4750ea9 Mon Sep 17 00:00:00 2001 From: Riley Snyder Date: Tue, 10 Jan 2023 11:30:39 -0600 Subject: [PATCH 2/2] actor is conditional --- plugin.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin.go b/plugin.go index b8c0d44..69f3a0f 100644 --- a/plugin.go +++ b/plugin.go @@ -64,12 +64,16 @@ func (p Plugin) Exec() error { secretFile, "--env-file", envFile, - "--actor", - p.Action.Actor, "-b", "--detect-event", } + // optional arguments + if p.Action.Actor != "" { + cmdArgs = append(cmdArgs, "--actor") + cmdArgs = append(cmdArgs, p.Action.Actor) + } + if p.Action.EventPayload != "" { if err := ioutil.WriteFile(eventPayloadFile, []byte(p.Action.EventPayload), 0644); err != nil { return errors.Wrap(err, "failed to write event payload to file")