Open jacob-ai-bot[bot] opened 1 day ago
Hello human! 👋
This PR was created by JACoB to address the issue Implement Functionality to Link Todos Back to Jira Tickets
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 enhance our Jira integration by adding the ability for our application to update Jira tickets with a link to the corresponding todo item in our system. When a todo is created based on a Jira ticket, the application should automatically write back to that Jira ticket, adding a link that directs users to the related todo within our platform.
Expected Outcome
Additional Information
Plan:
Step 1: Create
/src/server/db/migrations/20241120000000_add_jira_issue_id_to_todos.ts
Task: Add jiraIssueId column to todos table
Instructions: Create a new migration file to add a nullable 'jiraIssueId' column to the 'todos' table. This column should be a string (varchar) to store the Jira issue ID associated with the todo. Ensure the migration handles both adding and removing the column for up and down migrations.
Exit Criteria: The migration file should successfully add a nullable 'jiraIssueId' column to the 'todos' table when run.
Step 2: Edit
/src/server/db/tables/todos.table.ts
Task: Update todos.table.ts to include jiraIssueId column
Instructions: Modify the '/src/server/db/tables/todos.table.ts' file to add the 'jiraIssueId' column to the 'TodosTable' class. The new column should be defined as a nullable string (t.text().nullable()) named 'jiraIssueId'. Ensure that the column is included in the table's columns definition.
Exit Criteria: The TodosTable class should include the new 'jiraIssueId' column, matching the database schema.
Step 3: Edit
/src/server/utils/todos.ts
Task: Update todos.ts to link todos back to Jira tickets
Instructions: In the '/src/server/utils/todos.ts' file, within the 'getOrCreateTodo' function, modify the function to capture the 'jiraIssueId' when creating a todo based on a Jira ticket. After creating the todo, if 'jiraIssueId' is present, retrieve the user's Jira access token and cloudId from the database. Then, call the 'updateJiraTicketWithTodoLink' function to update the Jira ticket with a link to the todo. Ensure that you handle any errors that may occur during the process and that the user's Jira credentials are securely managed.
Exit Criteria: When a todo is created from a Jira ticket, the application updates the corresponding Jira ticket by adding a comment with a link to the todo, and errors are properly handled.
Step 4: Edit
/src/server/utils/jira.ts
Task: Add function to update Jira ticket with todo link
Instructions: In the '/src/server/utils/jira.ts' file, add a new function named 'updateJiraTicketWithTodoLink'. This function should accept parameters 'jiraIssueId', 'cloudId', 'accessToken', and 'todoLink'. The function should use the Jira API to add a comment to the Jira issue identified by 'jiraIssueId', including the 'todoLink' in the comment body. Ensure proper error handling and authentication, using the Jira access token provided.
The link format is:
https://app.jacb.ai/dashboard/[org]/[repo]/todos/[todo.id]
Exit Criteria: The 'updateJiraTicketWithTodoLink' function is implemented, allowing the application to add a comment with the todo link to a Jira ticket.