示例#1
0
        public static async Task CreateOrUpdateWorkItemAsync <T>(this WorkItemTrackingHttpClient workItemTrackingHttpClient, T workitem, CancellationToken cancellationToken = default)
            where T : GenericWorkItem
        {
            if (workItemTrackingHttpClient == null)
            {
                throw new ArgumentNullException(nameof(workItemTrackingHttpClient));
            }
            if (workitem == null)
            {
                throw new ArgumentNullException(nameof(workitem));
            }


            var patchDocument = workitem.CreatePatchDocument();

            Task <WorkItem> task;

            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (workitem.Id.HasValue)
            {
                task = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workitem.Id.Value, null, null, null, cancellationToken);
            }
            else
            {
                task = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, workitem.Project, workitem.WorkItemType, null, null, null, cancellationToken);
            }
            var savedOrCreatedWorkItem = await task;

            workitem.CopyValuesFromWorkItem(savedOrCreatedWorkItem);
        }
示例#2
0
        public static async Task CreateWorkItemSpike()
        {
            var           BaseURL             = Configuration["BaseURL"];
            var           PAT                 = Configuration["AzureDevOpsPAT"];
            var           organizationURL     = BaseURL.Substring(0, BaseURL.LastIndexOf('/'));
            VssConnection connection          = new VssConnection(new Uri(organizationURL), new VssBasicCredential(string.Empty, PAT));
            WorkItemTrackingHttpClient client = connection.GetClient <WorkItemTrackingHttpClient>();

            JsonPatchDocument document = new JsonPatchDocument();

            document.Add(new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "This is the title of Work Item."
            });
            document.Add(new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Description",
                Value     = "This is <b>description</b>. "
            });

            await client.CreateWorkItemAsync(document, "DevSecOps", "Task");
        }
        public async Task <dynamic> PutAsync(string name, string data)
        {
            var doc = new JsonPatchDocument();

            doc.Add(new JsonPatchOperation
            {
                Operation = Operation.Add,
                Path      = $"/fields/{_settings.NameField}",
                Value     = name
            });

            doc.Add(new JsonPatchOperation
            {
                Operation = Operation.Add,
                Path      = $"/fields/{_settings.ValueField}",
                Value     = data
            });

            foreach (var item in _settings.AdditionalFields)
            {
                doc.Add(new JsonPatchOperation
                {
                    Operation = Operation.Add,
                    Path      = $"/fields/{item.Key}",
                    Value     = item.Value
                });
            }

            return(await _client.CreateWorkItemAsync(doc, _projectName, _settings.WorkItemType));
        }
示例#4
0
        static void Main(string[] args)
        {
            Uri            serverUrl   = new Uri(vstsUrl);
            VssCredentials credentials = new VssClientCredentials();

            credentials.Storage = new VssClientCredentialStorage();

            VssConnection connection = new VssConnection(serverUrl, credentials);

            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Tags",
                Value     = "tag1"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "Sample task  with tags"
            }
                );

            var newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, "MyAgile2", "Task").Result;
        }
示例#5
0
        public WorkItem CreateWorkItem(JsonPatchDocument patchDocument, GitHubPostViewModel vm)
        {
            string pat     = _options.Value.ADO_Pat;
            string org     = _options.Value.ADO_Org;
            string project = _options.Value.ADO_Project;
            string wit     = _options.Value.ADO_DefaultWIT;

            Uri baseUri = new Uri("https://dev.azure.com/" + org);

            VssCredentials clientCredentials = new VssCredentials(new VssBasicCredential("username", pat));
            VssConnection  connection        = new VssConnection(baseUri, clientCredentials);

            WorkItemTrackingHttpClient client = connection.GetClient <WorkItemTrackingHttpClient>();
            WorkItem result = null;

            try
            {
                result = client.CreateWorkItemAsync(patchDocument, project, wit).Result;
            }
            catch (Exception)
            {
                result = null;
            }
            finally
            {
                clientCredentials = null;
                connection        = null;
                client            = null;
            }

            return(result);
        }
