зеркало из
1
0
Форкнуть 0

updated code to link to a commit or pr (#136)

#135
This commit is contained in:
Dan Hellem 2018-05-30 06:24:08 -07:00 коммит произвёл GitHub
Родитель 6e1259780a
Коммит 84bb486ab1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 65 добавлений и 4 удалений

Просмотреть файл

@ -1,4 +1,5 @@
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.WebApi;
@ -846,10 +847,66 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
return result;
}
public WorkItem UpdateWorkItemAddCommitLink()
public WorkItem UpdateWorkItemLinkToPullRequest()
{
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3
VssConnection connection = Context.Connection;
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
//you will need to edit this line and enter a legit pull request id
var pullRequest = gitClient.GetPullRequestByIdAsync(999).Result;
var pullRequestUri = pullRequest.ArtifactId;
JsonPatchDocument patchDocument = new JsonPatchDocument();
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Test,
Path = "/rev",
Value = "3"
}
);
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new
{
rel = "ArtifactLink",
url = pullRequestUri,
attributes = new {
comment = "Fixed in Commit",
name = "pull request"
}
}
}
);
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
return result;
}
public WorkItem UpdateWorkItemLinkToCommit()
{
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
System.Guid repositoryId = new Guid("2f3d611a-f012-4b39-b157-8db63f380226");
string commitId = "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4";
VssConnection connection = Context.Connection;
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
//you will need to edit this line and enter a legit repo id and commit id
//these are samples and will not work
var commit = gitClient.GetCommitAsync(commitId, repositoryId).Result;
var commitUri = commit.Url;
JsonPatchDocument patchDocument = new JsonPatchDocument();
@ -871,12 +928,16 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
{
rel = "ArtifactLink",
url = commitUri,
attributes = new { comment = "Fixed in Commit" }
attributes = new
{
comment = "Fixed in Commit",
name = "commit"
}
}
}
);
VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;