Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

ci(github): check every PR for a valid Linear ticket (#16822)

Othman Abu Ajamiehafc658461044
diff --git a/.github/workflows/linear-ticket-check.yml b/.github/workflows/linear-ticket-check.yml
new file mode 100644
index 00000000000..0664a37f148
--- /dev/null
+++ b/.github/workflows/linear-ticket-check.yml
@@ -0,0 +1,33 @@
+name: Linear ticket check
+
+on:
+ pull_request_target:
+ types: [opened, edited, reopened, synchronize]
+
+permissions:
+ contents: read
+
+jobs:
+ linear-ticket-check:
+ name: Linear ticket check
+ runs-on: ubuntu-latest
+ timeout-minutes: 2
+ concurrency:
+ group: linear-ticket-check-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+ if: >
+ github.repository == 'activepieces/activepieces' &&
+ !contains(fromJSON('["dependabot[bot]", "automated-commits-ap"]'), github.event.pull_request.user.login)
+ steps:
+ # pull_request_target exposes secrets to fork PRs: check out the base branch only, never the PR head.
+ - uses: actions/checkout@v5
+
+ - uses: oven-sh/setup-bun@v2
+ with:
+ bun-version: latest
+
+ - name: Check the Linear ticket
+ env:
+ LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
+ PR_BODY: ${{ github.event.pull_request.body }}
+ run: bun tools/scripts/linear-ticket-check.ts
diff --git a/tools/scripts/linear-ticket-check.test.ts b/tools/scripts/linear-ticket-check.test.ts
new file mode 100644
index 00000000000..07f8c515d99
--- /dev/null
+++ b/tools/scripts/linear-ticket-check.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from 'bun:test'
+import { linearTicketCheck } from './linear-ticket-check'
+
+describe('findTickets', () => {
+ it('reads Fixes and Refs for every team key', () => {
+ const body = 'Fixes ENG-123\nRefs AI-45\nrefs sre-7\nFixes GIT-8 and Refs PIE-9'
+ expect(linearTicketCheck.findTickets({ body })).toEqual(['ENG-123', 'AI-45', 'SRE-7', 'GIT-8', 'PIE-9'])
+ })
+
+ it('reads a colon after the keyword and a Markdown link', () => {
+ const body = 'Fixes: ENG-1\nRefs [AI-2](https://linear.app/activepieces/issue/AI-2/title)'
+ expect(linearTicketCheck.findTickets({ body })).toEqual(['ENG-1', 'AI-2'])
+ })
+
+ it('ignores the unedited template placeholder', () => {
+ expect(linearTicketCheck.findTickets({ body: '### Linear ticket\n\nFixes ENG-\n' })).toEqual([])
+ })
+
+ it('ignores tickets inside HTML comments', () => {
+ expect(linearTicketCheck.findTickets({ body: '<!-- Fixes ENG-1 -->' })).toEqual([])
+ })
+
+ it('ignores unknown team keys and bare ticket IDs', () => {
+ expect(linearTicketCheck.findTickets({ body: 'Fixes FOO-1\nSee ENG-2\nFixes #123' })).toEqual([])
+ })
+
+ it('lists a repeated ticket once', () => {
+ expect(linearTicketCheck.findTickets({ body: 'Refs ENG-5\nFixes ENG-5' })).toEqual(['ENG-5'])
+ })
+})
+
+describe('ticketProblem', () => {
+ it('fails a missing ticket', () => {
+ expect(linearTicketCheck.ticketProblem({ id: 'ENG-1', stateType: null })).toContain('does not exist')
+ })
+
+ it('fails a canceled or duplicate ticket', () => {
+ expect(linearTicketCheck.ticketProblem({ id: 'ENG-1', stateType: 'canceled' })).toContain('canceled')
+ expect(linearTicketCheck.ticketProblem({ id: 'ENG-1', stateType: 'duplicate' })).toContain('duplicate')
+ })
+
+ it('passes a ticket in any other status', () => {
+ for (const stateType of ['triage', 'backlog', 'unstarted', 'started', 'completed']) {
+ expect(linearTicketCheck.ticketProblem({ id: 'ENG-1', stateType })).toBeNull()
+ }
+ })
+})
diff --git a/tools/scripts/linear-ticket-check.ts b/tools/scripts/linear-ticket-check.ts
new file mode 100644
index 00000000000..cfc2e57d6c4
--- /dev/null
+++ b/tools/scripts/linear-ticket-check.ts
@@ -0,0 +1,85 @@
+const TEAM_KEYS = ['ENG', 'AI', 'SRE', 'GIT', 'PIE']
+const CLOSED_STATE_TYPES = ['canceled', 'duplicate']
+const TICKET_PATTERN = new RegExp(`\\b(?:fixes|refs):?\\s+\\[?((?:${TEAM_KEYS.join('|')})-\\d+)\\b`, 'gi')
+const ISSUE_QUERY = `query($team: String!, $number: Float!) {
+ issues(includeArchived: true, filter: { team: { key: { eq: $team } }, number: { eq: $number } }) {
+ nodes { state { type } }
+ }
+}`
+const HOW_TO_FIX = [
+ 'How to fix: edit the PR description. Under "Linear ticket", write "Fixes ENG-123" on the last PR of the work, or "Refs ENG-123" on an earlier PR.',
+ `Any team key works: ${TEAM_KEYS.join(', ')}. The check runs again when you save the description.`,
+ 'Community contributor? You need no Linear account and nothing to do. A maintainer adds a GIT or PIE ticket to your PR description, and the check runs again.',
+].join('\n')
+
+function findTickets({ body }: { body: string }): string[] {
+ const visible = body.replace(/<!--[\s\S]*?-->/g, '')
+ return [...new Set([...visible.matchAll(TICKET_PATTERN)].map((match) => match[1].toUpperCase()))]
+}
+
+function ticketProblem({ id, stateType }: { id: string, stateType: string | null }): string | null {
+ if (stateType === null) {
+ return `${id} does not exist in Linear.`
+ }
+ if (CLOSED_STATE_TYPES.includes(stateType)) {
+ return `${id} is ${stateType}. Link the ticket that carries the work.`
+ }
+ return null
+}
+
+async function fetchStateType({ id, apiKey }: { id: string, apiKey: string }): Promise<string | null> {
+ const [team, number] = id.split('-')
+ const response = await fetch('https://api.linear.app/graphql', {
+ method: 'POST',
+ headers: { Authorization: apiKey, 'Content-Type': 'application/json' },
+ body: JSON.stringify({ query: ISSUE_QUERY, variables: { team, number: Number(number) } }),
+ })
+ const result: LinearIssuesResponse = await response.json()
+ if (!response.ok || result.errors || !result.data) {
+ throw new Error(`Linear API returned ${response.status}: ${result.errors?.[0]?.message ?? 'no data'}`)
+ }
+ return result.data.issues.nodes[0]?.state.type ?? null
+}
+
+function fail({ problems }: { problems: string[] }): never {
+ console.error('❌ Linear ticket check failed:\n')
+ for (const problem of problems) {
+ console.error(` - ${problem}`)
+ }
+ console.error(`\n${HOW_TO_FIX}`)
+ process.exit(1)
+}
+
+async function main(): Promise<void> {
+ const tickets = findTickets({ body: process.env.PR_BODY ?? '' })
+ if (tickets.length === 0) {
+ fail({ problems: ['The PR description names no Linear ticket.'] })
+ }
+ const apiKey = process.env.LINEAR_API_KEY
+ if (!apiKey) {
+ console.error('❌ LINEAR_API_KEY is not set. A repo admin must add a read-only Linear API key as the LINEAR_API_KEY secret.')
+ process.exit(1)
+ }
+ const stateTypes = await Promise.all(tickets.map((id) => fetchStateType({ id, apiKey })))
+ const problems = tickets
+ .map((id, index) => ticketProblem({ id, stateType: stateTypes[index] }))
+ .filter((problem): problem is string => problem !== null)
+ if (problems.length > 0) {
+ fail({ problems })
+ }
+ console.log(`✅ Linear ticket check passed: ${tickets.join(', ')}`)
+}
+
+type LinearIssuesResponse = {
+ data?: { issues: { nodes: { state: { type: string } }[] } }
+ errors?: { message: string }[]
+}
+
+export const linearTicketCheck = { findTickets, ticketProblem }
+
+if (import.meta.main) {
+ main().catch((error: unknown) => {
+ console.error(`❌ Linear ticket check could not reach Linear: ${error instanceof Error ? error.message : String(error)}`)
+ process.exit(1)
+ })
+}