Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Deleting comment on pull-request fails

BRIAN CARLSON July 30, 2022

I am using a Jenkins groovy script using Curl commands to interact with Stash/Bitbucket.

I can successfully grab all the activity data as a JSON object using the /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/activities

as recommended here:

https://community.atlassian.com/t5/Answers-Developer-Questions/Reading-pull-request-comments-via-REST-API-fails/qaq-p/523952 

{"size":25, "limit":25, "isLastPage":false, "values": [{"id":185562, LOTS OF INFO},{"id": #### .....}}
If I iterate over the values and filter on objects containing "comment" I can parse the following info.
comment_obj_keys = [id, createdDate, user, action, commentAction, comment]
comment_obj_keys.getClass() = class java.util.LinkedHashSet

if comment_obj_keys.contains("comment")

id = 185562
createDate = null
user = [REMOVED]
action = COMMENTED
commentAction = ADDED
comment = [ properties:[repositoryId:1794],
            id:16564, version:0,
            text:Meaninful results of Jenkins build,
            author:[REMOVED],
            createdDate:1659127730708,
            updatedDate:1659127730708,
            comments:[],
            tasks:[],
            severity:NORMAL,
            state:OPEN,
            permittedOperations:[editable:true, transitionable:true, deletable:true]]
According to everything I've read.  I should be able to use the id=166564 to access the comment with the goal of ultimately deleting it.  If I put the url in my brower I can see the comment.
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/16564
{"properties":{"repositoryId":1794},
 "id":16564,
 "version":0,
 "text":"Meaninful results of Jenkins build",
 "author":REMOVED,
 "createdDate":1659071192164,
 "updatedDate":1659071192164,
 "comments":[],
 "tasks":[],
 "severity":"NORMAL",
 "state":"OPEN",
 "permittedOperations":{"editable":false,
"transitionable":true,
"deletable":false}}
FYI I'm making (and trying to delete) the comment from Jenkins with the same bitbucket token.  And I'm going to the link for the above results 
However, when I try to delete the comment (projectKey, repositorySlug, and pullRequestId are replaced with the actual values):
curlCmd = "curl -s --insecure  -X DELETE -H 'Authorization: REMOVED TOKEN INFO' -H 'X-Atlassian-Token: no-check' https:///rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/16564"
{"errors":[{"context":null,"message":"You are attempting to modify a comment based on out-of-date information.", "exceptionName":"com.atlassian.bitbucket.comment.CommentOutOfDateException","currentVersion":0,"expectedVersion":-1}]}
adding:  comments/16564?0 yields the same result
adding:  comments/16564?-1 yields the same result
adding:  comments/16564/?-1 yields the same result
Any ideas what the issue might be?
Thanks!

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events