Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provide a more clear await example in the README #115

Closed
@JPrendy

Description

@JPrendy

Is your feature request related to a problem? Please describe.
Apologies, If I am doing this incorrectly. I would like to use your https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml example in a separate file instead of an inline script.

Describe the solution you'd like
So, I originally looked at your solution in https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml, but noticed it was all done in an inline script, I think it would be helpful if you provided a more extensive example in the README as it took me a few trys to get it working in a separate file.

Describe alternatives you've considered

Additional context
So, if you could provide something like the following in the README, I think it would be helpful for other people as the example in https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml is quite good and uses await.

on: push


jobs:
  echo-input:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/github-script@v3
        with:
          script: |
            const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
            await script({github, context})

and then in that js file have

module.exports = async ({ github, context }) => {
  // Get the existing comments.
  const { data: comments } = await github.issues.listComments({
    owner: context.repo.owner,
    repo: context.repo.repo,
    issue_number: context.payload.number,
  })
  
  // Find any comment already made by the bot.
  const botComment = await comments.find(comment => comment.user.id === 41898282)
  const commentBody = "Hello from actions/github-script! (${{ github.sha }})"

  if (botComment) {
    return await github.issues.updateComment({
      owner: context.repo.owner,
      repo: context.repo.repo,
      comment_id: botComment.id,
      body: commentBody
    })
  } else {
    return await github.issues.createComment({
      owner: context.repo.owner,
      repo: context.repo.repo,
      issue_number: context.payload.number,
      body: commentBody
    })
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions