Can I set custom github transforming/formatting of branch name to pull request title? - github

At this moment github during creating PR proposes title generated from branch name. This example branch name - feature/JIRA-1234-my-name-of-branch - would be transformed to:
"feature jira 1234 my name of branch". Can I change this transforming to sth like "feature(JIRA-1234): My name of branch"?

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:

How do I get the label added_at in a PR for a repo?

I am trying to derive some metrics from the github, for which I have created few labels in my repositories and would want to track when that is added to the PR.
I am using the below API to get the PR details but I am able to see what are all the labels have been added to the PR but unable to get the time stamp of it , How do I get the label added_at time from the github APIs ?
API route - https://api.github.com/repos/<org>/<repo>/pulls?state=closed&page=%s&per_page=100
Label section of the API reponse :
{
"id":1234,
"node_id":"1234",
"url":"https://api.github.com/repos/<org>/<repo>/labels/enhancement",
"name":"enhancement",
"color":"a2eeef",
"default":true,
"description":"New feature or request"
}

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.

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 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')