Skip to content

Commit

Permalink
Create chatops-binder.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Dec 13, 2021
1 parent 05ce070 commit 87f3974
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/chatops-binder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#./github/workflows/chatops-binder.yaml
name: Chatops Binder
on: [issue_comment] # issues and PRs are equivalent in terms of comments for the GitHub API

jobs:
trigger-chatops:
# Make sure the comment is on a PR, and contains the command "/binder"
if: (github.event.issue.pull_request != null) && contains(github.event.comment.body, '/binder')
runs-on: ubuntu-latest
steps:
# Use the GitHub API to:
# (1) Get the branch name of the PR that has been commented on with "/binder"
# (2) make a comment on the PR with the binder badge
- name: comment on PR with Binder link
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get the branch name
github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number
}).then( (pr) => {
// use the branch name to make a comment on the PR with a Binder badge
var BRANCH_NAME = pr.data.head.ref
github.issues.createComment({
issue_number: context.payload.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${context.repo.owner}/${context.repo.repo}/${BRANCH_NAME}) :point_left: Launch a binder notebook on this branch`
})
})

0 comments on commit 87f3974

Please sign in to comment.