From cef91e68fac69773d5b120322e69f654700c2a0d Mon Sep 17 00:00:00 2001 From: "RL \"Nearest\" Nabors" <236306+nearestnabors@users.noreply.github.com> Date: Wed, 10 Dec 2025 02:10:51 +0000 Subject: [PATCH] Assign Linear tickets to review GitHub PRs in Dev Rel Team --- .github/workflows/linear.yml | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .github/workflows/linear.yml diff --git a/.github/workflows/linear.yml b/.github/workflows/linear.yml new file mode 100644 index 000000000..3efda06ad --- /dev/null +++ b/.github/workflows/linear.yml @@ -0,0 +1,94 @@ +name: Create Linear ticket on review assignment + +on: + pull_request: + types: + - assigned + - review_requested + - review_request_removed + +jobs: + create-linear-issue: + if: github.event.action == 'assigned' || github.event.action == 'review_requested' + runs-on: ubuntu-latest + + steps: + - name: Extract PR info + id: pr + run: | + echo "title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT + echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT + echo "url=${{ github.event.pull_request.html_url }}" >> $GITHUB_OUTPUT + echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT + + - name: Create Linear issue + id: linear + env: + LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }} + LINEAR_TEAM_ID: ${{ secrets.LINEAR_TEAM_ID }} + LINEAR_PROJECT_ID: ${{ secrets.LINEAR_PROJECT_ID }} + GITHUB_ASSIGNEE: ${{ github.event.assignee.login }} + GITHUB_REVIEWER: ${{ github.event.requested_reviewer.login }} + run: | + # Pick whoever got assigned / requested + ASSIGNEE="${GITHUB_ASSIGNEE:-$GITHUB_REVIEWER}" + + # Simple mapping GitHub username -> Linear user ID (adjust to your team) + case "$ASSIGNEE" in + "nearestnabors") LINEAR_ASSIGNEE_ID="nearestnabors" ;; + "torresmateo") LINEAR_ASSIGNEE_ID="mateo" ;; + "vfanelle") LINEAR_ASSIGNEE_ID="valerie" ;; + "avoguru") LINEAR_ASSIGNEE_ID="guru" ;; + *) LINEAR_ASSIGNEE_ID="" ;; + esac + + TITLE="Review PR: ${{ steps.pr.outputs.title }}" + DESCRIPTION="GitHub PR: ${{ steps.pr.outputs.url }}\nRepository: ${{ steps.pr.outputs.repo }}\nPR #${{ steps.pr.outputs.number }}" + + QUERY='mutation IssueCreate($input: IssueCreateInput!) { + issueCreate(input: $input) { + issue { + id + identifier + url + } + } + }' + + INPUT=$(jq -n \ + --arg title "$TITLE" \ + --arg desc "$DESCRIPTION" \ + --arg teamId "$LINEAR_TEAM_ID" \ + --arg projId "$LINEAR_PROJECT_ID" \ + --arg assigneeId "$LINEAR_ASSIGNEE_ID" \ + '{ + query: $ENV.QUERY, + variables: { + input: { + title: $title, + description: $desc, + teamId: $teamId, + projectId: ($projId | select(. != "")), + assigneeId: ($assigneeId | select(. != "")) + } + } + }' + ) + + RESPONSE=$(curl -s \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $LINEAR_API_KEY" \ + -d "$INPUT" \ + https://api.linear.app/graphql) + + echo "response=$RESPONSE" >> $GITHUB_OUTPUT + + - name: Comment on PR with Linear issue + if: always() + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ISSUE_URL=$(echo '${{ steps.linear.outputs.response }}' | jq -r '.data.issueCreate.issue.url // empty') + if [ -n "$ISSUE_URL" ]; then + gh pr comment ${{ steps.pr.outputs.number }} --body "Created Linear issue: $ISSUE_URL" + fi