This repository was archived by the owner on Mar 27, 2026. It is now read-only.
forked from PagerDuty/pagerduty-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (146 loc) · 6.42 KB
/
Copy pathcreate-jira-ticket.yml
File metadata and controls
150 lines (146 loc) · 6.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Create Jira Ticket for New GitHub Issues
on:
issues:
types: [opened]
jobs:
create-jira-ticket:
runs-on: ubuntu-latest
steps:
- name: Create Jira Ticket
uses: actions/github-script@v7
with:
script: |
const issueData = context.payload.issue;
const issueLabels = issueData.labels.map(label => label.name);
console.log(`Processing GitHub issue #${issueData.number}: ${issueData.title}`);
console.log(`Labels: ${issueLabels.join(', ')}`);
// Determine issue type and priority based on GitHub labels
let jiraIssueType = "13880"; // Default to Task
let priority = "Medium";
let issueTypeForLog = "Task";
if (issueLabels.includes('bug')) {
jiraIssueType = "11"; // Bug
priority = "High";
issueTypeForLog = "Bug";
} else if (issueLabels.includes('enhancement')) {
jiraIssueType = "13880"; // Task
priority = "Medium";
issueTypeForLog = "Task";
}
console.log(`Mapping to Jira: Type=${issueTypeForLog} (ID: ${jiraIssueType}), Priority=${priority}`);
// Format labels for Jira description
const labelsText = issueLabels.length > 0 ? issueLabels.join(', ') : 'None';
// Create description with GitHub information
const description = "*GitHub Issue:* " + issueData.html_url + "\n\n" +
"*Reporter:* " + issueData.user.login + "\n" +
"*Labels:* " + labelsText + "\n" +
"*Created:* " + new Date(issueData.created_at).toLocaleString() + "\n\n" +
"----\n\n" +
"h3. Description\n\n" +
(issueData.body || 'No description provided') + "\n\n" +
"----\n\n" +
"_This ticket was automatically created from a GitHub issue in the PagerDuty MCP Server repository._";
// Create Jira ticket payload
const jiraPayload = {
fields: {
project: {
key: "CSGINS"
},
parent: {
key: "CSGINS-2353"
},
summary: "[GitHub MCP] " + issueData.title,
description: description,
issuetype: {
id: jiraIssueType
},
priority: {
name: priority
},
assignee: {
emailAddress: "jruiz@pagerduty.com"
},
labels: [
"github-mcp",
"auto-created"
].concat(issueLabels.map(label => label.replace(/[^a-zA-Z0-9]/g, '-'))),
components: [
{
name: "CSG APPS"
}
]
}
};
console.log('Jira payload prepared');
// Create Jira ticket
const jiraAuth = Buffer.from(`${process.env.JIRA_EMAIL}:${process.env.JIRA_API_TOKEN}`).toString('base64');
try {
console.log('Sending request to Jira API...');
const response = await fetch(`${process.env.JIRA_BASE_URL}/rest/api/2/issue`, {
method: 'POST',
headers: {
'Authorization': `Basic ${jiraAuth}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(jiraPayload)
});
if (!response.ok) {
const errorData = await response.text();
console.error(`Jira API Error: ${response.status} - ${errorData}`);
throw new Error(`Jira API error: ${response.status} - ${errorData}`);
}
const jiraTicket = await response.json();
console.log(`✅ Created Jira ticket: ${jiraTicket.key}`);
// Add success comment to GitHub issue - Community focused without Jira link
const successComment = "🙏 **Thanks for contributing to the PagerDuty MCP Server!**\n\n" +
"Your issue has been logged and a ticket has been created for our development team. We appreciate you taking the time to help us improve.\n\n" +
"**What happens next:**\n" +
"- Our team will review and prioritize your issue\n" +
"- Updates will be posted here as we make progress\n" +
"- Feel free to add more details if you think of anything else\n\n" +
"We'll keep you in the loop! 📬";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueData.number,
body: successComment
});
console.log('✅ Added success comment to GitHub issue');
} catch (error) {
console.error('❌ Error creating Jira ticket:', error.message);
// Add detailed error comment to GitHub issue
const errorComment = "❌ **Failed to create Jira ticket**\n\n" +
"**Error**: " + error.message + "\n\n" +
"**Attempted Configuration:**\n" +
"- Project: CSGINS\n" +
"- Epic: CSGINS-2353\n" +
"- Issue Type: " + issueTypeForLog + " (ID: " + jiraIssueType + ")\n" +
"- Priority: " + priority + "\n" +
"- Assignee: jruiz@pagerduty.com\n" +
"- Component: CSG APPS\n\n" +
"Please check the [GitHub Actions logs](https://github.com/" + context.repo.owner + "/" + context.repo.repo + "/actions) for more details, or create the Jira ticket manually.";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueData.number,
body: errorComment
});
// Re-throw error to mark the action as failed
throw error;
}
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
- name: Notify on Success
if: success()
run: |
echo "✅ Jira ticket created successfully!"
echo "Check the GitHub issue for the Jira ticket link."
- name: Notify on Failure
if: failure()
run: |
echo "❌ Failed to create Jira ticket."
echo "Check the GitHub issue for error details."
echo "Review the action logs for debugging information."