コード例 #1
0
        private static async Task <WorkItem> CreateVSTSWorkItem(string gitHubItemType, dynamic node)
        {
            // Common fields
            var fields = new Dictionary <string, object>()
            {
                {
                    "/fields/ContentDevelopment.GitHubItemType", gitHubItemType
                },
                {
                    "/fields/ContentDevelopment.GitHubURI", (string)node.html_url
                },
                {
                    "/fields/System.AreaPath", $"{Settings.VSTSProjectName}\\{Settings.VSTSRootAreaPath}"
                },
                {
                    "/fields/System.Description", (string)node.body
                },
                {
                    "/fields/System.Tags", "from-github"
                },
                {
                    "/fields/System.Title", (string)node.title
                },
                {
                    "/relations/-", new Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItemRelation()
                    {
                        Rel = "Hyperlink",
                        Url = (string)node.html_url
                    }
                }
            };

            using (var workItemClient = CreateClient())
            {
                var document = WorkItems.BuildCreateDocument(fields);
                var workitem = await workItemClient.CreateWorkItemAsync(
                    document, Settings.VSTSProjectName, Settings.GitHubWorkItemType)
                               .ConfigureAwait(false);

                _log.Info("VSTS workitem created with Id: " + workitem.Id);
                return(workitem);
            }
        }