Is there a way for me to add a label to a PR befor...
# how-do-i
j
Is there a way for me to add a label to a PR before graphite closes it when it gets past the merge queue? I'm trying to put
externally-merged
on the PR. We would really appreciate this being possible so we can take advantage of linear status automations and more importantly their releases feature. If it isn't something that graphite currently supports, is there any kind of github action or other automation we can set up to make this work ourselves?
c
Hey Jack! Unfortunately there isn't a Graphite Automation event that can do this today. Graphite Automations can add labels but aren't tied to the merge-queue lifecycle, so there's no built-in way to add
externally-merged
right as the queue closes a PR. To do it before close, you'd have to watch an earlier queue signal like a GitHub Action triggered by Graphite's "Merge activity" comment when the PR is enqueued then label it (removing it if the merge doesn't go through). Since that's a Linear trigger (*https://linear.app/docs/github#custom-merge-queues*), it'll mark the issue Done. Thanks!
b
someone shared this GitHub Action on this slack, it seems to have fallen out of retention so I can't properly attribute the creator. Here's the copy we're running:
Copy code
name: Linear - mark externally-merged when queued in Graphite

on:
  issue_comment:
    types: [created]

permissions: {}

jobs:
  label-externally-merged:
    permissions:
      pull-requests: write # Required to add labels to PRs
    steps:
      - name: Add externally-merged label
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            if (!context.payload.issue.pull_request) return;

            const commentAuthor = context.payload.comment.user.login;
            if (commentAuthor !== 'graphite-app[bot]') return;

            const comment = context.payload.comment.body;
            const queuePhrase = 'added this pull request to the [Graphite merge queue]';
            if (!comment.includes(queuePhrase)) return;

            const prNumber = context.payload.issue.number;

            await github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: prNumber,
              labels: ['externally-merged']
            });
🙌 3