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

DELETE request for stash tag

Hi, 

I am using python requests library to work with stash REST API. With POST request I have no problem to create a new tag on specified commit:

 

#!/usr/bin/python3.5

import requests

url = '{}/rest/api/1.0/projects/{}/repos/{}/tags'.format(url, project_name, repo_name)

data = {'force': 'false',
        'message': 'Test tag',
	'name': '1.0',
	'startPoint': 'ffffff',
	'type': 'LIGHTWEIGHT'}

headers = {'Content-Type': 'application/json',
           'X-Atlassian-Token': 'no-check'}

r = requests.post(url, data=data, header=headers)

this gives response 200 and tag 1.0 is created at commit 'ffffff'

 

<stash base url>/rest/api/1.0/projects/<project>/repos/<repo>/tags

However if I try to follow https://developer.atlassian.com/static/rest/stash/3.11.6/stash-scm-git-rest.html and make DELETE request:

 

url = '{}/rest/api/1.0/projects/{}/repos/{}/tags/{}'.format(url, project_name, repo_name, tag)  # where tag is '1.0'

r = requests.delete(url)

I get 404 (not existing) response, and not surprisingly I can't go to url:

 

 

<stash base url>/rest/api/1.0/projects/<project>/repos/<repo>/tags/1.0

Even though tag I created is visible in json at:

<stash base url>/rest/api/1.0/projects/<project>/repos/<repo>/tags

So the question is really - what is the correct syntax to access and delete a single tag?

Best Regards,

Majus

 

 

1 answer

1 accepted

1 vote
Answer accepted
Jeff Thomas Atlassian Team May 02, 2017

Hi Majus,

Looking at the REST documentation you linked, it looks like the endpoint you should be hitting is /rest/git/1.0, not /rest/api/1.0:

url = '{}/rest/git/1.0/projects/{}/repos/{}/tags/{}'.format(url, project_name, repo_name, tag)  # where tag is '1.0'

Can you try updating the URL and see if that resolves the issue?

Cheers,
Jeff

Hi Jeff,

Thank you for answer. This is correct and it was my mistake to use api instead of git in url. However, this change did not resolve problem fully.

I added a new tag using '/rest/git/1.0/projects/{projectKey}/repos/{repositorySlug}/tags' (with correct git instead of api) as a target url, using the same method as described in original question. Subsequently I removed the tag using request.delete() with git instead of api (also as above). It looked allright (201 response for post and 204 for delete), the tag disappeared from stash rest (and could not be fetched using git from CLI).

But surprisingly the tag was still visible in the GUI

tags.jpg

even though it did not exist in git at all! After this, I could overwrite this tag in GUI by making another post request, resulting in new tag and changed tag in GUI.

To the contrary, if I tried to overwrite this tag, before actually deleting it with a request, I got 409 (Confict) response, as could be expected. I got the same behaviour with python requests and curl, i.e. the tag could be successfully deleted from git, but it would remain visible in gui.

This is very baffling for me.

Moreover, only way I have found to delete this hanging tag, was to actually make new tag for the same commit using git CLI:

git tag -a TEST_LATEST_SUCCESSFUL fca6f1
git push --tags

and then explicitly delete it:

git push origin --delete TEST_LATEST_SUCCESSFUL

after that the tag dissappeared from GUI.

Can you try to reproduce this behaviour and tell me, if this issue happens only with me, or is it general Bitbucket problem?

Kind regards,

Majus Misiak

Jeff Thomas Atlassian Team May 04, 2017

Hi Majus,

I'm not able to reproduce what you're seeing at the moment. When I delete a tag via the REST API and refresh the commits page in the UI, the tag no longer appears. Which version are you running? 

I did my testing on Bitbucket Server 4.14.4.

Hi Jeff,

We are using Bitbucket v4.5.2 (1ec1147), so this might be issue related to older version. I will try to reproduce this error with latest Bitbucket version and if it reoccurs I will update this question.

Regardless of that, I accept your first answer as correct.

Thank you for help :)

Majus Misiak

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Atlassian supported Jenkins integration for Bitbucket Server

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...

955 views 1 17
Read article

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