jacob-ai-bot / jacob

Just Another Coding Bot
https://jacb.ai
Apache License 2.0
131 stars 20 forks source link

JACoB PR for Issue Implement Linear Project Management Integration #284

Closed jacob-ai-bot[bot] closed 2 weeks ago

jacob-ai-bot[bot] commented 2 weeks ago

Summary:

Overview

We need to add integration support for Linear, a project management tool, similar to our existing Jira integration. This will allow users to connect their Linear accounts and synchronize their project boards with our application.

Requirements

Expected Outcome

Users should be able to seamlessly connect their Linear accounts, select a project board, and have new issues from Linear automatically synchronized with our application, just as they currently can with Jira. @jacob-ai-bot --skip-build

Plan:

Step 1: Create /src/server/db/migrations/20241101000003_addLinearToAccounts.ts

Task: Add Linear fields to accounts table

Instructions: Create a new migration file named '20241101000003_addLinearToAccounts.ts' in '/src/server/db/migrations/'. This migration should add new nullable text columns 'linearAccessToken', 'linearRefreshToken', and a nullable timestamp column 'linearTokenExpiresAt' to the 'accounts' table.

Exit Criteria: Running the migration successfully adds the new columns to the 'accounts' table.

Step 2: Edit /src/server/db/tables/accounts.table.ts

Task: Update AccountsTable to include Linear token fields

Instructions: In the 'AccountsTable' class, add new nullable text fields 'linearAccessToken', 'linearRefreshToken', and a nullable timestamp field 'linearTokenExpiresAt' to the 'columns' definition.

Exit Criteria: The 'AccountsTable' includes the new Linear token fields, and ORM mappings are updated accordingly.

Step 3: Create /src/app/api/auth/linear/callback/route.ts

Task: Implement OAuth callback route for Linear

Instructions: Create a new route at '/src/app/api/auth/linear/callback/route.ts'. This route should handle the OAuth callback from Linear by extracting the 'code' and 'state' parameters from the query string. Exchange the authorization code for access and refresh tokens using Linear's token endpoint. Store the tokens in the 'accounts' table for the authenticated user. Redirect the user to the settings page after successful authentication.

Exit Criteria: The OAuth callback route successfully handles Linear's OAuth response, stores tokens in the database, and redirects the user to the settings page.

Step 4: Edit /src/app/dashboard/[org]/[repo]/settings/Settings.tsx

Task: Add Linear integration option to settings page

Instructions: In the settings page component at '/src/app/dashboard/[org]/[repo]/settings/Settings.tsx', add a new section or button for Linear integration, similar to the existing Jira integration. The button should initiate the OAuth flow for Linear by redirecting the user to Linear's authorization URL.

Exit Criteria: The settings page displays an option to connect to Linear, and clicking the button initiates the OAuth flow.

Step 5: Create /src/app/auth/linear/page.tsx

Task: Create Linear OAuth initiation page

Instructions: Implement a new page at '/src/app/auth/linear/page.tsx' that constructs the Linear OAuth authorization URL with the required parameters ('client_id', 'redirect_uri', 'scope', 'state') and redirects the user to Linear's authorization page.

Exit Criteria: Accessing '/auth/linear' redirects the user to Linear's OAuth authorization page.

Step 6: Create /src/server/utils/linear.ts

Task: Implement Linear utility functions

Instructions: Create a new utility file at '/src/server/utils/linear.ts'. Implement functions to use the Linear API to fetch the user's boards using the stored access token. Include functions for refreshing tokens if necessary.

Exit Criteria: Utility functions for interacting with the Linear API are implemented and can fetch boards using the access token.

Step 7: Edit /src/app/api/auth/linear/callback/route.ts

Task: Present Linear boards for selection after OAuth

Instructions: In the OAuth callback route at '/src/app/api/auth/linear/callback/route.ts', after storing the tokens, redirect the user to a frontend page where the user's Linear boards are fetched and displayed for selection.

Exit Criteria: After connecting their Linear account, users are redirected to select a Linear board.

Step 8: Create /src/server/db/migrations/20241101000004_addLinearBoardToProjects.ts

Task: Add linearBoardId to projects table

Instructions: Create a new migration file named '20241101000004_addLinearBoardToProjects.ts' in '/src/server/db/migrations/'. This migration should add a new nullable text column 'linearBoardId' to the 'projects' table.

Exit Criteria: Running the migration successfully adds the 'linearBoardId' column to the 'projects' table.

Step 9: Edit /src/server/db/tables/projects.table.ts

Task: Update ProjectsTable with linearBoardId field

Instructions: In the 'ProjectsTable' class at '/src/server/db/tables/projects.table.ts', add a new nullable text field 'linearBoardId' to the columns definition.

Exit Criteria: The 'ProjectsTable' includes the 'linearBoardId' field, and ORM mappings are updated.

Step 10: Edit /src/server/api/routers/linear.ts

Task: Save selected Linear board to database

Instructions: Implement backend logic to save the user's selected Linear board ID to the 'linearBoardId' field in the 'projects' table. Update or create the necessary API endpoint to handle the board selection submission from the frontend.

Exit Criteria: The selected Linear board ID is saved to the database for the user's project.

Step 11: Edit /src/server/messaging/listener.ts

Task: Add cron job for Linear issue synchronization

Instructions: In '/src/server/messaging/listener.ts', add a new cron job that runs every hour, similar to the existing Jira synchronization job. This cron job should call a function 'fetchAllNewLinearIssues' to fetch new issues from Linear boards and create corresponding issues in the application.

Exit Criteria: The cron job is set up and triggers the Linear issue synchronization function every hour.

Step 12: Edit /src/server/utils/linear.ts

Task: Implement Linear issue synchronization functions

Instructions: In '/src/server/utils/linear.ts', implement functions similar to those in '/src/server/utils/jira.ts' for handling Linear issue synchronization. These functions should handle refreshing access tokens if necessary, fetching new issues from the Linear boards saved in the database, and creating corresponding issues in the application.

Exit Criteria: Linear issue synchronization functions are implemented and can fetch and process new issues from Linear boards.

Step 13: Edit /src/server/utils/issues.ts

Task: Update application to handle issues from Linear

Instructions: Modify the existing issue handling logic in '/src/server/utils/issues.ts' (or the appropriate file) to support creating and managing issues from Linear. Ensure that issues imported from Linear are properly integrated into the application, following the same patterns used for Jira issues.

Exit Criteria: New issues from Linear are correctly created and integrated into the application.

jacob-ai-bot[bot] commented 2 weeks ago

Hello human! 👋

This PR was created by JACoB to address the issue Implement Linear Project Management Integration

Next Steps

  1. Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.

  2. 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.

  3. Once the code looks good, approve the PR and merge the code.