Skip to content

Commit d179782

Browse files
authored
Create chatops-binder.yaml
1 parent 96c9d3c commit d179782

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/chatops-binder.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Reference https://mybinder.readthedocs.io/en/latest/howto/gh-actions-badges.html
2+
name: Chatops Binder
3+
on: [issue_comment] # issues and PRs are equivalent in terms of comments for the GitHub API
4+
5+
jobs:
6+
trigger-chatops:
7+
# Make sure the comment is on a PR, and contains the command "/binder"
8+
if: (github.event.issue.pull_request != null) && contains(github.event.comment.body, '/binder')
9+
runs-on: ubuntu-latest
10+
steps:
11+
# Use the GitHub API to:
12+
# (1) Get the branch name of the PR that has been commented on with "/binder"
13+
# (2) make a comment on the PR with the binder badge
14+
- name: comment on PR with Binder link
15+
uses: actions/github-script@v1
16+
with:
17+
github-token: ${{secrets.GITHUB_TOKEN}}
18+
script: |
19+
// Get the branch name
20+
github.pulls.get({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
pull_number: context.payload.issue.number
24+
}).then( (pr) => {
25+
26+
// use the branch name to make a comment on the PR with a Binder badge
27+
var BRANCH_NAME = pr.data.head.ref
28+
github.issues.createComment({
29+
issue_number: context.payload.issue.number,
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${context.repo.owner}/${context.repo.repo}/${BRANCH_NAME}?urlpath=lab/tree/examples/demo.ipynb) :point_left: Launch a binder JupyterLab on this branch`
33+
})
34+
})

0 commit comments

Comments
 (0)