diff options
author | Daniel Baumann <daniel@debian.org> | 2025-01-24 09:00:09 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2025-01-24 09:00:09 +0100 |
commit | 4bf4dabd48aa70da3699b9a023f22689645d24f4 (patch) | |
tree | ed8175444649e71c0ed0e5f1d30101786ca2473e /pkg/common/dryrun.go | |
parent | Initial commit. (diff) | |
download | forgejo-act-debian.tar.xz forgejo-act-debian.zip |
Adding upstream version 1.24.0.HEADupstream/1.24.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'pkg/common/dryrun.go')
-rw-r--r-- | pkg/common/dryrun.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/common/dryrun.go b/pkg/common/dryrun.go new file mode 100644 index 0000000..2d5a14e --- /dev/null +++ b/pkg/common/dryrun.go @@ -0,0 +1,25 @@ +package common + +import ( + "context" +) + +type dryrunContextKey string + +const dryrunContextKeyVal = dryrunContextKey("dryrun") + +// Dryrun returns true if the current context is dryrun +func Dryrun(ctx context.Context) bool { + val := ctx.Value(dryrunContextKeyVal) + if val != nil { + if dryrun, ok := val.(bool); ok { + return dryrun + } + } + return false +} + +// WithDryrun adds a value to the context for dryrun +func WithDryrun(ctx context.Context, dryrun bool) context.Context { + return context.WithValue(ctx, dryrunContextKeyVal, dryrun) +} |