1
votes

Is there a Repos Tags REST Api call to get the data from this page? (Repos > Tags)

enter image description here

It would be awesome if it also includes CREATE, PATCH and DELETE.

The tab it self use https://dev.azure.com/{organization}/_git/{repo}/tags?__rt=fps&__ver=2 which I interpret as a bad sign.


EDIT 1: Create a Tag

Create: the Create Tag button use: Annotated Tags

So what is missing in this REST Api call is a LIST to get the {objectId} of the elements.


EDIT 2: List & Delete Tags

List: To list all Tags objectId, I found out that you can use Refs - List

Delete: I think this call is complete undocumented. But you can comprehend that the TFS use the following payload to do this job:

var json = {
    name: `refs/tags/${xName}`,
    newObjectId: '0000000000000000000000000000000000000000',
    oldObjectId: xObjectId
};
var payload = [json];

Post this payload to https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=5.1


EDIT 3: behavior on git client side

The only way I found to update the git tags on client side is here:

git tag -l | xargs git tag -d
git fetch --tags
1

1 Answers

2
votes

1.To create Tags: Create/Get tag apis

Create tag:

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/annotatedtags?api-version=6.0-preview.1

Get tag:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/annotatedtags/{objectId}?api-version=6.0-preview.1

2.To list Tags: We don't have "Annotated Tags-List", but we have Refs-tags which does similar job. (Hint from Mar Tin, thanks to him!)

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?filter=tags/&api-version=6.0-preview.1

3.To delete the tag(Fetch it from F12):

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{RepoName}/refs?api-version=5.1

Request Body(Don't forget the [ and ],it's necessary when testing in PostMan):

 [{
    "name": "refs/tags/{TagName}",
    "newObjectId": "0000000000000000000000000000000000000000",
    "oldObjectId": "{OldObjectID}"
 }]

Note: All the info about ObjectID can be fetched via Refs-tags api in tip2.

For your question about whether the tag is really deleted or is it only moved to a sneaky archive.

You're see this when trying to delete the Tag via the Delete tag button in web portal:

enter image description here

And the corresponding request I fetched from Edge(F12) is:

enter image description here

So the tag will be permanently deleted, it's not just moved to a sneaky archive.