Created
March 21, 2023 21:46
-
-
Save ericksoa/8756c24a562cc3a905dcc2a7cf17dc26 to your computer and use it in GitHub Desktop.
Read the Jira story to let the robot implement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jiraClient.ts | |
| import axios, { AxiosInstance } from 'axios'; | |
| export class JiraClient { | |
| private apiClient: AxiosInstance; | |
| constructor(baseUrl: string, apiToken: string) { | |
| this.apiClient = axios.create({ | |
| baseURL: `${baseUrl}/rest/api/3/`, | |
| headers: { | |
| Authorization: `Basic ${Buffer.from(`email@example.com:${apiToken}`).toString('base64')}`, | |
| 'Content-Type': 'application/json', | |
| }, | |
| }); | |
| } | |
| async getNextStory(): Promise<{ key: string; summary: string }> { | |
| const response = await this.apiClient.get('search', { | |
| params: { | |
| jql: 'project = "YourProjectKey" AND issuetype = Story AND status = "To Do" ORDER BY priority DESC', | |
| maxResults: 1, | |
| fields: ['key', 'summary'], | |
| }, | |
| }); | |
| const issue = response.data.issues[0]; | |
| if (!issue) { | |
| throw new Error('No stories found in Jira.'); | |
| } | |
| return { | |
| key: issue.key, | |
| summary: issue.fields.summary, | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment