-
Hi, I would like to strip out snippets of JS code into separate files outside of YAML for ease of legibility. However, I'm struggling to understand how best to achieve something this. Before/Currentscript: |
const { data: list_comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
per_page: 100,
repo: context.repo.repo,
});
const get_comment = list_comments
.sort((a, b) => b.id - a.id)
.find((comment) => /^keyword/.test(comment.body));
return {
body: get_comment.body,
id: get_comment.id,
}; After/Proposedscript: |
require(process.env.GITHUB_ACTION_PATH + '/comment.js'); // File: comment.js
const { data: list_comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
per_page: 100,
repo: context.repo.repo,
});
const get_comment = list_comments
.sort((a, b) => b.id - a.id)
.find((comment) => /^keyword/.test(comment.body));
return {
body: get_comment.body,
id: get_comment.id,
}; With this, I get: "SyntaxError: await is only valid in async functions and the top level bodies of modules." I'm sure I'm missing something obvious with Really appreciate any thoughts/inputs, thanks for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I shared an example script here that got @rdhar on the right path. The crux of the solution is that:
|
Beta Was this translation helpful? Give feedback.
I shared an example script here that got @rdhar on the right path.
The crux of the solution is that:
require
ed in the script step that needs re-usable code as an exported function.await
ed in the calling script step.