Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira + Python : How can I retrieve the last comment of an issue?

Sunesh M S September 10, 2018

Hi All,

Jira + Python : Could you please help me to retrieve the last comment of an issue?

 

for Issue in jira.search_issues('project=YKP and assignee='+ Assignee +
' and status not in ("Discarded") and updated > -7d ORDER BY issuekey, issuetype, status'):
#for SubIssue in jira.search_issues('project=YKP and "epic link"= ' + Issue.key +' and assignee='+ Assignee + ' and status not in ("Discarded") and updated > -7d ORDER BY issuekey, issuetype, status'): 

  print(">>>" + '{} | {} | {} | {}'.format(Issue.key, Issue.fields.issuetype, Issue.fields.status, Issue.fields.summary))

 

Thanks in Advance,

Maadi

2 answers

1 accepted

1 vote
Answer accepted
Mohamed Benziane
Community Champion
September 10, 2018

Hello, 

You can try this, it will return all comment of the issue with created date and updated date

https://yourdomain/rest/api/2/issue/{issueKey]/comment

 

Hope this helps

Regards 

Sunesh M S September 11, 2018

Thanks for the reply @Mohamed Benziane.

I am using JIRA library in Python and I am looking for the last comment entered for an issue. 

Let me know do you have any suggestion?

Mohamed Benziane
Community Champion
September 11, 2018

Hello @Sunesh M S,

 

Can you try this

comments_a = issue.fields.comment.comments
comments_b = jira.comments(issue) # comments_b == comments_a

I don't know if it will return you the comment date but you can test and let me know

 

Regards 

Sunesh M S September 13, 2018

@Mohamed Benziane

I have tried like below,

print(issue.fields.comment.comments)
print(jira.comment(IssueNo,'12252').body)

Output 

[<JIRA Comment: id='12252'>]
completed. unit testing done.

------

For another issue I got the below output, here this issue have multiple comments,

[<JIRA Comment: id='10920'>, <JIRA Comment: id='12321'>, <JIRA Comment: id='1402
2'>, <JIRA Comment: id='14053'>, <JIRA Comment: id='14083'>]

Let me know do you have any suggestion to get the MAX id from the above list.

[I tried MAX(listname), but not worked.]

Mohamed Benziane
Community Champion
September 13, 2018

Hi @Sunesh M S

 

I'm not expert but i tried this and it worked :

comment=jira.comments('issueKey')
a=int(0)
for i in comment:
if int(i.id)>a:
a=int(i.id)

 If it works for you you can go for a loop to get all last comment of your jira search.

 

Hope this helps

Sunesh M S September 13, 2018

@Mohamed Benziane, I am travelling today, So I can check this on next week only. Thanks for your comments. :)

Sunesh M S September 18, 2018

@Mohamed Benziane Thanks for you support. :)

 

comment=jira.comments(IssueNo)
a=int(0)
for i in comment:
     if int(i.id)>a:
          a=int(i.id)
print(jira.comment(IssueNo,a).body)

The above code will print the last comment (Text).

[Solved]

Mohamed Benziane
Community Champion
September 19, 2018

Hi @Sunesh M S

 

Glad i helped you. Feel free to accept my answer to help other people with same issue.

 

Regards

Deleted user July 23, 2019

Hi, Can you help in getting only the "External Comments"

Mohamed Benziane
Community Champion
July 24, 2019

Hello @[deleted] 

 

What do you meant by "External comments" ?

Mario
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2019

I think it's about get the "internal" parameter to know if the comment is for the user or just for the internal people. I've got the same issue. How can we get the "is_internal" parameter from the comments?

Mohamed Benziane
Community Champion
July 24, 2019
Mario
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2019

Yeah, I saw that, but I need to get that parameter with Python. Do you know how? Thanks

Mohamed Benziane
Community Champion
July 24, 2019

you will need to use the requests module in python.

 

here the url to use in you code : https://yourdomain/rest/servicedeskapi/request/{issueIdOrKey}/comment?public=false

 

you will have only the internal ticket thank to the public parameter

2 votes
Prakash P
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 24, 2021

Hi,

This will give you last comment, author name, time when its updated.

from jira import JIRA

jira 
= JIRA(auth=(uname, pwd), options={'server': 'https://jira.company.com/'})

output = {}

for result in jira.search_issues(your querystartAt=0, maxResults=100):
issue = jira.issue(result.key)        

for com in issue.fields.comment.comments:        
comment = com.body        
author = com.author.displayName        
time = com.created        

output['Jira No'] = issue       
output['Comment'] = comment    
output['author'] = author    
output['Time'] = time    

print(output)

Suggest an answer

Log in or Sign up to answer