Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

azure devops - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...