jacob-ai-bot / jacob

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

Convert New Jira Issues into JACoB Todos #241

Closed kleneway closed 3 weeks ago

kleneway commented 4 weeks ago

We want to enhance our integration with Jira by converting new Jira issues into JACoB todos. The goal is to allow users to sync specific Jira boards with our application so that any new issues created in those boards are automatically converted into todos within JACoB.

Requirements:

Expected Outcome:

Additional Considerations:


Here is more detailed information gathered from the internet to help with this request.

To integrate your application with Jira and allow users to select a specific board for issue analysis, follow these detailed steps:

1. Determine the User's Jira Domain

Each Jira Cloud instance is hosted under a unique subdomain in the format https://{user-domain}.atlassian.net. To identify the correct domain for API requests:

2. Retrieve Available Boards

With the baseUrl determined, fetch the list of boards accessible to the user:

Request:

```http GET {baseUrl}/rest/agile/1.0/board Authorization: Bearer {access_token} Accept: application/json



**Response**:

```json
{
  "maxResults": 50,
  "startAt": 0,
  "total": 2,
  "values": [
    {
      "id": 1,
      "self": "https://{user-domain}.atlassian.net/rest/agile/1.0/board/1",
      "name": "Sample Scrum Board",
      "type": "scrum"
    },
    {
      "id": 2,
      "self": "https://{user-domain}.atlassian.net/rest/agile/1.0/board/2",
      "name": "Sample Kanban Board",
      "type": "kanban"
    }
  ]
}
```

Present this list to the user, allowing them to select a specific board.

**3. Fetch Issues from the Selected Board**

Once a board is selected, retrieve its issues:

**Request**:

```http
GET {baseUrl}/rest/agile/1.0/board/{boardId}/issue
Authorization: Bearer {access_token}
Accept: application/json
```

Replace `{boardId}` with the ID of the selected board.

**Response**:

```json
{
  "startAt": 0,
  "maxResults": 50,
  "total": 100,
  "issues": [
    {
      "id": "10001",
      "key": "PROJ-1",
      "fields": {
        "summary": "Issue summary",
        "status": {
          "name": "To Do"
        },
        ...
      }
    },
    ...
  ]
}
```

This response provides the issues on the selected board, which you can then analyze using your AI tools.

**4. Implement Periodic Issue Retrieval**

To monitor new issues hourly:

- **Store the Timestamp of the Last Check**: Maintain the timestamp of the last successful issue retrieval.

- **Schedule Hourly Checks**: Set up a cron job to run every hour. there is already support for cron jobs in the project, look to it for examples. 

- **Fetch New Issues**: During each run, use the Jira API to search for issues created or updated since the last check.

  **Request**:

  ```http
  GET {baseUrl}/rest/api/3/search?jql=project={projectKey} AND updated >= "{lastCheckTime}"
  Authorization: Bearer {access_token}
  Accept: application/json
  ```

  Replace `{projectKey}` with the key of the project associated with the board and `{lastCheckTime}` with the stored timestamp.

**5. Analyze and Process New Issues**

For each new issue retrieved:

-** Create New Todo": Use the same workflow as the webhook for new github issues and create a new Todo + Research for the project. 

**6. Handle Authentication and Token Refresh**

Ensure your application can handle token expiration:

- **Monitor Token Expiry**: Track the expiration time of the OAuth token.

- **Refresh Tokens as Needed**: If the token is expired or about to expire, use the refresh token to obtain a new access token.

**Additional Considerations**

- **Error Handling**: Implement robust error handling for API requests, including retries and logging.

- **Rate Limiting**: Be aware of Jira's API rate limits and design your application to handle HTTP 429 responses gracefully.

- **User Permissions**: Ensure that the OAuth token has the necessary scopes to access board and issue data.

By following these steps, you can effectively integrate your application with Jira, allowing users to select boards and enabling your AI tools to analyze new issues as they arise. 
@jacob-ai-bot --skip-build
jacob-ai-bot[bot] commented 4 weeks ago

JACoB here...

You mentioned me on this issue and I am busy taking a look at it.

I'll continue to comment on this issue with status as I make progress.

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

Update

I've completed my work on this issue and have created a pull request: JACoB PR for Issue Convert New Jira Issues into JACoB Todos.

Please review my changes there.