示例#6
0
        private Task GetCreateWorkItemTask(WorkItemTrackingHttpClient client, WorkItem workItem, string project)
        {
            var newWorkItem = new JsonPatchDocument();

            var fieldsToCopy = new string[]
            {
                TITLE,
                "System.Description",
                "Microsoft.VSTS.Scheduling.RemainingWork"
            };

            foreach (var fieldName in fieldsToCopy)
            {
                var field = CreateWorkItemField(workItem, fieldName);
                if (field != null)
                {
                    newWorkItem.Add(field);
                }
            }

            var tags = CreateTags(workItem);

            if (tags != null)
            {
                newWorkItem.Add(tags);
            }

            return(client.CreateWorkItemAsync(newWorkItem, project, (string)workItem.Fields[TYPE]));
        }
        public static Task <WorkItem> CreateWorkItemUnrestrictedAsync(this WorkItemTrackingHttpClient source, TeamProject project, JsonPatchDocument document, string itemType, CancellationToken cancellationToken)
        {
            //Null values aren't allowed when creating a new item so remove any patches that are null
            document.RemoveAll(o => o.Value == null);

            return(source.CreateWorkItemAsync(document, project.Name, itemType, bypassRules: true, cancellationToken: cancellationToken));
        }
        public void AddWorkItem(ProductBacklog productBacklog, string projectName)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = productBacklog.Title
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Description",
                Value     = productBacklog.Description
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.State",
                Value     = productBacklog.State
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.Scheduling.OriginalEstimate",
                Value     = productBacklog.TimeAllocated
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.CreatedDate",
                Value     = productBacklog.CreatedDate
            }
                );


            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials))
            {
                WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, productBacklog.Type).Result;
                if (result != null)
                {
                    productBacklog.Id = result.Id;
                    _FrameworxProjectDatabaseContext.Add <ProductBacklog>(productBacklog);
                }
            }
        }
示例#9
0
        /// <summary>
        /// Create a new work item based on template
        /// </summary>
        /// <param name="projectName"></param>
        /// <param name="template"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        static WorkItem CreateWorkItemByTemplate(string projectName, WorkItemTemplate template, Dictionary <string, object> fields)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            foreach (var templateKey in template.Fields.Keys) //set default fields from template
            {
                if (!fields.ContainsKey(templateKey))         //exclude fields added by users
                {
                    patchDocument.Add(new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/" + templateKey,
                        Value     = template.Fields[templateKey]
                    });
                }
            }

            //add user fields
            foreach (var key in fields.Keys)
            {
                patchDocument.Add(new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/" + key,
                    Value     = fields[key]
                });
            }

            return(WitClient.CreateWorkItemAsync(patchDocument, projectName, template.WorkItemTypeName).Result);
        }
        public WorkItem CreateWorkItem(string projectName, string workItemTypeName, Dictionary <string, object> fields)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            foreach (var key in fields.Keys)
            {
                patchDocument.Add(new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/" + key,
                    Value     = fields[key]
                });
            }

            return(WitClient.CreateWorkItemAsync(patchDocument, projectName, workItemTypeName).Result);
        }
        private async Task <WorkItem> CreateChildTask(Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem parentPbi, string title)
        {
            var document = new JsonPatchDocument();

            document.Add(
                new JsonPatchOperation()
            {
                Path      = "/fields/System.Title",
                Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
                Value     = title
            });

            document.Add(
                new JsonPatchOperation()
            {
                Path      = "/relations/-",
                Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
                Value     = new
                {
                    rel = "System.LinkTypes.Hierarchy-Reverse",
                    url = parentPbi.Url
                }
                //https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/297
            });

            return(await witClient.CreateWorkItemAsync(document, projectId, "Task"));
        }
