Skip to content

Conversation

@jacob-local-kevin
Copy link
Contributor

Summary:

Summary:

Description

Implement a feature in Jacob that integrates with Jira by setting up a webhook to listen for new Jira issues. When a new Jira issue is created, Jacob will automatically generate a corresponding to-do, mirroring the existing functionality for GitHub issues. This integration aims to streamline task management and ensure consistency across both platforms.

Features

  • Webhook Integration: Establish a webhook to monitor and receive notifications for new Jira issues using the existing JIRA_API_KEY from process.env.
  • Settings Page Enhancement: Add a new section in the dashboard settings (settings.tsx) that allows users to log in with their Jira accounts.
  • Authentication Handling: Securely store the user's Jira token in the user table after authentication.
  • Automated To-Do Creation: Utilize the stored Jira token to listen for new Jira issues and create corresponding to-dos in Jacob, following the same workflow used for GitHub issues.

Implementation Details

  1. Webhook Setup

    • Configure Jira to send webhook events for new issue creations to Jacob.
    • Ensure the webhook utilizes the JIRA_API_KEY securely stored in process.env.
  2. Update Settings Page (settings.tsx)

    • Introduce a "Log in with Jira" option in the settings section.
    • Implement OAuth or token-based authentication to connect Jira accounts.
    • Store the retrieved Jira token securely in the user table.
  3. Database Schema Modification

    • Add a new field to the user table to store the Jira token.
    • Ensure that the token is encrypted and handled securely to protect user data.
  4. To-Do Workflow Integration

    • Develop the logic to process incoming Jira webhook events.
    • Automatically generate a to-do in Jacob upon receiving a new Jira issue notification.
    • Incorporate necessary steps such as research and planning, consistent with the GitHub issue workflow.

Expected Behavior

  • User Authentication: Users can connect their Jira accounts through the Jacob settings page.
  • Automated Task Creation: New Jira issues will automatically result in the creation of corresponding to-dos within Jacob.
  • Consistent Workflow: The process mirrors the existing GitHub integration, providing a unified experience for managing tasks from both platforms.

Benefits

  • Increased Efficiency: Automates the synchronization of tasks between Jira and Jacob, reducing manual effort.
  • Unified Task Management: Allows users to manage tasks from both GitHub and Jira within a single platform.
  • Improved Consistency: Ensures that workflow processes are standardized across different issue tracking systems.

Environment and Configuration

  • Environment Variables: Ensure that JIRA_API_KEY is correctly set in the environment.
  • Security Measures: Store Jira tokens securely in the database and implement best practices for handling sensitive information.

Additional Notes

  • Error Handling: Implement robust error handling for webhook failures and authentication issues to ensure reliability.

Be sure to research the jira-client package here: https://github.com/jira-node/node-jira-client but ideally use an oauth token instead of username/password. Use this URL to install your 3LO app: https://auth.atlassian.com/authorize?audience=api.atlassian.com&client_id=z9MOoQe9g8QmMCGACf8fMOKnIQAMdoGb&scope=read%3Ame&redirect_uri=https%3A%2F%2Fapp.jacb.ai%2Fapi%2Fjira%2Fcallback&state=${YOUR_USER_BOUND_VALUE}&response_type=code&prompt=consent and the callback url should be https://app.jacb.ai/api/jira/callback

@jacob-ai-bot --skip-build

Plan:

Step 1: Edit /src/server/db/tables/users.table.ts

Task: Add 'jiraToken' field to UsersTable

Instructions:
In the file '/src/server/db/tables/users.table.ts', add a new nullable text field 'jiraToken' to the 'columns' definition in the 'UsersTable' class. This field will securely store the user's Jira access token. Ensure that appropriate data types and security considerations are applied.

Exit Criteria:
The 'UsersTable' class includes the new 'jiraToken' field, and it can be accessed in user records.

Step 2: Create /src/server/db/migrations/20241101000000_addJiraTokenToUsers.ts

