chore: add linear issue creation workflow #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Linear Issue from Comments | |
| on: | |
| issue_comment: | |
| types: [created] | |
| pull_request_review_comment: | |
| types: [created] | |
| jobs: | |
| create-issue: | |
| if: startsWith(github.event.comment.body, '/linear ') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Parse and create Linear issue | |
| uses: actions/github-script@v7 | |
| env: | |
| LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }} | |
| LINEAR_TEAM_KEY: ${{ secrets.LINEAR_TEAM_KEY }} | |
| with: | |
| script: | | |
| const body = context.payload.comment.body; | |
| const title = body.replace('/linear ', '').split('\n')[0].trim(); | |
| const sourceUrl = context.payload.comment.html_url; | |
| const sourceTitle = context.payload.issue?.title || context.payload.pull_request?.title; | |
| const author = context.payload.comment.user.login; | |
| const description = `Created from GitHub by @${author}\n\n[Source](${sourceUrl}): ${sourceTitle}`; | |
| const response = await fetch('https://api.linear.app/graphql', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': process.env.LINEAR_API_KEY | |
| }, | |
| body: JSON.stringify({ | |
| query: ` | |
| mutation CreateIssue($title: String!, $teamKey: String!, $description: String) { | |
| issueCreate(input: { title: $title, teamId: $teamKey, description: $description }) { | |
| issue { identifier url } | |
| } | |
| } | |
| `, | |
| variables: { | |
| title, | |
| teamKey: process.env.LINEAR_TEAM_KEY, | |
| description | |
| } | |
| }) | |
| }); | |
| const data = await response.json(); | |
| const issue = data.data.issueCreate.issue; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.issue?.number || context.payload.pull_request?.number, | |
| body: `Created Linear issue: [${issue.identifier}](${issue.url})` | |
| }); |