Skip to content

Commit da6f98d

Browse files
committed
Handle when workflow parsing fails
1 parent ae403bb commit da6f98d

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function run_repo(owner, repo, octokit) {
3232
continue;
3333
}
3434

35-
debug(`Checking branch ${branchName} for workflows.`);
35+
debug(`Checking branch https://github.com/${owner}/${repo}/blob/${branchName} for workflows.`);
3636
let contents;
3737
try {
3838
contents = await octokit.rest.repos.getContent({
@@ -43,7 +43,7 @@ async function run_repo(owner, repo, octokit) {
4343
});
4444
} catch (error) {
4545
if (error.status === 404) {
46-
debug(`Branch ${branchName} does not contain any workflows.`);
46+
debug(`https://github.com/${owner}/${repo}/blob/${branchName} does not contain any workflows.`);
4747
continue;
4848
}
4949
throw (`Error: ${error.status}. Failed to retrieve contents for branch ${branchName}`, error);
@@ -52,7 +52,7 @@ async function run_repo(owner, repo, octokit) {
5252
for (const file of contents.data) {
5353
const lowerCaseFile = file.name.toLowerCase();
5454
if (file.type === 'file' && (lowerCaseFile.endsWith('.yml') || lowerCaseFile.endsWith('.yaml'))) {
55-
debug(`Retrieving workflow file ${file.path}.`);
55+
debug(`Retrieving workflow file https://github.com/${owner}/${repo}/blob/${branchName}/${file.path}.`);
5656
const fileContent = await octokit.rest.repos.getContent({
5757
owner,
5858
repo,
@@ -63,26 +63,31 @@ async function run_repo(owner, repo, octokit) {
6363
const content = Buffer.from(fileContent.data.content, 'base64').toString('utf-8');
6464

6565
if (!content.includes('pull_request_target')) {
66-
debug(`No occurrence of 'pull_request_target' in ${file.path}.`);
66+
debug(`No occurrence of 'pull_request_target' in https://github.com/${owner}/${repo}/blob/${branchName}/${file.path}.`);
6767
continue;
6868
}
6969

70-
debug(`Parsing workflow file ${file.path}.`);
70+
debug(`Parsing workflow file https://github.com/${owner}/${repo}/blob/${branchName}/${file.path}.`);
7171
const result = parseWorkflow(
7272
{
7373
name: file.name,
7474
content: content
7575
},
7676
new NoOperationTraceWriter()
7777
);
78+
if (result.value === undefined) {
79+
found = true;
80+
console.log(`Failed to parse https://github.com/${owner}/${repo}/blob/${branchName}/${file.path}.`);
81+
continue;
82+
}
7883
const workflow = await convertWorkflowTemplate(result.context, result.value);
7984
if (workflow.events['pull_request_target'] === undefined) {
80-
debug(`No usage of 'pull_request_target' in ${file.path}.`);
85+
debug(`No usage of 'pull_request_target' in https://github.com/${owner}/${repo}/blob/${branchName}/${file.path}.`);
8186
continue;
8287
}
8388

8489
if (workflow.events['pull_request_target'].branches !== undefined) {
85-
debug(`${file.path} is using branch filter ${JSON.stringify(workflow.events['pull_request_target'].branches)}.`);
90+
debug(`https://github.com/${owner}/${repo}/blob/${branchName}/${file.path} is using branch filter ${JSON.stringify(workflow.events['pull_request_target'].branches)}.`);
8691
continue;
8792
}
8893

0 commit comments

Comments
 (0)