In this tutorial, you will build a Forge app that integrates with OpenAI APIs to summarize comments in Jira issues. This app addresses the following challenges:
Make sure you have the following:
The tutorial uses these components to build the app: Jira issue panel module, permissions, text, fetch API, api.asApp(), .requestJira(), useState() and useEffect().
An Atlassian cloud developer site lets you install and test your app on Atlassian apps including Confluence and Jira. If you don't have one yet, set it up now:
You can install your app to multiple Atlassian sites. However, app data won't be shared between separate Atlassian apps, sites, or Forge environments.
The limits on the numbers of users you can create are as follows:
To view a summary of an issue's Jira comments, the user clicks the Summarizer button on an issue page. The app displays an issue panel containing a summary of all the comments for the issue.

You can find the source code for this demo here: atlassian/forge-ai-jira-comment-summarizer.

Following the numbered points in the diagram:
Once your development environment is set up, follow these steps to create an initial version of your app:
forge create command in the terminal.summarizer.UI Kit, the Jira app, and then the template jira-issue-panel.forge deploy to deploy your app.forge install in terminal. You will be asked to provide the site
in which you would like to install the app.Depending on your Jira site, you may see the name of your app in the menu, as pictured below, or you may see only its icon.

You can read an explanation of each code block below it.
manifest.yml
1 2modules: jira:issuePanel: - key: summarizer-hello-world-issue-panel resource: main resolver: function: resolver render: native title: summarizer icon: https://developer.atlassian.com/platform/forge/images/icons/issue-panel-icon.svg function: - key: resolver handler: index.handler resources: - key: main path: src/frontend/index.jsx permissions: scopes: - 'read:jira-work' external: fetch: backend: - 'api.openai.com' app: id: <your-app-id>To call certain Jira APIs and external APIs, you need to give your app permission to do so. This is done by adding scopes and external permissions to the app’s manifest.yml file. The app will call two APIs:
- Get issue comments API - As per the API documentation,
read:jira-workpermission is required to call this API.- OpenAI API -
external.fetch.backendis used to define external domains your Forge functions can talk to.The
jira:issuePanelmodule entry was added by thejira-issue-paneltemplate. You can learn more about this module here.Update
src/frontend/index.jsxwith the main top-level logic for your appThe top-level code calls other functions to interact with the Jira and Chat GPT APIs, which you’ll add as you work through the tutorial.
src/frontend/index.jsx
1 2import React, { useEffect, useState } from 'react'; import ForgeReconciler, { Text } from '@forge/react'; import { invoke, view } from '@forge/bridge'; const App = () => { const [summary, setSummary] = useState(); // Getting all the comments of the issue. useEffect(() => { const getCommentSummary = async () => { const commentsData = await invoke('getComments'); console.log("Comments - " + commentsData); if (commentsData) { // ChatGPT prompt to get the summary const prompt = `Here is a sample data where all the comments of a jira issue is joined together: "${commentsData}". I want to summarize this in a way that anybody can get an idea what's going on in this issue without going through all the comments. Create a summary or TLDR for this.` // OpenAI API call to get the summary. const summary = await invoke('callOpenAI', { prompt }); console.log("Summary - " + summary); setSummary(summary); } }; getCommentSummary(); }, []); return ( <> <Text>{summary}</Text> </> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> );This is the main part of the app, which contains the top-level logic to render the UI and fetch data via Forge Resolvers.
App() is then triggered. This is where all the magic happens:
getComments resolver, which is defined later in this tutorial.callOpenAI resolver, which is defined later in this tutorial.Text component.src/resolvers/index.js to call a Jira API to get all comments for this issuesrc/resolvers/index.js
1 2import Resolver from '@forge/resolver'; import api, { route, fetch } from '@forge/api'; const resolver = new Resolver(); resolver.define('getComments', async ({context}) => { // API call to get all comments of Jira issue with key const commentsData = await api.asApp().requestJira(route`/rest/api/3/issue/${context.extension.issue.key}/comment`, { headers: { 'Accept': 'application/json' } }); // API call to get all comments of Jira issue with key const responseData = await commentsData.json(); const jsonData = await responseData.comments let extractedTexts = []; // Extracting all texts in the comments into extractedTexts array await jsonData.map(comment => { if (comment.body && comment.body.content) { comment.body.content.map(contentItem => { if (contentItem.type === "paragraph" && contentItem.content) { contentItem.content.map(textItem => { if (textItem.type === "text" && textItem.text) { extractedTexts.push(textItem.text); } }); } }); } }); return extractedTexts.join(' '); });The app first imports the resolver and API calls that will be used.
We can define the
getCommentsresolver. This resolver calls the Get issue comments API using the api.asApp() method.
- The app will find the issue using the
issue.keyfound incontext, and retrieve the comments associated with that issue- Once the app retrieves all the comments using the Jira API, try to extract only the texts from the comments and exclude other data like
created atandauthor, and join all the comments together into a paragraph.- Join all of the comments together into a paragraph and return it. The app will use this paragraph to construct the
promptvariable it sends to ChatGPT.Step 3: Integrate your app with OpenAI API
Now that the app can retrieve all the comments in a Jira Issue via an API, the next step is to pass it to OpenAI API to get the summary.
Update
src/resolvers/index.jsto call the ChatGPT API to summarize the commentsIn the
src/frontend/index.jsx, you added the variableprompt, then constructed a prompt using the comments and a command that tells OpenAI what to do with that data (in this case: summarize it). The code passes the prompt variable to an API callcallOpenAI, which would call OpenAI API and return the results.Here is the code for the
callOpenAIcall, which would be placed underneath thegetCommentscall:src/resolvers/index.js
1 2resolver.define('callOpenAI', async ({payload, context}) => { const choiceCount = 1; // OpenAI API endpoint const url = `https://api.openai.com/v1/chat/completions`; // Body for API call const body = { model: getOpenAPIModel(), n: choiceCount, messages: [{ role: 'user', content: payload.prompt }] }; // API call options const options = { method: 'POST', headers: { Authorization: `Bearer ${getOpenAPIKey()}`, 'Content-Type': 'application/json', }, redirect: 'follow', body: JSON.stringify(body) }; // API call to OpenAI const response = await fetch(url, options); let result = '' if (response.status === 200) { const chatCompletion = await response.json(); const firstChoice = chatCompletion.choices[0] if (firstChoice) { result = firstChoice.message.content; } else { console.warn(`Chat completion response did not include any assistance choices.`); result = `AI response did not include any choices.`; } } else { const text = await response.text(); result = text; } return result; }); // Get OpenAI API key const getOpenAPIKey = () => { return process.env.OPEN_API_KEY; } // Get OpenAI model const getOpenAPIModel = () => { return 'gpt-3.5-turbo'; // return 'gpt-4'; }Here, the app makes a basic API call to OpenAI. You can learn more about this through their documentation. The steps involved include:
- Set the URL of the API to which the call will be made.
- Provide the details of the payload which consists of information about the GPT model to which the request will be made and the prompt containing the comments and command.
- Set the options that contains extra information like call method, authorisation headers and the payload in JSON format.
- Use Forge’s fetch method to make the API call. Then, parse through the response to get the text of summary that will be displayed in the Jira UI for that issue.
The
getOpenAPIKey()function returns a Forge environment variable calledOPEN_API_KEY. Before running the app for the first time, set this environment variable to the OpenAI API key that is needed to interact with their APIs. To create an environment variable in Forge, enter the following command in your terminal:1 2forge variables set --encrypt OPEN_API_KEY your-keyThe
--encryptflag instructs Forge to store the variable in encrypted form.Step 4: Deploy your app
Once all the above steps are done, you can:
- Run
forge deployin the terminal again as themanifest.ymlfile was updated.- Run
forge install --upgradeand select the installation to upgrade. If you have followed along with this tutorial, it should list the development environment for your Jira instance.- Try out the app in your cloud instance. The first time you run it, Atlassian asks you for permission, for that app to access Jira comments and your user information.
Next steps
Great job on finishing the tutorial on developing a Forge app with OpenAI! Take a moment to celebrate this impressive achievement. If you require any additional help, reach out to our developer community. Keep up the excellent work and continue to explore new opportunities for your apps using Forge and OpenAI technology.
Rate this page: