Azure DevOps REST Api Tags call (Repos > Tags) - azure-devops

Is there a Repos Tags REST Api call to get the data from this page? (Repos > Tags)
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.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:
And the corresponding request I fetched from Edge(F12) is:
So the tag will be permanently deleted, it's not just moved to a sneaky archive.

Related

How to filter some repository URL list according tags via Azure Devops API?

Thanks for your attention.I am a new Azure Devops API user.
Now,I want to filter some repo url with a same tag.
According the api rule base on:
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/annotated-tags/get?view=azure-devops-rest-7.0&tabs=HTTP
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/annotatedtags/{objectId}?api-version=7.0
I can get {organization},{project},{repositoryId}, but I haven't find the API to get the tag's id:{objectId}.
objectId path True string ObjectId (Sha1Id) of tag to get.
Then I want to create a new tag with the output result to get the tag id for a workaround,base on:
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/annotated-tags/create?view=azure-devops-rest-7.0&tabs=HTTP
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/annotatedtags?api-version=7.0
However,there is no parameter to define the tag name.
Question: Is there any way to get the ADO repo's tag id with command if i have the tag name?
OR:
Is there any way to filter all repo URL with the same tag name via command?
Thanks for your patience and help.
Question: Is there any way to get the ADO repo's tag id with command
if i have the tag name?
You can use Refs – List to get tag objectid.
Find the tag here:

Copy pull request description to work item comments on Azure Devops

When PR is approved, there is message "Completing Pull Request 123 and the associated work items." added to associated work item's comments area.
Is there any way how to append PR description?
I have zapier webhook attached to comments and I wont to get PR message in another app.
When PR is approved, there is message "Completing Pull Request 123 and
the associated work items." added to associated work item's comments
area.
Based on this description, I guess you are attempting to append the PR description to work item comment while the Pull Request is completing, right?
Afraid to say that there's no such out-of-box feature can let you direct to use. But you can consider to run powershell scripts along with rest api in build pipeline to achieve such goal.
The logic of my suggestion is:
Step 1: Prepare environment.
Create one build pipeline, and make its trigger type as Continues Integration(CI). Only this, the pull request completing can trigger this pipeline processing, then do next job.
Step 2: Get the PR completing node id, then get corresponding Pull request ID by calling this PRs query api.
For the build which run by CI, there has one environment variable Build.SourceVersion can represents the merge node id which generated by Pull request complete.
POST https://dev.azure.com/{org}/{project name}/_apis/git/repositories/{repo name}/PullRequestQuery?api-version=6.0-preview.1
{
"queries": [
{
"type": 1,
"items": [
"$(Build.SourceVersion)" // Put the $(Build.SourceVersion) value here.
]
}
]
}
Then, in its response body, you will see there has one parameter pullRequestId which target to the Pull request this commit id associated with.
Step 3: Get detailed PR description and work item id by using the pull request id we get in step 2.
Get https://dev.azure.com/{org}/{project name}/_apis/git/repositories/{repo name}/pullrequests/{pull request id}?includeWorkItemRefs=true&api-version=5.1
Put the pull reqeust id we got from step 2 into this api, then you can see the description contents along with the work item id from its response body:
Step 4: Add this description contents to corresponding work item comment area.
POST https://dev.azure.com/{org}/{project name}/_apis/wit/workItems/{WorkItem Id}?api-version=5.1-preview.3
[
{
"op": "add",
"path": "/fields/System.History",
"Value": $(description) // put the description here
}
]
As I mentioned firstly, make sure this pipeline is triggered by CI. Then you will get the description contents be added into WIT comment once the Pull request is completing.

Obtain TFS GIT Commit Details From TFS Work Item Artifact Link

