Skip to content

Commit

Permalink
ENH - Replace binder on PR workflow (#65)
Browse files Browse the repository at this point in the history
* 👷 Update binder workflow

* 👷 Change PR target
  • Loading branch information
trallard authored Jul 13, 2023
1 parent 1efd781 commit 40f4e1f
Showing 1 changed file with 4 additions and 54 deletions.
58 changes: 4 additions & 54 deletions .github/workflows/binder-on-pr.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,15 @@
# References:
# This workflow adds a Binder preview URL to new PRs (via a comment on the PR).
# This comment will only be created once, and then it will be updated with
# every new commit
# - https://github.com/jupyterlab/jupyterlab-git/blob/master/.github/workflows/binder-on-pr.yaml
# - https://mybinder.readthedocs.io/en/latest/howto/gh-actions-badges.html
name: Add binder link to PR
on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
pull-requests: write

jobs:
binder:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: comment on PR with Binder link
uses: actions/github-script@v3
- uses: jupyterlab/maintainer-tools/.github/actions/binder-link@v1
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var PR_HEAD_USERREPO = process.env.PR_HEAD_USERREPO;
var PR_HEAD_REF = process.env.PR_HEAD_REF;
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
var autogenerated_id = '';
for( var i = 0; i < comments.data.length; i++ ){
var act_comment = comments.data[ i ];
if( act_comment.body.includes( "https://mybinder.org/" ) ){
autogenerated_id = act_comment.id;
}
}
var date = new Date( Date.now() );
if( autogenerated_id === '' ){
github.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/${PR_HEAD_USERREPO}/${PR_HEAD_REF}?urlpath=lab) :point_left: Launch a binder notebook on branch [${PR_HEAD_USERREPO}/${PR_HEAD_REF}]${PR_HEAD_USERREPO}/${PR_HEAD_REF})`
})
}
else {
github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: autogenerated_id,
body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${PR_HEAD_USERREPO}/${PR_HEAD_REF}?urlpath=lab) :point_left: Launch a binder notebook on branch [${PR_HEAD_USERREPO}/${PR_HEAD_REF}](${PR_HEAD_USERREPO}/${PR_HEAD_REF}) \n<sub>Comment updated on ${date.toISOString()}</sub>`,
});
}
env:
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_HEAD_USERREPO: ${{ github.event.pull_request.head.repo.full_name }}
github_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 40f4e1f

Please sign in to comment.