示例#12
0
        public static WorkItem CreateBug(string title, string stepsToReproduce, string description, List <string> filePathsToBeAttached = null)
        {
            var credentials = new VssBasicCredential(string.Empty, _personalAccessToken);

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = title,
            });

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.TCM.SystemInfo",
                Value     = description,
            });

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.TCM.ReproSteps",
                Value     = stepsToReproduce,
            });

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.Common.Priority",
                Value     = ConfigurationService.GetSection <AzureDevOpsBugReportingSettings>().DefaultPriority,
            });

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.Common.Severity",
                Value     = ConfigurationService.GetSection <AzureDevOpsBugReportingSettings>().DefaultSeverity,
            });

            try
            {
                using var httpClient = new WorkItemTrackingHttpClient(new Uri(_uri), credentials);
                var attachments = CreateAttachments(httpClient, filePathsToBeAttached);
                AddAttachmentRelationships(patchDocument, attachments);

                WorkItem result = httpClient.CreateWorkItemAsync(patchDocument, _project, "Bug").Result;
                return(result);
            }
            catch
            {
                return(null);
            }
        }
        public int Create <T>(T workItem) where T : AzureDevOpsWorkItem
        {
            var createdWorkItem = WorkItemTrackingHttpClient
                                  .CreateWorkItemAsync(workItem.ToJsonPatchDocument(), ProjectName, workItem.WorkItemType).Result;

            workItem.Id = createdWorkItem.Id.Value;

            if (workItem?.Comments != null)
            {
                // Add revisions for comments
                foreach (var comment in workItem?.Comments.OrderBy(m => m.OrderingId))
                {
                    Update(workItem.Id, "/fields/System.History", comment.Text);
                }
            }

            if (workItem?.Attachments != null)
            {
                foreach (var attachment in workItem?.Attachments.OrderBy(m => m.OrderingId))
                {
                    UploadAttachmentToWorkItem(workItem.Id, attachment);
                }
            }

            return(workItem.Id);
        }
示例#14
0
        public WorkItem CreateWorkItem(string title, string type)
        {
            // Construct the object containing field values required for the new work item
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = title
            }
                );

            // Get a client
            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            // Get the project to create the sample work item in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Create the new work item
            WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, type).Result;

            Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);

            return(newWorkItem);
        }
        public WorkItem CreateAndLinkToWorkItem(WorkItem itemToLinkTo, string title, string description = null, string projectName = Constants.SitefinityProjectName, string type = Constants.Task)
        {
            WorkItemTrackingHttpClient witClient = this.connection.GetClient <WorkItemTrackingHttpClient>();

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = $"/fields/{Constants.Title}",
                Value     = title
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = $"/fields/{Constants.Description}",
                Value     = description
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = $"/fields/{Constants.Iteration}",
                Value     = itemToLinkTo.Fields[Constants.Iteration]
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = $"/fields/{Constants.Area}",
                Value     = itemToLinkTo.Fields[Constants.Area]
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/relations/-",
                Value     = new
                {
                    rel = "System.LinkTypes.Hierarchy-Reverse",
                    itemToLinkTo.Url
                }
            }
                );

            WorkItem result = witClient.CreateWorkItemAsync(patchDocument, projectName, type).Result;

            return(result);
        }
        public async Task <bool> RaiseBugInBacklog(string twitchUsername, DevOpsBug bugInfo)
        {
            try
            {
                var jsonPatch = _createJsonPatchDocumentFromBugRequestCommand.Create(twitchUsername, bugInfo);

                await _workItemTrackingClient.CreateWorkItemAsync(jsonPatch, _configService.Get <string>("DevOpsProjectName"), "Bug");

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e,
                                 $"Could not raise bug: {twitchUsername}, {bugInfo.Title}, {bugInfo.ReproSteps}, {bugInfo.AcceptanceCriteria}, {bugInfo.SystemInfo}");
                return(false);
            }
        }
示例#17
0
        public TFSBug CreateBug(SNDevelopmentItem developmentItem, string teamProject)
        {
            TFSBug tfsBug = null;
            // Construct the object containing field values required for the new work item
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = developmentItem.Short_Description == null ? "No description in ServiceNow" : developmentItem.Short_Description
            });
            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/FET.SNDefect",
                Value     = developmentItem.Number
            }
                );
            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/FET.SNInternalId",
                Value     = developmentItem.SystemId
            }
                );


            string serverUrl = (string)configReader.GetValue("TFSServerUrl", typeof(string));
            //Initialise the connection to the TFS server
            VssConnection connection = new VssConnection(new Uri(serverUrl), new VssCredentials(new WindowsCredential(true)));

            using (WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>())
            {
                // Get the project to create the work item in
                TeamProjectReference projectReference = FindProject(connection, teamProject);

                if (projectReference != null)
                {
                    // Create the new work item
                    WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectReference.Id, "Bug").Result;

                    if (newWorkItem != null)
                    {
                        tfsBug = GetBugFromSNDevItem(developmentItem);
                    }
                }
            }
            return(tfsBug);
        }