Is it possible to leverage TFS or TS REST api to obtain details for a GIT commit by leveraging the work item commit "ArtifiactLink" url?
So you want to get detail commit information based on a work item artifacts link (while the artifact link type contains commit).
You can achieve that with two REST API, detail steps as below:
1. Get the work item with full expanded
GET https://{instance}/DefaultCollection/_apis/wit/workitems/{id}?api-version1.0&$expand=all
For TFS2015, the format looks like:
GET http://tfsServer:8080/tfs/DefaultCollection/_apis/wit/workitems?ids={id}&$expand=all&api-version=1.0
For VSTS, the format looks like:
GET https://account.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=7&$expand=all&api-version=1.0
2. Get commit(s) and related repo(s) linked in the above work item
Search in the response of the step1 REST API, get the part which rel is ArtifactLink and the url start with vstfs:///Git/Commit. The URL format is
vstfs:///Git/Commit/{project ID}%2F{repo ID}%2F{commit ID}
Such as part of the REST API response as:
{
"rel": "ArtifactLink",
"url": "vstfs:///Git/Commit/b959f22b-eeb7-40dc-b37e-986377eaa86f%2F4cfde261-fec3-451c-9d41-a400ba816110%2Fb3c3c5b8718f403402be770cb3b5912df7c64dd6",
"attributes": {
"authorizedDate": "2017-09-26T03:14:03.98Z",
"id": 92,
"resourceCreatedDate": "2017-09-26T03:14:03.98Z",
"resourceModifiedDate": "2017-09-26T03:14:03.98Z",
"revisedDate": "9999-01-01T00:00:00Z",
"name": "Fixed in Commit"
}
}
The project ID is b959f22b-eeb7-40dc-b37e-986377eaa86f, the repo ID is 2F4cfde261-fec3-451c-9d41-a400ba816110 and the commit ID is b3c3c5b8718f403402be770cb3b5912df7c64dd6.
3. Get commit(s) details
Use the project ID, repo ID and commit ID you get in step2 to get a single commit:
GET https://{instance}/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version={version}
For TFS 2015, the format looks like:
GET http://tfsServer:8080/tfs/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version=1.0
For VSTS, the format looks like:
GET https://account.visualstudio.com/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version=1.0

How can I use github api to get all tags or releases for a project?

I would like to know how to use the github-api to get all the current releases or tags for a project. I have seen the documentation for tags in github-api but I don't see a way to list all tags or list all releases but only list a specific tag by :sha.
It's possible, but the documentation is perhaps not in the place you'd expect it to be.
http://developer.github.com/v3/git/refs/
You can also request a sub-namespace. For example, to get all the tag
references, you can call:
GET /repos/:owner/:repo/git/refs/tags
This morning I received an answer to this same question that I posted to the github support team. Not sure how I can attribute the answer correctly but here is their response.
Quote from Ivan Žužak of Github support team
You can get a list of all tags for a repository using this API call:
http://developer.github.com/v3/repos/#list-tags
So, for example, making the following cURL request will return the list of tags for the libgit2/libgit2 repository:
$ curl -v "https://api.github.com/repos/libgit2/libgit2/tags"
Note: for the releases specifically of a GitHub repo, you now have (since Sept. 25th, 2013), an api to list all the releases:
List releases for a repository
Users with push access to the repository will receive all releases (i.e., published releases and draft releases).
Users with pull access will receive published releases only.
GET /repos/:owner/:repo/releases
Response
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
"assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
"upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name}",
"id": 1,
"tag_name": "v1.0.0",
"target_commitish": "master",
"name": "v1.0.0",
"body": "Description of the release",
"draft": false,
"prerelease": false,
"created_at": "2013-02-27T19:35:32Z",
"published_at": "2013-02-27T19:35:32Z"
}
]
Get a single release
GET /repos/:owner/:repo/releases/:id
In v4, graphQL, you can use this query https://developer.github.com/v4/object/tag/
query {
repository(owner: "onmyway133", name: "Scale") {
refs(refPrefix: "refs/tags/", last: 2) {
edges {
node {
name
}
}
}
}
}
The API call to get all tags as JSON list is:
https://api.github.com/repos/{OWNER}/{REPO}/tags
Example: https://api.github.com/repos/alacritty/alacritty/tags
The response is sorted: more recent tags come first.
To get releases change /tags to /releases. And don't add a trailing slash / to the end.
This will list all your Releases (tags) on Github. Might need to tweek the grep part depending on your tag naming conventions:
curl -s 'https://github.com/username/reponame/tags/'|grep -o "$Version v[0-9].[0-9][0-9]"
If cutting-n-pasting the URL from the "clone repo" section, remember to chop the.git off at the end of the address when constructing above URL- HTH- Terrence Houlahan

How can I get a list of all pull requests for a repo through the github API?

