-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
85 lines (75 loc) · 2.79 KB
/
server.js
File metadata and controls
85 lines (75 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import express from 'express';
import axios from 'axios';
import cors from 'cors';
import dotenv from 'dotenv';
import process from 'process';
import { Buffer } from 'buffer';
dotenv.config({ path: './keys.config' });
const app = express();
app.use(cors());
app.use(express.json());
const authHeader = `Basic ${Buffer.from(`${process.env.EMAIL}:${process.env.AUTH_TOKEN}`).toString('base64')}`;
app.get('/api/projects', async (req, res) => {
try {
const response = await axios.get(`${process.env.JIRA_API_URL}/project/search`, {
headers: {
'Authorization': authHeader,
'Content-Type': 'application/json'
}
});
const projects = response.data.values.map(project => ({
value: project.id,
name: project.name,
key: project.key
}));
console.log("projects? ", projects)
res.json(projects);
} catch (error) {
console.error("Error fetching projects:", error);
res.status(500).json({ error: error.message });
}
});
app.get('/api/epics/:projectId', async (req, res) => {
const { projectId } = req.params;
console.log("projectId: ", projectId);
try {
const response = await axios.get(`${process.env.JIRA_API_URL}/search?jql=project=${projectId} AND issuetype=Epic`, {
headers: {
'Authorization': authHeader,
'Content-Type': 'application/json'
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.post('/api/create-story', async (req, res) => {
const { projectId, epicId, userStories } = req.body;
try {
// Loop over userStories and create each story in JIRA
const results = await Promise.all(userStories.map(async (story) => {
const issueData = {
fields: {
project: { id: projectId },
summary: story.summary,
description: story.description,
issuetype: { id: "10004" }, // Story Issue Type ID
// Replace 'customfield_XXXXX' with your JIRA's Epic Link field name
"customfield_XXXXX": epicId
}
};
return await axios.post(`${process.env.JIRA_API_URL}/issue`, issueData, {
headers: {
'Authorization': authHeader,
'Content-Type': 'application/json'
}
});
}));
res.json({ success: true, data: results.map(r => r.data) });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
const PORT = process?.env?.PORT || 3001;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));