You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenAI与JIRA集成POC开发求助:实现从JIRA取数并通过OpenAI分析的最小可运行方案

OpenAI与JIRA集成POC开发求助:实现从JIRA取数并通过OpenAI分析的最小可运行方案

Hey there! Let's put together a minimal, working POC for this—since you just need it to run once, we can skip over complex frontend setup hurdles and go with a straightforward Node.js script that handles both JIRA data fetching and OpenAI analysis. Here's how to make it happen step by step:

1. Prep Your Credentials

First, grab the keys you'll need:

  • JIRA: Get your API token (go to your JIRA profile > Security > Create and manage API tokens) and note your JIRA email + your JIRA domain (like your-domain.atlassian.net).
  • OpenAI: Grab your API key from your OpenAI account settings.

2. Minimal Node.js Script (All-in-One)

We'll use two npm packages: axios for JIRA API calls, and openai for interacting with OpenAI. Create a new folder, set up the script, and install dependencies:

First, initialize the project and install packages:

npm init -y
npm install axios openai dotenv

Then create a file jira-openai-poc.js with this code:

require('dotenv').config();
const axios = require('axios');
const { OpenAI } = require('openai');

// Initialize OpenAI client
const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// JIRA configuration
const jiraConfig = {
  email: process.env.JIRA_EMAIL,
  token: process.env.JIRA_TOKEN,
  domain: process.env.JIRA_DOMAIN,
};

// Function to fetch JIRA issues via JQL
async function fetchJiraIssues(jql) {
  try {
    const response = await axios.get(`https://${jiraConfig.domain}/rest/api/3/search`, {
      auth: {
        username: jiraConfig.email,
        password: jiraConfig.token,
      },
      params: {
        jql: jql,
        fields: 'summary,description,status', // Keep fields minimal for POC
        maxResults: 5, // Limit results to keep it simple
      },
    });

    return response.data.issues.map(issue => ({
      key: issue.key,
      summary: issue.fields.summary,
      description: issue.fields.description || 'No description',
      status: issue.fields.status.name,
    }));
  } catch (error) {
    console.error('Error fetching JIRA issues:', error.response?.data || error.message);
    throw error;
  }
}

// Function to analyze issues with OpenAI
async function analyzeWithOpenAI(issues) {
  try {
    const prompt = `Summarize the following JIRA issues and highlight the most common status and top 2 recurring themes:\n\n${JSON.stringify(issues, null, 2)}`;

    const completion = await openai.chat.completions.create({
      model: 'gpt-3.5-turbo',
      messages: [{ role: 'user', content: prompt }],
    });

    return completion.choices[0].message.content;
  } catch (error) {
    console.error('Error analyzing with OpenAI:', error.message);
    throw error;
  }
}

// Main function to run the POC
async function runPOC() {
  // Use a simple JQL query (adjust this to match your project/sprint if needed)
  const jql = 'project = "YOUR_PROJECT_KEY" AND sprint = "YOUR_SPRINT_NAME"';
  
  console.log('Fetching JIRA issues...');
  const issues = await fetchJiraIssues(jql);
  
  console.log('Fetched issues:', issues);
  
  console.log('\nAnalyzing with OpenAI...');
  const analysis = await analyzeWithOpenAI(issues);
  
  console.log('\nOpenAI Analysis Result:\n', analysis);
}

// Run the POC
runPOC();

3. Set Up Environment Variables

Create a .env file in your project folder with these values:

JIRA_EMAIL=your-jira-email@example.com
JIRA_TOKEN=your-jira-api-token
JIRA_DOMAIN=your-domain.atlassian.net
OPENAI_API_KEY=your-openai-api-key

4. Run the Script

Just execute this command in your terminal:

node jira-openai-poc.js

Quick Notes on Your Frontend Script

If you really want to stick with the frontend form you started, you'll need to handle CORS issues (JIRA doesn't allow direct frontend calls by default). For a quick fix, you could use a proxy server, but the Node.js script above is way faster to get up and running for a minimal POC.

That's it—this will fetch a small set of JIRA issues, send them to OpenAI, and return a simple analysis. Adjust the JQL query or the OpenAI prompt to match what you want to analyze!

备注:内容来源于stack exchange,提问作者Cinthiya Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 08:24:33