I want to obtain a list of all pull requests on a repo through the github API.
I've followed the instructions at http://developer.github.com/v3/pulls/ but when I query /repos/:owner/:repo/pulls it's consistently returning fewer pull requests than displayed on the website.
For example, when I query the torvalds/linux repo I get 9 open pull requests (there are 14 on the website). If I add ?state=closed I get a different set of 11 closed pull requests (the website shows around 20).
Does anyone know where this discrepancy arises, and if there's any way to get a complete list of pull requests for a repo through the API?
You can get all pull requests (closed, opened, merged) through the variable state.
Just set state=all in the GET query, like this->
https://api.github.com/repos/:owner/:repo/pulls?state=all
For more info: check the Parameters table at https://developer.github.com/v3/pulls/#list-pull-requests
Edit: As per Tomáš Votruba's comment:
the default value for, "per_page=30". The maximum is per_page=100. To get more than 100 results, you need to call it multiple itmes: "&page=1", "&page=2"...
PyGithub (https://github.com/PyGithub/PyGithub), a Python library to access the GitHub API v3, enables you to get paginated resources.
For example,
g = Github(login_or_token=$YOUR_TOKEN, per_page=100)
r = g.get_repo($REPO_NUMBER)
for pull in r.get_pulls('all'):
# You can access pulls
See the documentation (http://pygithub.readthedocs.io/en/latest/index.html).
With Github's new official CLI (command line interface):
gh pr list --repo OWNER/REPO
which would produce something like:
Showing 2 of 2 pull requests in OWNER/REPO
#62 Doing something that-weird-branch-name
#58 My PR title wasnt-inspired-branch
See additional details and options and installation instructions.
There is a way to get a complete list and you're doing it. What are you using to communicate with the API? I suspect you may not be doing something correctly. For example (there are only 13 open pull requests currently) using my API wrapper (github3.py) I get all of the open pull requests. An example of how to do it without my wrapper in python is:
import requests
r = requests.get('https://api.github.com/repos/torvalds/linux/pulls')
len(r.json()) == 13
and I can also get that result (vaguely) in cURL by counting the results myself: curl https://api.github.com/repos/torvalds/linux/pulls.
If you, however, run into a repository with more than 25 (or 30) pull requests that's an entirely different issue but most certainly it is not what you're encountering now.
If you want to retrieve all pull requests (commits, comments, issues etc) you have to use pagination.
https://developer.github.com/v3/#pagination
The GET request "pulls" will only return open pull-requests.
If you want to get all pull-requests either you do set the parameter state to all, or you use issues.
Extra information
If you need other data from Github, such as issues, then you can identify pull-requests from issues, and you can then retrieve each pull-request no matter if it is closed or open. It will also give you a couple of more attributes (mergeable, merged, merge-commit-sha, nr of commits etc)
If an issue is a pull-request, then it will contain that attribute. Otherwise, it is just an issue.
From the API: https://developer.github.com/v3/pulls/#labels-assignees-and-milestones
"Every pull request is an issue, but not every issue is a pull request. For this reason, “shared” actions for both features, like manipulating assignees, labels and milestones, are provided within the Issues API."
Edit I just found that issues behaves similar to pull-requests, so one would need to do retrieve all by setting the state parameter to all
You can also use GraphQL API v4 to request all pull requests for a repo. It requests all the pull requests by default if you don't specify the states field :
{
repository(name: "material-ui", owner: "mui-org") {
pullRequests(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
totalCount
nodes {
title
state
author {
login
}
createdAt
}
}
}
}
Try it in the explorer
The search API shoul help: https://help.github.com/enterprise/2.2/user/articles/searching-issues/
q = repo:org/name is:pr ...
GitHub provides a "Link" header which specifies the previous, next and last URL to fetch the values.Eg, Link Header response,
<https://api.github.com/repos/:owner/:repo/pulls?state=all&page=2>; rel="next", <https://api.github.com/repos/:owner/:repo/pulls?state=all&page=15>; rel="last"
rel="next" suggests the next set of values.
Here's a snippet of Python code that retrieves information of all pull requests from a specific GitHub repository and parses it into a nice DataFrame:
import pandas as pd
organization = 'pvlib'
repository = 'pvlib-python'
state = 'all' # other options include 'closed' or 'open'
page = 1 # initialize page number to 1 (first page)
dfs = [] # create empty list to hold individual dataframes
# Note it is necessary to loop as each request retrieves maximum 30 entries
while True:
url = f"https://api.github.com/repos/{organization}/{repository}/pulls?" \
f"state={state}&page={page}"
dfi = pd.read_json(url)
if dfi.empty:
break
dfs.append(dfi) # add dataframe to list of dataframes
page += 1 # Advance onto the next page
df = pd.concat(dfs, axis='rows', ignore_index=True)
# Create a new column with usernames
df['username'] = pd.json_normalize(df['user'])['login']