Created
March 21, 2023 18:56
-
-
Save ericksoa/cbc75923171ba73b24b72db411c4c61f to your computer and use it in GitHub Desktop.
Summarize your work from Jira into an engaging narrative for your boss
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
| // Step 1: Setup your development environment and install required dependencies. | |
| // Install required packages using npm or yarn: | |
| // npm install axios @types/axios dotenv openai @types/node | |
| // or | |
| // yarn add axios @types/axios dotenv openai @types/node | |
| import axios, { AxiosResponse } from 'axios'; | |
| import * as dotenv from 'dotenv'; | |
| import * as openai from 'openai'; | |
| dotenv.config(); | |
| // Replace with your Jira and OpenAI API credentials | |
| const JIRA_EMAIL = process.env.JIRA_EMAIL; | |
| const JIRA_API_TOKEN = process.env.JIRA_API_TOKEN; | |
| const OPENAI_API_KEY = process.env.OPENAI_API_KEY; | |
| const JIRA_BASE_URL = 'https://yourcompany.atlassian.net/rest/api/3'; | |
| const jiraAuthHeader = { | |
| Authorization: `Basic ${Buffer.from(`${JIRA_EMAIL}:${JIRA_API_TOKEN}`).toString('base64')}`, | |
| }; | |
| openai.apiKey = OPENAI_API_KEY; | |
| // Step 2: Fetch Jira data using the Jira API. | |
| async function fetchCompletedTasks() { | |
| try { | |
| const response: AxiosResponse = await axios.get(`${JIRA_BASE_URL}/search`, { | |
| headers: jiraAuthHeader, | |
| params: { | |
| jql: 'project = YOUR_PROJECT_KEY AND resolution = Done AND updated >= -1w', // Adjust JQL query as needed | |
| fields: 'summary,created,updated,issuetype,status', | |
| }, | |
| }); | |
| return response.data.issues; | |
| } catch (error) { | |
| console.error('Error fetching Jira data:', error); | |
| return []; | |
| } | |
| } | |
| // Step 3: Call the OpenAI API to generate a summary. | |
| async function generateReportSummary(tasks: any[]) { | |
| const taskDescriptions = tasks.map( | |
| (task) => `* ${task.fields.summary} (${task.fields.status.name})` | |
| ).join('\n'); | |
| const prompt = `Write a summary about the following completed tasks in an exciting and engaging tone:\n\n${taskDescriptions}\n\nSummary:`; | |
| try { | |
| const response = await openai.Completion.create({ | |
| engine: 'text-davinci-002', | |
| prompt, | |
| max_tokens: 100, | |
| n: 1, | |
| stop: null, | |
| temperature: 0.8, | |
| }); | |
| return response.choices[0].text.trim(); | |
| } catch (error) { | |
| console.error('Error generating report summary:', error); | |
| return ''; | |
| } | |
| } | |
| (async () => { | |
| const tasks = await fetchCompletedTasks(); | |
| if (tasks.length === 0) { | |
| console.log('No completed tasks found.'); | |
| return; | |
| } | |
| const summary = await generateReportSummary(tasks); | |
| console.log('Report Summary:', summary); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment