Skip to content

Unable to use v6, to create comment on issue #273

Closed

Description

@lakshmajee

Describe the bug

  • When a request is made to create a comment, the step throw below error
Unhandled error: HttpError: Not Found
  • Another problem is the library adds an additional slash before the resource
      // should not have extras slash before `comments`
      https://api.github.com/repos/awkward-minion/gh_actions_poc/issues//comments

To Reproduce

  1. Create a workflow file
  2. use github-script@v6 action
  3. Add some code to create a comment

Notes: Not provided any inputs apart from the script (assuming GitHub-script uses default token).

Expected behavior

  • Should be able to create a comment using this action
  • Should not add the extras slash in the request URL

Screenshots
https://github.com/awkward-minion/gh_actions_poc/runs/7257014713?check_suite_focus=true
image

Desktop (please complete the following information):

  • OS: [e.g. iOS] Ubuntu 20.24
  • Browser [e.g. chrome, safari]: Chrome
  • Version [e.g. 22]: 95.0.4638.69 (Official Build) (64-bit)

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.
Repository available here
PS: I have added some random messages in the commit, please ignore them

Activity

  1. Tom-Whi commented on Jul 12, 2022

    @Tom-Whi

    I've noticed the same issue with the double slashes.

    image

  2. lakshmajee commented on Jul 13, 2022

    @lakshmajee
    Author

    I've noticed the same issue with the double slashes.

    @Tom-Whi Yes, I know and added this in Expected behavior section in the original issue ☝️. And this URL is being manipulated by GitHub-scripts, that's why I raised this issue.

  3. Tom-Whi commented on Jul 13, 2022

    @Tom-Whi

    Yep. I was agreeing with you.

    I also have the same issue using @v5, which produces the same results.

  4. lakshmajee commented on Jul 13, 2022

    @lakshmajee
    Author

    @Tom-Whi did you find any solution or trick to solve this kind of error!

  5. Tom-Whi commented on Jul 13, 2022

    @Tom-Whi

    Sadly not yet. I'm still trying find a workaround. If I find something I'll post back to this issue.

  6. lakshmajee commented on Jul 13, 2022

    @lakshmajee
    Author

    I configured the wrong workflow event.

  7. lakshmajee commented on Jul 13, 2022

    @lakshmajee
    Author

    I configured the wrong workflow event.

  8. Tomasz-Kluczkowski commented on Jul 14, 2022

    @Tomasz-Kluczkowski

    Ok so this action is basically broken for now?
    To me it looks like it does not insert issue number when trying to create a comment?

    request: {
        method: 'POST',
        url: 'https://api.github.com/repos/flexciton/azure_infrastructure_costs/issues//comments',
        headers: {
          accept: 'application/vnd.github.-preview+json',
          'user-agent': 'actions/github-script octokit-core.js/3.5.1 Node.js/16.13.0 (linux; x64)',
          authorization: 'token [REDACTED]',
          'content-type': 'application/json; charset=utf-8'
        },
    

    url: 'https://api.github.com/repos/flexciton/azure_infrastructure_costs/issues/ <HERE SHOULD BE ISSUE NUMBER?> /comments',

  9. lakshmajee commented on Jul 15, 2022

    @lakshmajee
    Author

    Ok so this action is basically broken for now? To me it looks like it does not insert issue number when trying to create a comment?

    request: {
        method: 'POST',
        url: 'https://api.github.com/repos/flexciton/azure_infrastructure_costs/issues//comments',
        headers: {
          accept: 'application/vnd.github.-preview+json',
          'user-agent': 'actions/github-script octokit-core.js/3.5.1 Node.js/16.13.0 (linux; x64)',
          authorization: 'token [REDACTED]',
          'content-type': 'application/json; charset=utf-8'
        },
    

    url: 'https://api.github.com/repos/flexciton/azure_infrastructure_costs/issues/ <HERE SHOULD BE ISSUE NUMBER?> /comments',

    Yes exactly, because it won't be available on regular push events on the actions.
    For now I am using pull_request event to deal with this (it automatically pick the issue from PR)

  10. Tomasz-Kluczkowski commented on Jul 15, 2022

    @Tomasz-Kluczkowski
  11. lakshmajee commented on Jul 22, 2022

    @lakshmajee
    Author

    Working as expected with correct event (pull_request), which grabs issue number from Pull request

  12. infa-msheik commented on Sep 25, 2022

    @infa-msheik

    Hi @Tomasz-Kluczkowski

    Can you please let me know the query you used to get the pull request number on Push events ?

    I have found a workaround though by getting the pull request number using another query.

  13. Tomasz-Kluczkowski commented on Sep 25, 2022

    @Tomasz-Kluczkowski

    Hi @Tomasz-Kluczkowski

    Can you please let me know the query you used to get the pull request number on Push events ?

    I have found a workaround though by getting the pull request number using another query.

    Hi,

    I paste my workaround code below, hope it helps you or anyone else.

    We use it in our pipeline and all is fine.

    I am sending this from a mobile so formatting will probably be awkward ;).

    If I get a chance I will reformat this on a laptop maybe tomorrow.

    Also I have this code in a separate script to avoid polluting the main github workflow file with javascript code.

    module.exports = async (github, context) => {
        // Get pull requests that are open for current ref.
        const pullRequests = await github.rest.pulls.list({
            owner: context.repo.owner,
            repo: context.repo.repo,
            state: 'open',
            head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`
        })
    
        // Set issue number for following calls from context (if on pull request event) or from above variable.
        const issueNumber = context.issue.number || pullRequests.data[0].number
    
        // Retrieve existing bot comments for the PR
        const {data: comments} = await github.rest.issues.listComments({
            owner: context.repo.owner,
            repo: context.repo.repo,
            issue_number: issueNumber,
        })
        const botComment = comments.find(comment => {
            return comment.user.type === 'Bot' && comment.body.includes('Terraform Plan')
        })
    
        // Prepare format of the comment - it has to be de-indented to make markdown work properly.
        const output = `
    #### Terraform Plan 📖 \`${process.env.TERRAFORM_PLAN_STEP_OUTCOME}\`
    
    <hr>
    
    *Pusher: @${context.actor}*
    *Action: \`${context.eventName}\`*
    *Workflow: \`${context.workflow}\`*
    *Commit: \`${context.sha}\`*
    
    <details><summary>Show Plan</summary>
    
    \`\`\`\n
    ${process.env.TERRAFORM_PLAN}
    \`\`\`
    
    </details>`;
    
        // If we have a comment, update it, otherwise create a new one
        if (botComment) {
            github.rest.issues.updateComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                comment_id: botComment.id,
                body: output
            })
        } else {
            github.rest.issues.createComment({
                issue_number: issueNumber,
                owner: context.repo.owner,
                repo: context.repo.repo,
                body: output
            })
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions