Skip to content

Commit

Permalink
Refactored pipeline message construction to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisjbell committed Dec 19, 2022
1 parent c7ce928 commit 24c9eae
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/Genesis/CI/Legacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ use Genesis;
use Genesis::Top;
use Genesis::UI;
use Socket qw/inet_ntoa/;
use JSON::PP qw/encode_json/;
use JSON::PP;

sub string_to_yaml {
# Note: the resulting string MUST be surrounded by double quotes
return substr(encode_json($_[0]), 1, -1);
if (ref($_[0])) {
return JSON::PP->new->encode($_[0]);
} else {
return substr(JSON::PP->new->allow_nonref->encode($_[0]), 1, -1);
}
}
sub boolean_to_yaml {
return $_[0] ? "true" : "false";
Expand All @@ -27,16 +31,17 @@ sub _gen_notifications {
my ($pipeline, $message, $alias) = @_;
$alias = "" unless defined $alias;
my $notification = "in_parallel: [\n";
my $pipeline_name = $pipeline->{pipeline}{name};
my $message_as_yaml = string_to_yaml($message);
if ($pipeline->{pipeline}{slack}) {
$notification .= <<EOF;
{
put: "slack",
params: {
channel: "(( grab pipeline.slack.channel ))",
username: "(( grab pipeline.slack.username ))",
icon_url: "(( grab pipeline.slack.icon ))",
text: "(( concat pipeline.name \": $message_as_yaml\" ))"
channel: (( grab pipeline.slack.channel )),
username: (( grab pipeline.slack.username )),
icon_url: (( grab pipeline.slack.icon )),
text: "$pipeline_name: $message_as_yaml"
}
},
EOF
Expand All @@ -46,10 +51,10 @@ EOF
{
put: "hipchat",
params: {
from: "(( grab pipeline.hipchat.username ))",
color: "gray",
message: "(( concat pipeline.name \": $message_as_yaml\" ))",
notify: "(( grab pipeline.hipchat.notify ))"
from: (( grab pipeline.hipchat.username )),
color: "gray",
message: "$pipeline_name: $message_as_yaml",
notify: (( grab pipeline.hipchat.notify ))
}
},
EOF
Expand All @@ -59,8 +64,8 @@ EOF
{
put: "stride",
params: {
conversation: "(( grab pipeline.stride.conversation ))",
message: "(( concat pipeline.name \": $message_as_yaml\" ))"
conversation: (( grab pipeline.stride.conversation )),
message: "$pipeline_name: $message_as_yaml"
}
},
EOF
Expand Down
60 changes: 60 additions & 0 deletions t/pipeline.t
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: a-testing-errand-for-the-ages
GENESIS_HONOR_ENV: 1
VAULT_ADDR: https://127.0.0.1:8200
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: false
platform: linux
run:
args:
Expand Down Expand Up @@ -1576,6 +1580,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: a-testing-errand-for-the-ages
GENESIS_HONOR_ENV: 1
VAULT_ADDR: https://127.0.0.1:8200
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: false
platform: linux
run:
args:
Expand Down Expand Up @@ -1699,6 +1707,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: a-testing-errand-for-the-ages
GENESIS_HONOR_ENV: 1
VAULT_ADDR: https://127.0.0.1:8200
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: false
platform: linux
run:
args:
Expand Down Expand Up @@ -2065,6 +2077,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -2331,6 +2347,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -2520,6 +2540,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -3235,6 +3259,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -3496,6 +3524,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -3682,6 +3714,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -4204,6 +4240,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -4467,6 +4507,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -4653,6 +4697,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -5176,6 +5224,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -5437,6 +5489,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down Expand Up @@ -5623,6 +5679,10 @@ jobs:
DEBUG: 1
ERRAND_NAME: run-something-good
GENESIS_HONOR_ENV: 1
VAULT_ADDR: http://myvault.myorg.com:5999
VAULT_ROLE_ID: this-is-a-role
VAULT_SECRET_ID: this-is-a-secret
VAULT_SKIP_VERIFY: true
platform: linux
run:
args:
Expand Down

0 comments on commit 24c9eae

Please sign in to comment.