Task: Create migration to add 'jiraToken' field to users table

Instructions:
Create a new migration file at '/src/server/db/migrations/20241101000000_addJiraTokenToUsers.ts'. In this migration, modify the 'users' table to add a new nullable text column 'jiraToken'. Use the database migration utilities provided by the project to properly define the change. Ensure the migration can be run without errors and can be rolled back if necessary.

Exit Criteria:
The migration file exists, and running migrations adds the 'jiraToken' column to the 'users' table in the database.

Step 3: Create /src/app/dashboard/[org]/[repo]/settings/page.tsx

Task: Create a Settings page with 'Log in with Jira' option

Instructions:
Create a new Next.js page at '/src/app/dashboard/[org]/[repo]/settings/page.tsx'. This page should render a settings interface for the user, integrating with the existing dashboard layout. Include a 'Log in with Jira' button that initiates the Jira OAuth 2.0 authorization flow by redirecting to the API route '/api/auth/jira/authorize'. Ensure that the button triggers the authorization flow correctly when clicked.

Exit Criteria:
The settings page is accessible, displays correctly, and includes a functional 'Log in with Jira' button that initiates the Jira OAuth flow.

Step 4: Create /src/app/api/auth/jira/authorize/route.ts

Task: Create API route to initiate Jira OAuth authorization

Instructions:
Create a new API route at '/src/app/api/auth/jira/authorize/route.ts'. This route should initiate the Jira OAuth 2.0 authorization flow by redirecting the user to Jira's authorization URL with the necessary parameters, including client_id, redirect_uri, response_type, scopes, and state. Ensure to generate and store the PKCE code challenge and verifier securely for the OAuth flow.

Exit Criteria:
Accessing this API route redirects the user to Jira's authorization URL to begin the OAuth process, with all required parameters correctly set.

Step 5: Create /src/app/api/auth/jira/callback/route.ts

Task: Create API route to handle Jira OAuth callback

Instructions:
Create a new API route at '/src/app/api/auth/jira/callback/route.ts'. This route should handle the OAuth 2.0 callback from Jira after the user authorizes the application. It should exchange the authorization code received from Jira for an access token using Jira's OAuth 2.0 token endpoint. Once the access token is obtained, securely store it in the 'jiraToken' field of the user's record in the database. Handle any errors gracefully and provide appropriate feedback.

Exit Criteria:
The API route successfully processes the OAuth callback, exchanges the authorization code for an access token, and stores the 'jiraToken' in the database.

Step 6: Create /src/app/api/webhooks/jira/route.ts

Task: Create API route to handle Jira webhooks

Instructions:
Create a new API route at '/src/app/api/webhooks/jira/route.ts'. This route should handle incoming POST requests from Jira webhooks. Implement logic to parse the webhook payload, specifically handling events where new issues are created (event type 'jira:issue_created'). When such an event is received, extract the issue details and create a corresponding to-do in Jacob, following the same workflow as for GitHub issues. Ensure that all necessary fields are extracted and mapped correctly.

Exit Criteria:
The API route receives Jira webhook events for new issue creations and successfully creates corresponding to-dos in Jacob.

Step 7: Edit /src/server/auth.ts

Task: Update auth session callback to include 'jiraToken' in session

Instructions:
In the file '/src/server/auth.ts', update the 'session' callback function to include the user's 'jiraToken' in the session object. After retrieving the user from the database, include 'jiraToken' in 'session.user' to make it accessible throughout the application when needed. Ensure that sensitive data is handled securely and that the session remains protected.

Exit Criteria:
The session object now includes 'jiraToken' in 'session.user', making it accessible in the application where user session data is available.

@jacob-local-kevin
Copy link
Contributor Author

Hello human! 👋

This PR was created by JACoB to address the issue Add Jira Webhook 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.

kleneway added a commit that referenced this pull request Dec 3, 2024
JACoB PR for Issue  Implement Repo Dropdown in Dashboard Header to Display Repository Branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant