-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH - Replace binder on PR workflow (#65)
* 👷 Update binder workflow * 👷 Change PR target
- Loading branch information
Showing
1 changed file
with
4 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |