Skip to content

Commit 6f8486b

Browse files
authored
Merge pull request #305 from cloudposse/fix/action/safer-description-handling
fix: summary file crashes
2 parents 9f21bc2 + 597d23d commit 6f8486b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/action.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ const createIssues = async (octokit, context, maxOpenedIssues, labels, users, co
258258
for (let i = 0; i < numOfIssuesToCreate; i++) {
259259
const slug = componentsCandidatesToCreateIssue[i];
260260
const issueTitle = erroredComponents.includes(slug) ? `Failure Detected in \`${slug}\`` : `Drift Detected in \`${slug}\``;
261-
const file_name = slug.replace("/", "_")
261+
const file_name = slug.replace(/\//g, "_")
262+
if (!fs.existsSync(`issue-description-${file_name}.md`)) {
263+
core.error(`Failed to create issue for component ${slug} because file "issue-description-${file_name}.md" does not exist`);
264+
continue;
265+
}
262266
const issueDescription = fs.readFileSync(`issue-description-${file_name}.md`, 'utf8');
263267

264268
const label = erroredComponents.includes(slug) ? "error" : "drift"
@@ -299,7 +303,7 @@ const updateIssues = async (octokit, context, componentsToIssues, componentsToUp
299303

300304
for (let i = 0; i < componentsToUpdateExistingIssue.length; i++) {
301305
const slug = componentsToUpdateExistingIssue[i];
302-
const file_name = slug.replace("/", "_")
306+
const file_name = slug.replace(/\//g, "_")
303307
const issueDescription = fs.readFileSync(`issue-description-${file_name}.md`, 'utf8');
304308
const issueNumber = componentsToIssues[slug].number;
305309

@@ -390,7 +394,7 @@ const postStepSummaries = async (driftingComponents, erroredComponents) => {
390394
const components = driftingComponents.concat(erroredComponents)
391395
for (let i = 0; i < components.length; i++) {
392396
const slug = components[i];
393-
const file_name = slug.replace("/", "_")
397+
const file_name = slug.replace(/\//g, "_")
394398
const file = `step-summary-${file_name}.md`;
395399
const content = fs.readFileSync(file, 'utf-8');
396400

0 commit comments

Comments
 (0)