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

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:

Related

Azure DevOps REST Api Tags call (Repos > Tags)

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.

Get PR number from github templates

I create a new environtment for my backend for each commit, this environment have the PR number on the URL.
So I was hopping to create a template so that everytime someone creates a PR the text contains the URL for that enviroment, something like:
Im expecting to have a template pull_request_template.md like:
# How to test
Url: http://myurl-<PR-number>.myhost.com
And so everytime the PR
# How to test
Url: http://myurl-123.myhost.com
Where 123 is the PR number
As illustrated in here and in this discussion, you can have and use multiple template files (adding ?template=MY_PR_TEMPLATE.md), but not one file with variable content.
In your case, that wouldn't work.
What might work is a Pull Request Action, which would add a label and/or message, with said message being the URL computed automatically from the PR number.
That GitHub Action would help updating any PR with an additional information: the URL you want.

How to get the related JIRAISSUEKEY of given changeset ID using FishEye REST API request or EyeQL or Anyother possible way?

Inputs in Hand:-
ChangesetID (csid)
Repository Name
Branch Name
Requirement to find:
Get the JIRAISSUEKEY releated to given changesetid.
I was searching in EyeQL & FishEye REST API but couldn't find any possible ways to achieve my requirement.
Below URL helps to get the JIRAISSUEKEY of a changesetId.
http://hg.domain.com/log/<repo_name>/rev/branch(<branch_name>)%20and%20<csid>

Recommended way to list all repos/commits for a given user using github3.py

I'm building a GitHub application to pull commit information from our internal repos. I'm using the following code to iterate over all commits:
gh = login(token=gc.ACCESS_TOKEN)
for repo in gh.iter_repos():
for commit in repo.iter_commits():
print(commit.__dict__)
print(commit.additions)
print(commit.author)
print(commit.commit)
print(commit.committer)
print(commit.deletions)
print(commit.files)
print(commit.total)
The additions/deletions/total values are all coming back as 0, and the files attribute is always []. When I click on the url, I can see that this is not the case. I've verified through curl calls that the API indeed has record of these attributes.
Reading more in the documentation, it seems that iter_commits is deprecated in favor of iter_user_commits. Might this be the case why it is not returning all information about the commits? However, this method does not return any repositories for me when I use it like this:
gh = login(token=gc.ACCESS_TOKEN)
user = gh.user()
for repo in gh.iter_user_repos(user):
In short, I'm wondering what the recommended method is to get all commits for all the repositories a user has access to.
There's nothing wrong with iter_repos with a logged in GitHub instance.
In short here's what's happening (this is described in github3.py's documentation): When listing a resource from GitHub's API, not all of the attributes are actually returned. If you want all of the information, you have to request the information for each commit. In short your code should look like this:
gh = login(token=gc.ACCESS_TOKEN)
for repo in gh.iter_repos():
for commit in repo.iter_commits():
commit.refresh()
print(commit.additions)
print(commit.deletions)
# etc.

How do I determine branch name or id in webhook push event?

I was ecstatic when I got a simple webhook event listener working with GitHub push events on my Azure site, but I realize now I'm not seeing the branch name or id in the json payload (example here https://developer.github.com/v3/activity/events/types/#pushevent)
I thought maybe "tree_id" would be it, but it doesn't seem to be. I couldn't find any info about this in GitHubs's doc. Maybe I need to take one of the id's from the event and make another api call to get the branch? The reason for this is I want to be able to link GitHub push events with my app portfolio, which has branches defined. So, the push events are a way to see code change activity on my different apps -- and knowing the branch is therefore important.
I wrote to GitHub support, and they told me that the branch name is part of the "ref" element in the root of the json payload. When parsing from a JToken object called jsonBody, the C# looks like this
var branchName = jsonBody["ref"].ToString().Split('/').Last();
For example in "refs/heads/master", the branch name is "master"
You need to pay closer look on WEBHOOK response mainly. Here is the trick for JSONPATH ( at-least what I did with my jenkins job):
first read your webhook whole response with character "$". You can catch it is some variable like:
$webhookres='$'
echo $webhookres
Once you have response printed, copy it and paste here: https://jsonpath.com/
Now create your pattern. For example if you want branch name (if event is push):
$.ref
Once you have the branch name( it will have extra string with /), simply trim the unwanted part using awk or cut (linux commands).
You are not limited to this only. All you need to work on pattern and you can make use of this approach for getting other values as well like, author, git repo url etc. and then these can be used in your automation further.
even if you are using any other platform like Azure, JSONPATH concept will be same. because as suggested in accepted answer, "jsonBody["ref"]", it is equivalent to $.ref, as altogether you have to identify the PATTERN ( as here PATTERN is 'ref')