Prevent converting a Test Execution to another issue type when there is a test run
Hi All using below code I saw its working in log but how can I restrict the move if I have test runs
I shared the below code that's not restricting the move click but issue got reset after final changes
async function checkTestRuns(issueId, token) {
const query = `
query ($issueId: String!) {
getTestExecution(issueId: $issueId) {
testRuns(limit: 10) {
total
results {
id
status { name }
test { jira(fields: ["key", "summary"]) }
}
}
}
}
`;
const response = await api.fetch('https://xray.cloud.getxray.app/api/v2/graphql', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query, variables: { issueId } })
});
if (!response.ok) {
console.error('❌ Failed to fetch test runs:', await response.text());
return false;
}
const data = await response.json();
console.log("data",JSON.stringify(data))
const total = data?.data?.getTestExecution?.testRuns?.total || 0;
return total > 0;
}
// Check if issue type changed from Test Execution while test runs exist
export async function validateIssueTypeChange(event, token) {
const issueId = event?.issue?.id;
const changelog = event?.changelog?.items || [];
const issueTypeChange = changelog.find(i => i.field === 'issuetype');
const fromTypeId = issueTypeChange?.from;
const toTypeId = issueTypeChange?.to;
const currentTypeName = event.issue.fields.issuetype?.name;
console.log('Type change:', { fromTypeId, toTypeId, currentTypeName });
// Only validate if moving away from Test Execution
// Main validator entry point
export async function run(event) {
console.log('Incoming event:', JSON.stringify(event, null, 2));
//const issueId = event?.issue?.id;
const token = XRAY_TOKEN;
const typeChangeResult = await validateIssueTypeChange(event, token);
console.log("typeChangeResult",typeChangeResult)
if (!typeChangeResult) return typeChangeResult;
}
Welcome @Pandey_ Anil _Non-Kenvue_
I'd suggest to use an easier approach which is adding a property to your workflow on your moving transition:
Key: jira.permission.edit.denied
Value: leave it empty
Hi @Nikola Perisic thanks for quick reply, I just want to restrict this area using my plugins, its possible see attachments? as I have fixed for transition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.