How to delete comments from issues

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Cloud のみ - この記事は クラウド プラットフォームのアトラシアン製品に適用されます。

要約

Adding unlimited comments to issues often resulted in unusual load times, which in some cases caused reliability and performance problems.

With many comments across different issues and a lack of good ways to delete them in bulk ( JRACLOUD-91983 - Getting issue details... STATUS ), we don’t expect you to jump into your issues and remove the comments one by one.

ソリューション

Jira doesn’t have an easy way to delete comments in bulk. Below are some options:

Option 1: Delete all comments with Jira Automation

You can use Jira Cloud’s automation to delete comments in bulk.

To create a rule that deletes all comments (the comments can't be restored):

  1. Go to the Automation Rules page.

  2. [自動化を作成] を選択します。

  3. ルールの詳細を次のように指定します。

    1. Trigger: Manual trigger
    2. Advanced branching:
      1. Smart value: {{issue.comments.id}}
      2. Variable name: commentId
    3. Action: Delete comment
      1. comment id: {{commentId}}

Option 2: Delete comments older than a specific date with API

次のページは、課題コメントの削除に使用される API にリンクしています。

  1. Get a list of comment IDs under an issue: GET comments

  2. Delete a comment based on its ID: DELETE comment

Below is an example of a Python script that can be used to delete comments:

  • Remember to install python3 first and then jira and requests libraries before running it.
  • The advantage of using the API is that you can define a cutoff date and only delete comments older than the cutoff date.

Please be aware that the usage of the below script is not supported.

Python Script:
Delete Comments
from jira import JIRA
from datetime import datetime
import requests
from requests.auth import HTTPBasicAuth

def delete_old_comments(email, token, domain, issue_key, date_str):
    # Connect to Jira
    options = {'server': f'https://{domain}.atlassian.net'}
    jira = JIRA(options, basic_auth=(email, token))

    try:
        # Parse the input date
        cutoff_date = datetime.strptime(date_str, '%Y-%m-%d')

        # Get the issue
        issue = jira.issue(issue_key)
        
        # Retrieve all comments
        comments = jira.comments(issue)

        # Iterate over comments and delete those older than the cutoff date
        for comment in comments:
            comment_created = datetime.strptime(comment.created.split('T')[0], '%Y-%m-%d')
            if comment_created < cutoff_date:
                # Delete the comment using REST API
                comment_url = f"https://{domain}.atlassian.net/rest/api/3/issue/{issue_key}/comment/{comment.id}"
                response = requests.delete(
                    comment_url,
                    auth=HTTPBasicAuth(email, token)
                )
                
                if response.status_code == 204:
                    print(f"Deleted comment {comment.id} created on {comment.created}: {comment.body[:50]}...")
                else:
                    print(f"Failed to delete comment {comment.id}. Status code: {response.status_code}")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    #Define your inputs here
    email = '' #your email
    api_token = '' #your token
    domain = '' #your Jira domain, only the one before %.atlassian.net
    issue_key = 'KEY-1234' #the issue key
    date_str = '2025-01-01' #Format: YYYY-MM-DD

    # Call the function with the specified inputs
    delete_old_comments(email, api_token, domain, issue_key, date_str)


最終更新日: 2025 年 1 月 17 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.