Reputation: 10401
I want to create a push using TFS git client libraries that contains the specified workitems.
The code is basically:
public static async Task<GitPush> CreatePush(
this GitHttpClient git,
GitRepository repo,
GitRefUpdate branchUpdateRef,
GitChange change,
String comment,
IEnumerable<Int32> workitems = null)
{
workitems = (workitems ?? Enumerable.Empty<Int32>()).ToList();
var commit = new GitCommitRef
{
Comment = comment,
Changes = new[]
{
change
},
WorkItems = workitems
.Select(wi => new ResourceRef
{
Id = wi.ToString()
// Perhaps one should also set an URL of some kind
})
.ToList()
};
var push = new GitPush
{
Commits = new[]
{
commit
},
RefUpdates = new[]
{
branchUpdateRef
},
Repository = repo
};
return await git.CreatePushAsync(
push,
project: repo.ProjectReference.Id,
repositoryId: repo.Id);
}
The push is created successfully, though there are no workitem links on the created commit.
I have tried
GitCommitRef.WorkItems
ResourceRef
for commits that have related workitems.But to no avail.
I actually can achieve the desired final result by
$"#{workitemId}"
to the commit comment stringStill, both of those solutions have minor drawbacks(1 - changing commit message, 2 - possible race condition with CI and etc.) that I'd prefer to avoid.
Basically, is there a way to way to create GitPush
with associated workitems in a single operation, or do I have to use the aforementioned workarounds?
Upvotes: 0
Views: 470
Reputation: 29976
No, there isn't any way to achieve this. Even when you create a commit/push from TFS Web UI, TFS still create the commit/push first and then update the work item to link to the push.
Upvotes: 1