Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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 

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?

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 

@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.]

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

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

@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]

Hi @Sunesh M S

 

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

 

Regards

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

Hello @Shaheel Luckoo 

 

What do you meant by "External comments" ?

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?

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

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

1 vote
Prakash P I'm New Here Feb 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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you