How to update comments restriction in Jira through the REST API
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
要約
On Jira Service Management (JSM), comments on issues are either internal or shared with customer.
See Editing and collaborating on issues for more information on how comments relate to JSM issues.
As with other Jira project types, there's no option for JSM projects to use roles to restrict comments in an issue.
This is reported as a feature in - JSDSERVER-829Getting issue details... STATUS .
Moving issues from JSM to other projects' types (Business or Software) turns all comments into public (no restrictions) by default and there's no option in the move issue wizard to assign internal comments to a specific role in the target project.
There's a feature request about it in - JSDSERVER-7119Getting issue details... STATUS .
Sometimes there may be a requirement to move all (or a set of) issues from a JSM project to another from a different type and internal comments should be restricted to a specific project role.
Changing the comments' restrictions from the UI for each comment and issue might be an obstacle.
This document describes the steps needed to modify comments' restrictions through the Jira REST API.
ソリューション
The following procedure is based on comments executed in the Linux Shell.
You may adapt it to run on your preferred coding language.
- Determine the combination of Issue ID and Comment ID for all target internal comments that should be restricted to a specific project role.
If moving all issues in a specific project, the following query helps collecting this information.
- Move the target issues to the new project.
- While the next steps aren't executed, the comments will be public to the new project.
- For each comment (combination of Issue ID and Comment ID), run the following commands to change the comment's restriction.
Define values for some environment variables.
JIRA_ADMIN_USERNAME=admin JIRA_ADMIN_PASSWORD=admin JIRA_BASE_URL=https://mycompany.com/jira ROLE_NAME=Administrators ISSUE_ID=10142 COMMENT_ID=10106
Get current comment data and metadata.
REST_CONTENT_FULL_OUTPUT=$(curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X GET -H "Accept: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} 2>/dev/null)
Modify comment's visibility and temporarily save it in a file.
echo -E ${REST_CONTENT_FULL_OUTPUT} | \ jq '{body: .body, visibility: { type: ("role"), value: ("'${ROLE_NAME}'")}}' \ > modified-comment-data.json
Update the comment with the new restriction to a project role.
curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X PUT -H "Content-Type: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} --data @modified-comment-data.json
参考情報
Restricted comments disappear after moving an issue to a new project
Jira Service Management で内部または外部コメントを取得する方法