export async function run(event, context) {
console.log('Trigger Event:', event);
const issue = event.issue;
const parentIssueId = issue.fields.parent?.id;
if (parentIssueId) {
try {
// Fetch parent issue details
const response = await fetch(`/rest/api/3/issue/${parentIssueId}`);
const parentIssue = await response.json();
const allowedIssueTypes = ['Story', 'Task'];
if (!allowedIssueTypes.includes(parentIssue.fields.issuetype.name)) {
await fetch(`/rest/api/3/issue/${issue.id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
});
console.log(`Subtask ${issue.key} deleted because its parent issue type is not allowed.`);
}
} catch (error) {
console.error('Error handling issue:', error);
}
} else {
console.log(`No parent issue found for ${issue.key}.`);
}}