示例#18
0
        public string CreateBug()
        {
            string project = _configuration.Project;

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            // add fields to your patch document
            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "Authorization Errors"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.TCM.ReproSteps",
                Value     = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.Common.Priority",
                Value     = "1"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/Microsoft.VSTS.Common.Severity",
                Value     = "2 - High"
            }
                );

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials))
            {
                // create the bug
                WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result;
            }

            patchDocument = null;

            return("success");
        }
        private static void CloneWorkItem(WorkItemTrackingHttpClient witClient, int wiIdToClone, string NewTeamProject = "", bool CopyLink = false)
        {
            WorkItem wiToClone = (CopyLink) ? witClient.GetWorkItemAsync(wiIdToClone, expand: WorkItemExpand.Relations).Result
                : witClient.GetWorkItemAsync(wiIdToClone).Result;

            string teamProjectName = (NewTeamProject != "") ? NewTeamProject : wiToClone.Fields["System.TeamProject"].ToString();
            string wiType          = wiToClone.Fields["System.WorkItemType"].ToString();

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            foreach (var key in wiToClone.Fields.Keys) //copy fields
            {
                if (!systemFields.Contains(key) && !customFields.Contains(key))
                {
                    if (NewTeamProject == "" ||
                        (NewTeamProject != "" && key != "System.AreaPath" && key != "System.IterationPath")) //do not copy area and iteration into another project
                    {
                        patchDocument.Add(new JsonPatchOperation()
                        {
                            Operation = Operation.Add,
                            Path      = "/fields/" + key,
                            Value     = wiToClone.Fields[key]
                        });
                    }
                }
            }

            if (CopyLink) //copy links
            {
                foreach (var link in wiToClone.Relations)
                {
                    if (link.Rel != ChildRefStr)
                    {
                        patchDocument.Add(new JsonPatchOperation()
                        {
                            Operation = Operation.Add,
                            Path      = "/relations/-",
                            Value     = new
                            {
                                rel = link.Rel,
                                url = link.Url
                            }
                        });
                    }
                }
            }

            WorkItem clonedWi = witClient.CreateWorkItemAsync(patchDocument, teamProjectName, wiType).Result;

            Console.WriteLine("New work item: " + clonedWi.Id);
        }
示例#20
0
        static void Main(string[] args)
        {
            VssConnection connection = new VssConnection(new Uri(Settings.Default.VstsURL), new VssBasicCredential(string.Empty, Settings.Default.VstsPAT));

            using (WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>())
            {
                Jira jiraConn = Jira.CreateRestClient(Settings.Default.JiraURL, Settings.Default.JiraUser, Settings.Default.JiraPassword);

                var issues = (from i in jiraConn.Issues.Queryable
                              orderby i.Created
                              select i).ToList();

                foreach (var issue in issues)
                {
                    JsonPatchDocument document = new JsonPatchDocument();
                    string            title    = $"{issue.Key} - {issue.Summary}";
                    title = title.Substring(0, Math.Min(title.Length, 128));
                    document.Add(new JsonPatchOperation {
                        Path = "/fields/System.Title", Value = title
                    });
                    if (issue.Description != null)
                    {
                        document.Add(new JsonPatchOperation {
                            Path = "/fields/System.Description", Value = issue.Description
                        });
                    }

                    JiraUser user = jiraConn.Users.SearchUsersAsync(issue.Reporter).Result.FirstOrDefault();
                    if (user != null)
                    {
                        document.Add(new JsonPatchOperation {
                            Path = "/fields/System.CreatedBy", Value = user.Email
                        });
                    }

                    var x = issue.CustomFields["Story points"]?.Values.FirstOrDefault() ?? "";
                    if (x != "")
                    {
                        document.Add(new JsonPatchOperation {
                            Path = "/fields/Microsoft.VSTS.Scheduling.StoryPoints", Value = x
                        });
                    }

                    const string project      = "Parrish Shoes";
                    const string workItemType = "User Story";
                    var          workItem     = witClient.CreateWorkItemAsync(document, project, workItemType).Result;
                }
            }
        }
        public async Task MigrateAllTicketsFromAProjectToAzureDevopServer(string projectName, List <Ticket> tickets)
        {
            var counter = 0;

            foreach (var ticket in tickets)
            {
                try
                {
                    var patchDocument = CreateJsonPatchDocument(ticket);

                    await SetAreaForTicket(patchDocument, projectName);
                    await SetIterationForTicket(ticket, patchDocument, projectName);

                    SetTicketStatus(ticket, patchDocument);

                    string workItemType = "Requirement";
                    if (ticket.CaseType == CaseTypeEnum.ServiceRequest)
                    {
                        workItemType = "Feature";
                    }

                    WorkItem workItem = await _workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, workItemType, null, true);

                    Console.WriteLine($"{counter} Bug Successfully Created: Requirement #{workItem.Id}");
                    counter++;

                    await CreateMessagesOnATicket(ticket, workItem);
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Error creating Requirement: {0}", ex.InnerException.Message);
                    //_logger.LogInformation(ex.InnerException.Message);
                }
            }
        }
