Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vikrantyadav11/50adf47de1cb6a87aeea5c62c8d16a04 to your computer and use it in GitHub Desktop.
Save vikrantyadav11/50adf47de1cb6a87aeea5c62c8d16a04 to your computer and use it in GitHub Desktop.
// Retrieve the current context and issue key
const context = await getContext();
const issueKey = context.extension.issue.key;
// Access the fix version field. Replace this with your own custom field Id if needed.
const fixVersionField = getFieldById("fixVersions");
// Attempt to fetch the current issue data
try {
const res = await makeRequest(`/rest/api/3/issue/${issueKey}`);
const currentStatus = res.body.fields.status.name;
// List of statuses where the Fix Version field should be read-only
const restrictedStatuses = [
"Ready for Merge",
"Merged",
"Ready for Production",
"UAT",
"Closed"
];
// Determine if the field should be read-only
const restrictFixVersionEditing = restrictedStatuses.includes(currentStatus);
// Set the field to read-only based on the status
fixVersionField.setReadOnly(restrictFixVersionEditing);
} catch (error) {
// Log any errors encountered during the request
logger.error(`Failed to retrieve issue data for ${issueKey}: ${error}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment