From bc1c01c588d964f0174cd80abcb16649ea8e94e1 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Sat, 22 Aug 2026 19:20:30 -0600 Subject: [PATCH] Add Diff Tour PR link workflow Amp-Thread-ID: https://ampcode.com/threads/T-01a02c32-1832-737a-9677-4bddf58d68a9 Co-authored-by: Amp --- .github/workflows/difftour-link.yml | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/difftour-link.yml diff --git a/.github/workflows/difftour-link.yml b/.github/workflows/difftour-link.yml new file mode 100644 index 0000000..b16ab76 --- /dev/null +++ b/.github/workflows/difftour-link.yml @@ -0,0 +1,53 @@ +name: Diff Tour link + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + pull-requests: write # needed to create/update comments + +jobs: + post-link: + runs-on: ubuntu-latest + # DiffTour resolves branch names against this repository, so the head + # branch must live on this repo (skip fork PRs). + if: github.event.pull_request.head.repo.full_name == github.repository + steps: + - uses: actions/github-script@v7 + with: + script: | + const instance = 'https://sourcegraph.sourcegraph.com'; + const repo = `github.com/${context.payload.repository.full_name}`; + const base = context.payload.pull_request.base.ref; + const head = context.payload.pull_request.head.ref; + + const range = `${encodeURIComponent(base)}...${encodeURIComponent(head)}`; + const url = `${instance}/r/${repo}/-/compare/${range}?mode=Tour`; + + const marker = ''; + const body = `${marker}\n[Open the Diff Tour for this PR in Sourcegraph](${url})`; + + // Find an existing comment we posted before (sticky comment). + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + }); + const existing = comments.find(c => c.body.includes(marker)); + + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body, + }); + }