Skip to content

Commit

Permalink
fix(endpoint/gitlab): hack up the scope/data helper to avoid dict/map…
Browse files Browse the repository at this point in the history
… issues, fix pipeline hook message
  • Loading branch information
ssube committed Jun 2, 2019
1 parent 5830ea6 commit b9a9fa5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions docs/controller/gitlab/endpoint/push-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ data:
templates:
body: >-
{{#withMap cmd.data pipeline="object_attributes" user="user" }}
Pipeline {{ pipeline.id }} on {{ pipeline.ref }} by {{ user.username }} has finished: {{ pipeline.status }}
after {{ pipeline.duration }} seconds.
{{ json this }}
Pipeline {{ this.pipeline.[0].id }} on {{ this.pipeline.[0].ref }} by {{ this.user.[0].username }} has
finished: {{ this.pipeline.[0].status }} after {{ this.pipeline.[0].duration }} seconds.
{{/withMap}}
- metadata:
Expand Down
10 changes: 9 additions & 1 deletion src/transform/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export async function applyTransforms(
return result;
}

/**
* Convert a template scope (before or after rendering) into suitable data for
* a Command or Message.
*
* This helper exists to mask some Dict/Map inconsistencies that should be
* resolved elsewhere.
*/
export function scopeToData(scope: TemplateScope): MapLike<Array<string>> {
const data = new Map();
for (const [key, value] of Object.entries(scope)) {
Expand All @@ -34,7 +41,8 @@ export function scopeToData(scope: TemplateScope): MapLike<Array<string>> {
} else if (Array.isArray(value)) {
setOrPush(data, key, value);
} else {
setOrPush(data, key, JSON.stringify(value));
// TODO: handle nested objects
setOrPush(data, key, value);
}
}
return mapToDict(data);
Expand Down

0 comments on commit b9a9fa5

Please sign in to comment.