Closed jacob-ai-bot[bot] closed 2 weeks ago
Hello human! 👋
This PR was created by JACoB to address the issue Integrate Linear Task Management into Application Settings
Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.
If you identify code that needs to be changed, please reject the PR with a specific reason. Be as detailed as possible in your comments. JACoB will take these comments, make changes to the code and push up changes. Please note that this process will take a few minutes.
Once the code looks good, approve the PR and merge the code.
Summary:
Description
We need to create an integration with the task management tool Linear that functions similarly to our existing Jira integration. The integration will allow users to connect their Linear accounts, select specific boards, and synchronize issues between Linear and GitHub.
Requirements
OAuth Authentication Flow
accessToken
andrefreshToken
from the callback.Board Selection
Board Synchronization
Automated Synchronization
Expected Outcome
Notes
Plan:
Step 1: Create
/src/server/db/migrations/YYYYMMDDHHMMSS_addLinearToAccountsAndProjects.ts
Task: Create migration to add Linear columns to accounts and projects tables
Instructions: Create a new migration file that adds
linearAccessToken
andlinearRefreshToken
columns to theaccounts
table, and adds alinearBoardId
column to theprojects
table. Ensure that the new columns are nullable and use appropriate data types such astext
for tokens and identifiers.Exit Criteria: The migration file can be run to update the database schema without errors, adding the specified columns.
Step 2: Edit
/src/server/db/tables/accounts.table.ts
Task: Add Linear columns to AccountsTable model
Instructions: In the file
/src/server/db/tables/accounts.table.ts
, add two new nullable text columns namedlinearAccessToken
andlinearRefreshToken
to theAccountsTable
class. These columns will store the Linear OAuth tokens for each user account.Exit Criteria: The
AccountsTable
model includes the new columns, and the application can interact with the accounts table, including the new columns, without errors.Step 3: Edit
/src/server/db/tables/projects.table.ts
Task: Add linearBoardId to ProjectsTable model
Instructions: In the file
/src/server/db/tables/projects.table.ts
, add a new nullable text column namedlinearBoardId
to theProjectsTable
class. This column will store the selected Linear board ID for each project.Exit Criteria: The
ProjectsTable
model includes the new column, and the application can interact with the projects table, including the new column, without errors.Step 4: Create
/src/app/api/auth/linear/callback/route.ts
Task: Implement Linear OAuth callback route
Instructions: Create a new API route at
/src/app/api/auth/linear/callback/route.ts
to handle the OAuth callback from Linear. This route should extract the authorization code and state from the query parameters, validate them, and exchange the authorization code for access and refresh tokens using Linear's token endpoint. The obtained tokens should be stored in theaccounts
table underlinearAccessToken
andlinearRefreshToken
for the authenticated user. After storing the tokens, redirect the user to the project's settings page.Exit Criteria: The OAuth callback route successfully exchanges the code for tokens, stores them in the database, and redirects the user to the settings page.
Step 5: Create
/src/server/api/routers/linear.ts
Task: Create TRPC router for Linear integration
Instructions: Create a new TRPC router at
/src/server/api/routers/linear.ts
to handle Linear integration. This router should include procedures similar to the existing Jira router, such asisUserConnectedToLinear
,getBoards
,saveLinearBoardId
, andsyncBoard
. These procedures will manage the connection status, fetch available Linear boards, save the selected board ID for a project, and synchronize issues from Linear.Exit Criteria: The Linear TRPC router is created with the necessary procedures and can be used by the frontend to manage Linear integration.
Step 6: Edit
/src/app/dashboard/[org]/[repo]/settings/Settings.tsx
Task: Add 'Connect to Linear' button and UI components to Settings page
Instructions: In the settings page component at
/src/app/dashboard/[org]/[repo]/settings/Settings.tsx
, add a 'Connect to Linear' button similar to the 'Connect to Jira' button. Implement the logic to handle Linear authentication status. After successful authentication, provide an interface for the user to select a Linear board to associate with the project. Ensure state management and UI elements follow the existing patterns used for Jira integration.Exit Criteria: Users can connect their Linear accounts, select a Linear board, and initiate synchronization from the settings page.
Step 7: Create
/src/server/utils/linear.ts
Task: Implement utility functions for Linear API interactions
Instructions: Create a new utility module at
/src/server/utils/linear.ts
that includes functions for interacting with the Linear API. Implement functions such asrefreshLinearAccessToken
,fetchLinearBoards
,syncLinearBoard
, andfetchNewLinearIssues
. These functions should handle token refreshing, fetching available boards, synchronizing issues from Linear, and creating corresponding GitHub issues using the enhanced issue function. Follow similar patterns to the existing Jira utility functions.Exit Criteria: The utility module provides necessary functions to interact with the Linear API and supports board synchronization.
Step 8: Edit
/src/server/messaging/listener.ts
Task: Add cron job for fetching new Linear issues
Instructions: In the listener file at
/src/server/messaging/listener.ts
, add a new cron job that runs once an hour to fetch new Linear issues. This cron job should call a functionfetchAllNewLinearIssues
(implemented in the Linear utility module) that iterates over all projects connected to Linear, fetches new issues from the associated Linear boards, and creates corresponding GitHub issues using the enhanced issue function.Exit Criteria: New Linear issues are automatically synchronized to GitHub via the cron job.
Step 9: Edit
/src/types.ts
Task: Add 'Linear' to IssueBoardSource enum
Instructions: In the types file at
/src/types.ts
, add 'Linear' as a new value to theIssueBoardSource
enum. This will be used to distinguish Linear boards in the issue boards table and other parts of the application.Exit Criteria: The 'Linear' value is added to
IssueBoardSource
, and can be used in the application to identify Linear issue boards.Step 10: Create
/src/server/db/migrations/YYYYMMDDHHMMSS_addLinearToIssueSourceEnum.ts
Task: Create migration to add 'Linear' to issue_source enum
Instructions: Create a new migration file at
/src/server/db/migrations/YYYYMMDDHHMMSS_addLinearToIssueSourceEnum.ts
that alters theissue_source
enum type in the database to include 'Linear' as a valid value. Ensure that the migration handles both the up and down cases correctly.Exit Criteria: The migration file updates the
issue_source
enum in the database successfully, adding 'Linear' as a valid value.