Stabilize logging, correlation IDs, service-account Jira auth, and direct approver reminder DMs while splitting the monolith into focused modules with Compose-based deployment. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
2.7 KiB
JavaScript
62 lines
2.7 KiB
JavaScript
import { sleep } from '../lib/util.js';
|
|
|
|
export function createJiraService(jiraClient, log) {
|
|
const { logger, logError } = log;
|
|
|
|
function buildApprovers(issueKey) {
|
|
return new Promise(async function (resolve, reject) {
|
|
const startTime = new Date().getTime();
|
|
logger(`buildApprovers(${issueKey})`, 'Building approval list');
|
|
const approvalList = [];
|
|
await sleep(10000);
|
|
|
|
jiraClient.issues.getIssue({ issueIdOrKey: issueKey })
|
|
.then(issueApprovers => {
|
|
for (const approvals of issueApprovers.fields.customfield_10033) {
|
|
for (const approver of approvals.approvers) {
|
|
if (approver.approverDecision == 'pending') {
|
|
approvalList.push(approver.approver.emailAddress);
|
|
}
|
|
}
|
|
}
|
|
logger('buildApprovers', `${issueKey}: Found ${approvalList.length} approvers pending. (${new Date().getTime() - startTime}ms)`);
|
|
resolve(approvalList);
|
|
})
|
|
.catch(error => {
|
|
logError('buildApprovers', `${issueKey}: Error looking up approvers`, error);
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
async function searchUnapprovedRequests() {
|
|
try {
|
|
const response = await jiraClient.issueSearch.searchForIssuesUsingJqlEnhancedSearchPost({
|
|
jql: 'status in (Escalated, "Pending Approval", "Technical Approval", "Business Approval", "Technical / IT Approval")',
|
|
maxResults: 200,
|
|
fields: ['summary', 'status', 'created', 'reporter', 'updated', 'comment', 'customfield_10032', 'customfield_10033'],
|
|
});
|
|
|
|
logger('searchUnapprovedRequests', `Total matching issues: ${response.issues?.total}`);
|
|
logger('searchUnapprovedRequests', `Issues found: ${response.issues?.length || 0}`);
|
|
|
|
if (response.issues && response.issues.length > 0) {
|
|
response.issues.forEach(issue => {
|
|
logger('searchUnapprovedRequests', `- ${issue.key}: ${issue.fields.summary || 'No summary'} (Status: ${issue.fields.status?.name || 'Unknown'})`);
|
|
});
|
|
} else {
|
|
logger('searchUnapprovedRequests', 'No issues found matching the JQL.');
|
|
}
|
|
|
|
return response.issues || [];
|
|
} catch (error) {
|
|
logError('searchUnapprovedRequests', 'Jira search failed', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
return {
|
|
buildApprovers,
|
|
searchUnapprovedRequests,
|
|
};
|
|
}
|