Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH - Replace binder on PR workflow #65

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
Loading