示例#22
0
        /// <summary>
        /// Create a work item
        /// </summary>
        /// <param name="ProjectName"></param>
        /// <param name="WorkItemTypeName"></param>
        /// <param name="Fields"></param>
        /// <returns></returns>
        static Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem CreateWorkItem(string ProjectName, string WorkItemTypeName, Dictionary <string, object> Fields)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            foreach (var key in Fields.Keys)
            {
                patchDocument.Add(new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/" + key,
                    Value     = Fields[key]
                });
            }

            return(WitClient.CreateWorkItemAsync(patchDocument, ProjectName, WorkItemTypeName).Result);
        }
示例#23
0
        public static async Task <string> CreateWIinDevops(string WItitle, string projectName, string WIType)
        {
            var PAT = "7awtul6zkle7untncpxvqq25yvwgz6fb2qr6stxozzm6qr7swxca";


            var credentials = new VssBasicCredential(string.Empty, PAT);

            var operations = new JsonPatchDocument();

            AddPatch(operations, "/fields/System.Title", WItitle);
            AddPatch(operations, "/fields/System.Description", WItitle);
            var witClient =
                new WorkItemTrackingHttpClient(new Uri("https://dev.azure.com/adfd365"), credentials);
            var result = await witClient.CreateWorkItemAsync(operations, projectName, WIType);

            return(result.Id.ToString());
        }
示例#24
0
        public static WorkItem CreateBugInVSO(IWebDriver driver, Fields fields)
        {
            try
            {
                PathOfAttachment = ScreenShotCapture.CaptureScreenShotOfCurrentBrowser(driver, fields.PathOfFile);
                ListParams.AddRange(GetAllField(fields));
                Uri                 uri = new Uri(_uri);
                string              personalAccessToken = _personalAccessToken;
                string              project             = _project;
                VssBasicCredential  credentials         = new VssBasicCredential("", _personalAccessToken);
                AttachmentReference attachment          = UploadAttachment(uri, credentials);
                ListParams.Add(new Params()
                {
                    Path  = "/relations/-",
                    Value = new
                    {
                        rel        = "AttachedFile",
                        url        = attachment.Url,
                        attributes = new { comment = fields.Comments }
                    }
                });
                JsonPatchDocument patchDocument = new JsonPatchDocument();
                //add fields and their values to your patch document
                foreach (var item in ListParams)
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = item.Path,
                        Value     = item.Value,
                    }
                        );
                }
                VssConnection connection = new VssConnection(uri, credentials);
                WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>();

                WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result;
                return(result);
            }
            catch (AggregateException ex)
            {
                Log.Logger.Error("Error occurred while Creating bug in VSO" + ex);
                return(null);
            }
        }
