Add actions-util.getAutomationID()

This commit is contained in:
David Verdeguer 2021-05-03 19:36:32 +02:00
parent c6e734ccc5
commit 519d0771c7
6 changed files with 102 additions and 2 deletions

View file

@ -425,6 +425,27 @@ export async function getAnalysisKey(): Promise<string> {
return analysisKey;
}
export async function getAutomationID(): Promise<string> {
let automationID = `${await getAnalysisKey()}/`;
const environment = getOptionalInput("matrix");
// the id has to be deterministic so we sort the fields
if (environment !== undefined && environment !== "null") {
const environmentObject = JSON.parse(environment);
for (const entry of Object.entries(environmentObject).sort()) {
if (typeof entry[1] === "string") {
automationID += `${entry[0]}:${entry[1]}/`;
} else {
// In code scanning we just handle the string values,
// the rest get converted to the empty string
automationID += `${entry[0]}:/`;
}
}
}
return automationID;
}
/**
* Get the ref currently being analyzed.
*/