- Notifications
You must be signed in to change notification settings - Fork455
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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.jsconst{data:list_comments}=awaitgithub.rest.issues.listComments({issue_number:context.issue.number,owner:context.repo.owner,per_page:100,repo:context.repo.repo,});constget_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. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 1 reply
-
I shared an example scripthere that got@rdhar on the right path. The crux of the solution is that:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Thank you for sharing,@yhakbar! That script setup and // Beforereturn{body:get_comment.body,id:get_comment.id,};// Aftercore.setOutput("body",get_comment.body);core.setOutput("id",get_comment.id); Similarly, I had to amend references to the output result within the # BeforefromJSON(steps.comment.outputs.result)['body']fromJSON(steps.comment.outputs.result)['id']# Aftersteps.comment.outputs.bodysteps.comment.outputs.id |
BetaWas this translation helpful?Give feedback.