Skip to content

Commit

Permalink
prefix for annotations (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero authored Jun 8, 2022
1 parent 06a06b1 commit 507f2d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/utilities/workflowAnnotationUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
12 changes: 11 additions & 1 deletion src/utilities/workflowAnnotationUtils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 507f2d4

Please sign in to comment.