示例#25
0
        // WIT Operations
        /// <summary>
        /// Bypass rules incase there are required fields are not provided
        /// </summary>
        /// <param name="document">// Construct the object containing field values required for the new work item</param>
        /// <param name="WITypeName">Work Item Type Name: Learning Path / Module / Unit</param>
        /// <returns></returns>
        public WorkItem CreateWIT(JsonPatchDocument document, string WITypeName)
        {
            WorkItemTrackingHttpClient witHttpClient = this.Connection.GetClient <WorkItemTrackingHttpClient>();

            try
            {
                WorkItem result = witHttpClient.CreateWorkItemAsync(document, this.Project, WITypeName, bypassRules: true).Result;
                Console.WriteLine("{0} Successfully Created: # {1}", WITypeName, result.Id);
                WriteLog.WriteLogLine("{0} Successfully Created: # {1}", WITypeName, result.Id);
                return(result);
            }
            catch (AggregateException ex)
            {
                Console.WriteLine("Error creating {0}: {1}", WITypeName, ex.InnerException.Message);
                WriteLog.WriteLogLine("Error creating {0}: {1}", WITypeName, ex.InnerException.Message);
                return(null);
            }
        }
        internal static WorkItem SubmitWorkItem(Dictionary <string, object> Fields, int WiId = 0, string TeamProjectName = "", string WorkItemTypeName = "")
        {
            try
            {
                JsonPatchDocument patchDocument = new JsonPatchDocument();

                foreach (var key in Fields.Keys)
                {
                    if (key.StartsWith("<Parent>"))
                    {
                        patchDocument.Add(new JsonPatchOperation()
                        {
                            Operation = Operation.Add,
                            Path      = "/relations/-",
                            Value     = Fields[key]
                        });
                    }
                    else
                    {
                        patchDocument.Add(new JsonPatchOperation()
                        {
                            Operation = Operation.Add,
                            Path      = "/fields/" + key,
                            Value     = Fields[key]
                        });
                    }
                }

                if (WiId == 0)
                {
                    return(WitClient.CreateWorkItemAsync(patchDocument, TeamProjectName, WorkItemTypeName).Result);
                }

                return(WitClient.UpdateWorkItemAsync(patchDocument, WiId).Result);
            }
            catch (Exception ex)
            {
                Connected = false;
                string message = ex.Message + ((ex.InnerException != null) ? "\n" + ex.InnerException.Message : "");
                Exceptions += message;

                return(null);
            }
        }
示例#27
0
        public WorkItem BypassRulesOnCreate()
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "JavaScript implementation for Microsoft Account"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.CreatedDate",
                Value     = "6/1/2016"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.CreatedBy",
                Value     = "Art VanDelay"
            }
                );

            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            // Get the project to create the sample work item in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Name, "Task", bypassRules: true).Result;



            return(result);
        }
示例#28
0
        public WorkItem CreateWorkItem(string projectName)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "JavaScript implementation for Microsoft Account"
            }
                );

            VssConnection connection = new VssConnection(_uri, _credentials);
            WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>();
            WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result;

            return(result);
        }
示例#29
0
        /// <summary>
        /// Create or update a work item
        /// </summary>
        /// <param name="Fields"></param>
        /// <param name="WIId"></param>
        /// <param name="TeamProjectName"></param>
        /// <param name="WorkItemTypeName"></param>
        /// <returns></returns>
        static WorkItem SubmitWorkItem(List <WiField> Fields, int WIId = 0, string TeamProjectName = "", string WorkItemTypeName = "")
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            foreach (var field in Fields)
            {
                patchDocument.Add(new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = (field.FieldName.StartsWith(RelConstants.LinkKeyForDict)) ? "/relations/-" : "/fields/" + field.FieldName,
                    Value     = field.FiledValue
                });
            }

            if (WIId == 0)
            {
                return(WitClient.CreateWorkItemAsync(patchDocument, TeamProjectName, WorkItemTypeName).Result); // create new work item
            }
            return(WitClient.UpdateWorkItemAsync(patchDocument, WIId).Result);                                  // return updated work item
        }
示例#30
0
        public WorkItem CreateWorkItem()
        {
            // Construct the object containing field values required for the new work item
            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.Title",
                Value     = "Sample task 1"
            }
                );

            //patchDocument.Add(
            //    new JsonPatchOperation()
            //    {
            //        Operation = Operation.Add,
            //        Path = "/fields/System.IterationPath",
            //        Value = "Test Project\\Iteration 1"
            //    }
            //);

            // Get a client
            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            // Get the project to create the sample work item in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Create the new work item
            WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result;

            Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);

            // Save this newly created for later samples
            Context.SetValue <WorkItem>("$newWorkItem", newWorkItem);

            return(newWorkItem);
        }