From cba73db0b80f8fb5e40e3f09db8d82416035537d Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 2 Sep 2025 11:54:04 +0100 Subject: [PATCH 1/4] Create test.yml --- .github/workflows/test.yml | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..a1bc804b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,69 @@ +#./.github/workflows/binder-badge.yaml +name: Binder Badge +on: + pull_request_target: + types: [opened] + +jobs: + binder: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: comment on PR with Binder link + uses: actions/github-script@v6 + 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; + github.rest.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}) :point_left: Launch a binder notebook on branch _${PR_HEAD_USERREPO}/${PR_HEAD_REF}_` + }) + env: + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + PR_HEAD_USERREPO: ${{ github.event.pull_request.head.repo.full_name }} + +Example 2: Comment with a Binder badge in response to a comment + +In the below example, we will trigger GitHub Actions to run after someone comments on a pull request with the command /binder, which will trigger Actions to comment on a PR in the same way as Example 1. + +Download the below file: chatops-binder.yaml + +#./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@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + // Get the branch name + github.rest.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.rest.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` + }) + }) From ed7294f6ac178ec62d3ec068081fb3c014d900ba Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 2 Sep 2025 11:55:01 +0100 Subject: [PATCH 2/4] Update test.yml --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1bc804b..ba639777 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,3 @@ -#./.github/workflows/binder-badge.yaml name: Binder Badge on: pull_request_target: From 0d41367e3a2e74686ba3e1d0ab17e3f2a4714c65 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 2 Sep 2025 11:55:51 +0100 Subject: [PATCH 3/4] Update test.yml --- .github/workflows/test.yml | 41 -------------------------------------- 1 file changed, 41 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba639777..0d5f776c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,44 +25,3 @@ jobs: env: PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} PR_HEAD_USERREPO: ${{ github.event.pull_request.head.repo.full_name }} - -Example 2: Comment with a Binder badge in response to a comment - -In the below example, we will trigger GitHub Actions to run after someone comments on a pull request with the command /binder, which will trigger Actions to comment on a PR in the same way as Example 1. - -Download the below file: chatops-binder.yaml - -#./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@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - // Get the branch name - github.rest.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.rest.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` - }) - }) From 871423f6febfc0af5e91f980a08d7fc86c0d93fd Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 2 Sep 2025 11:56:41 +0100 Subject: [PATCH 4/4] Update test.yml --- .github/workflows/test.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d5f776c..86a5da3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,12 @@ name: Binder Badge on: - pull_request_target: - types: [opened] + workflow_dispatch: + pull_request: + branches: + - main + push: + branches: + - main jobs: binder: