In this short guide, we will learn how to retrieve issue comments from Jira using the Python Jira library. Whether you're building automation scripts, reporting dashboards, or data analysis tools, accessing Jira comments programmatically is essential for tracking discussions, decisions, and updates on tickets.

The Jira Python library provides simple methods to fetch comments, parse comment metadata, and extract user information from any issue.

1: Install and Setup Jira Python Library

First, install the jira library and set up authentication:

pip install jira

Basic connection setup:

from jira import JIRA

server = 'https://your-company.atlassian.net'
email = '[email protected]'
api_token = 'your_api_token'

jira = JIRA(server=server, basic_auth=(email, api_token))

print("Connected to Jira successfully!")

Output Result:

Connected to Jira successfully!

Note: Generate an API token from your Atlassian account settings at: https://id.atlassian.com/manage-profile/security/api-tokens

2: Get All Comments from a Jira Issue

Retrieve all comments from a specific issue using the issue key:

from jira import JIRA

jira = JIRA(server='https://your-company.atlassian.net', 
            basic_auth=('[email protected]', 'api_token'))

issue_key = 'PROJ-123'
issue = jira.issue(issue_key)

comments = issue.fields.comment.comments

print(f"Total comments on {issue_key}: {len(comments)}\n")

for idx, comment in enumerate(comments, 1):
    print(f"Comment {idx}:")
    print(f"Author: {comment.author.displayName}")
    print(f"Created: {comment.created}")
    print(f"Body: {comment.body[:100]}...\n")

Output Result:

Total comments on PROJ-123: 5

Comment 1:
Author: John Smith
Created: 2024-12-10T09:30:15.000+0000
Body: This issue is blocking our deployment. Need urgent attention from the backend team...

Comment 2:
Author: Sarah Johnson
Created: 2024-12-11T14:22:45.000+0000
Body: I've reviewed the code and identified the root cause. The API endpoint is missing proper...

Comment 3:
Author: Michael Chen
Created: 2024-12-12T10:15:30.000+0000
Body: Fixed in PR #456. Running integration tests now...

Key attributes available:

  • comment.author.displayName - User's full name
  • comment.author.emailAddress - Email address
  • comment.created - Creation timestamp
  • comment.updated - Last update timestamp
  • comment.body - Comment text content
  • comment.id - Unique comment ID

3: Filter Comments by User

Extract comments from specific users for tracking individual contributions:

from jira import JIRA

jira = JIRA(server='https://your-company.atlassian.net', 
            basic_auth=('[email protected]', 'api_token'))

issue = jira.issue('PROJ-456')
target_user = '[email protected]'

user_comments = [c for c in issue.fields.comment.comments 
                 if c.author.emailAddress == target_user]

print(f"Comments by {target_user}: {len(user_comments)}\n")

for comment in user_comments:
    print(f"Date: {comment.created}")
    print(f"Comment: {comment.body}\n")

Output Result:

Comments by [email protected]: 3

Date: 2024-12-08T11:20:00.000+0000
Comment: Starting work on this ticket today.

Date: 2024-12-09T16:45:30.000+0000
Comment: Encountered an issue with the database migration. Working on a fix.

Date: 2024-12-10T09:30:15.000+0000
Comment: Issue resolved. Ready for QA testing.

4: Export Comments to DataFrame for Analysis

Convert Jira comments to a pandas DataFrame for data analysis and reporting:

from jira import JIRA
import pandas as pd

jira = JIRA(server='https://your-company.atlassian.net', 
            basic_auth=('[email protected]', 'api_token'))

issue = jira.issue('PROJ-789')
comments = issue.fields.comment.comments

data = []
for comment in comments:
    data.append({
        'Author': comment.author.displayName,
        'Email': comment.author.emailAddress,
        'Created': comment.created[:10],
        'Comment': comment.body[:100]
    })

df = pd.DataFrame(data)
print(df)

Output Result:

           Author                    Email     Created                                           Comment
0     John Smith    [email protected]  2024-12-08         Starting work on this ticket today.
1  Sarah Johnson  [email protected]  2024-12-09  I've reviewed the code and identified the root...
2   Michael Chen    [email protected]  2024-12-10         Fixed in PR #456. Running integration tests...
3     Emma Davis      [email protected]  2024-12-11         Verified the fix in staging environment. All...

5: Get Comments with Expand Parameter

Use the expand parameter for more efficient comment retrieval when dealing with many issues:

from jira import JIRA

jira = JIRA(server='https://your-company.atlassian.net', 
            basic_auth=('[email protected]', 'api_token'))

issue = jira.issue('PROJ-234', expand='renderedFields,names,schema,operations,changelog')

comments = jira.comments(issue)

print(f"Total comments: {len(comments)}\n")

for comment in comments[-3:]:
    print(f"ID: {comment.id}")
    print(f"Author: {comment.author.displayName}")
    print(f"Body: {comment.body[:80]}...")
    print()

Output Result:

Total comments: 12

ID: 10234
Author: Sarah Johnson
Body: The API changes are deployed to production. Monitoring for any issues...

ID: 10235
Author: Michael Chen
Body: Performance looks good. Response times under 200ms...

ID: 10236
Author: Emma Davis
Body: Closing this ticket. All acceptance criteria met...

Resources