From 507f2d4fc713cdc92f96880e350464687ce2e960 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Wed, 8 Jun 2022 11:39:09 -0400 Subject: [PATCH] prefix for annotations (#191) --- src/utilities/workflowAnnotationUtils.test.ts | 18 ++++++++++++++++++ src/utilities/workflowAnnotationUtils.ts | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/utilities/workflowAnnotationUtils.test.ts diff --git a/src/utilities/workflowAnnotationUtils.test.ts b/src/utilities/workflowAnnotationUtils.test.ts new file mode 100644 index 000000000..0a467686e --- /dev/null +++ b/src/utilities/workflowAnnotationUtils.test.ts @@ -0,0 +1,18 @@ +import { prefixObjectKeys } from "../utilities/workflowAnnotationUtils"; + +describe("WorkflowAnnotationUtils", () => { + describe("prefixObjectKeys", () => { + it("should prefix an object with a given prefix", () => { + const obj = { + foo: "bar", + baz: "qux", + }; + const prefix = "prefix."; + const expected = { + "prefix.foo": "bar", + "prefix.baz": "qux", + }; + expect(prefixObjectKeys(obj, prefix)).toEqual(expected); + }); + }); +}); \ No newline at end of file diff --git a/src/utilities/workflowAnnotationUtils.ts b/src/utilities/workflowAnnotationUtils.ts index b99f4a99f..5e95fdb41 100644 --- a/src/utilities/workflowAnnotationUtils.ts +++ b/src/utilities/workflowAnnotationUtils.ts @@ -1,5 +1,14 @@ import { DeploymentConfig } from "../types/deploymentConfig"; +const ANNOTATION_PREFIX = "actions.github.com/"; + +export function prefixObjectKeys(obj: any, prefix: string): any { + return Object.keys(obj).reduce((newObj, key) => { + newObj[prefix + key] = obj[key]; + return newObj; + }, {}); +} + export function getWorkflowAnnotations( lastSuccessRunSha: string, workflowFilePath: string, @@ -22,7 +31,8 @@ export function getWorkflowAnnotations( helmChartPaths: deploymentConfig.helmChartFilePaths, provider: "GitHub", }; - return JSON.stringify(annotationObject); + const prefixedAnnotationObject = prefixObjectKeys(annotationObject, ANNOTATION_PREFIX); + return JSON.stringify(prefixedAnnotationObject); } export function getWorkflowAnnotationKeyLabel(