HttpError due to missing context info (`context.issue.number`)
See original GitHub issueDescribe 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: `[](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:
- Created 2 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
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.
And then use
pr
asissue_number
when callingcreateComment()
.If your workflow is triggering off of a
push
event, there won’t be an associated issue in the context. I’d recommend removing thatpush
trigger to get that example workflow working.