Add Global Carbon Budget to climate catalog #20
Workflow file for this run
This file contains hidden or 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
| --- | |
| name: Binder Link | |
| on: | |
| pull_request: | |
| types: [opened, reopened] | |
| workflow_dispatch: | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Comment on PR with Binder link | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const ref = '${{ github.head_ref || github.ref_name }}'; | |
| const REPO = '${{ github.repository }}'; | |
| const OWNER = REPO.split('/')[0]; | |
| const REPO_NAME = REPO.split('/')[1]; | |
| const BADGE = '[]'; | |
| const BASE_URL = 'https://mybinder.org/v2/gh'; | |
| const LINK = `${BADGE}(${BASE_URL}/${OWNER}/${REPO_NAME}/${ref}`; | |
| const PARAMS = '?urlpath=lab%2Ftree%2Fnotebooks%2Fdemo.ipynb)'; | |
| const BODY = `🚀 **Launch on Binder** | |
| ${LINK}${PARAMS} | |
| Note: First launch may take a few minutes while the image builds.`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: OWNER, | |
| repo: REPO_NAME, | |
| issue_number: context.issue.number | |
| }); | |
| const hasComment = comments.some(c => c.body.includes('Launch on Binder')); | |
| if (hasComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: OWNER, | |
| repo: REPO_NAME, | |
| comment_id: comments.find(c => c.body.includes('Launch on Binder')).id, | |
| body: BODY | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: OWNER, | |
| repo: REPO_NAME, | |
| issue_number: context.issue.number, | |
| body: BODY | |
| }); | |
| } |