Skip to content

Instantly share code, notes, and snippets.

@ericksoa
Created March 21, 2023 21:46
Show Gist options
  • Select an option

  • Save ericksoa/8756c24a562cc3a905dcc2a7cf17dc26 to your computer and use it in GitHub Desktop.

Select an option

Save ericksoa/8756c24a562cc3a905dcc2a7cf17dc26 to your computer and use it in GitHub Desktop.
Read the Jira story to let the robot implement
// 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