question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpError due to missing context info (`context.issue.number`)

See original GitHub issue

Describe the bug I’m trying to replicate Binder’s Example 1 to automatically add a Binder link to my repo when a PR is created. I’m getting an HttpError:

    at /home/runner/work/_actions/actions/github-script/v5/dist/index.js:4614:21
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  name: 'HttpError',
  status: 404,
  response: {
    url: 'https://api.github.com/repos/icesat2py/icepyx/issues//comments',
    status: 404,
...

I’m guessing this is tied to the “//” in the url, which I’m hypothesizing means that context.issue.number isn’t being filled in properly (because it doesn’t show up if I view console.log(context)).

To Reproduce Steps to reproduce the behavior:

name: AddBinderBadge
on:
  push:
  pull_request_target:
    types: [opened]

jobs:
  add-badge:
    runs-on: ubuntu-latest
    steps:
    - name: Comment on PR with Binder link
      uses: actions/github-script@v5
      with:
        github-token: ${{secrets.GITHUB_TOKEN}}
        script: |
          console.log(context)
          var BRANCH_NAME = process.env.GITHUB_REF.replace("refs/heads", "");
          var CONTENT_REPO = process.env.CONTENT_REPO;
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${CONTENT_REPO}/${BRANCH_NAME}?labpath=examples) :point_left: Launch a binder notebook on this branch`
          })
      # NOTE: Setting the vars as env vars is required to make them available within the Comment on PR step
      env:
        GITHUB_REF: ${{ github.ref }}
        CONTENT_REPO: ${{ github.repository }}

Expected behavior I expected to be able to automate adding a PR comment with the binder badge to my repo.

Screenshots Here’s the log from running the action.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser Firefox
  • Version [e.g. 22]

Additional context Despite several working examples, I’ve had no end of issues getting this up and running in my repo. One primary challenge was in getting the branch name for the PR, during debugging of which I determined that the github context was not being populated as I expected for a PR (see this GitHub community post).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
quulahcommented, Feb 2, 2022

I ended up here when trying to find a PR number in a case where the workflow was triggered by other means.

I came up with this, hopefully it’ll help others even if it doesn’t directly answer to the problem in this issue.

const issues = await github.rest.pulls.list({
  owner: context.repo.owner,
  repo: context.repo.repo,
  state: 'open',
  head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`
})

const pr = context.issue.number || issues.data[0].number

And then use pr as issue_number when calling createComment().

0reactions
joshmgrosscommented, Feb 9, 2022
name: AddBinderBadge
on:
  push:
  pull_request_target:
    types: [opened]

If your workflow is triggering off of a push event, there won’t be an associated issue in the context. I’d recommend removing that push trigger to get that example workflow working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Github Action running "terraform plan" failing with a 404
Try putting await in front of the function call in your action. await github.rest.issues.createComment({ issue_number: context.issue.number, ...
Read more >
HTTP error 401.1 with pre-authentication headers - Internet ...
An unexpected 401.1 status is returned when you use Pre-Authentication headers with Internet Explorer and Internet Information Services ...
Read more >
Resolve errors | Google Drive
This error appears when the application's owner has set a quota limit to cap usage of a particular resource. To fix this error,...
Read more >
Troubleshoot Cloud Run issues
HTTP 429: No available container instances ... The following error occurs during serving: HTTP 429 The request was aborted because there was no...
Read more >
octokit/rest.js
By default, octokit.log.debug() and octokit.log.info() are no-ops, while the ... The level of permission to grant the access token for issues and related...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found