public string CreateIssue(Issue issue)
        {
            if (!_connection.IsAuthenticated)
            {
                throw new InvalidRequestException(Language.YouTrackClient_CreateIssue_Not_Logged_In);
            }

            try
            {
                dynamic newIssueMessage = new ExpandoObject();

                newIssueMessage.project = issue.ProjectShortName;
                newIssueMessage.description = issue.Description;
                newIssueMessage.summary = issue.Summary;
                newIssueMessage.assignee = issue.Assignee;

                var response = _connection.Post<dynamic>("issue", newIssueMessage, HttpContentTypes.ApplicationJson);

                return response.id;

            }
            catch (HttpException httpException)
            {
                throw new InvalidRequestException(httpException.StatusDescription, httpException);
            }
        }
        Issue ConvertFromFields(Field[] source)
        {
            var issue = new Issue();

            PropertyInfo[] properties = typeof (Issue).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo property in properties)
            {
                property.SetValue(issue, GetValueByName(property.Name, source), null);
            }

            return issue;
        }
        Issue ConvertFromFields(Hashtable fields)
        {
            var issue = new Issue();

            PropertyInfo[] properties = typeof (Issue).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo property in properties)
            {
                if (String.Compare(property.Name, "Links") == 0 && fields["Links"] != null)
                {
                    issue.Links = ConvertLinks(fields["Links"]);

                } else
                {
                    property.SetValue(issue, Convert.ChangeType(fields[property.Name], property.PropertyType), null);
                }
            }
            return issue;
        }
        public ActionResult New(NewIssueModel model)
        {
            if (ModelState.IsValid)
            {

                var issueManagement = new IssueManagement(UserSession.Connection);

                var issue = new Issue()
                              {
                                  Description = model.Description,
                                  ProjectShortName = model.Project,
                                  Summary = model.Summary,
                                  Type = model.Type,
                                  ReporterName = UserSession.Username

                              };
                issueManagement.CreateIssue(issue);

                return RedirectToAction("Index", "Home");
            }
            return View(model);
        }
        Issue ConvertFromFields(Hashtable fields)
        {
            var issue = new Issue();

            PropertyInfo[] properties = typeof (Issue).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo property in properties)
            {
                if (String.Compare(property.Name, "CustomFields") != 0)
                {
                    if (String.Compare(property.Name, "Links") == 0 && fields["Links"] != null)
                    {
                        issue.Links = ConvertLinks(fields["Links"]);
                    } else
                    {
                        // Special case. Assignee is Assignee on single and AssigneeName on multiple
                        if (String.Compare(property.Name, "AssigneeName") == 0)
                        {
                            if (fields["Assignee"] != null)
                            {
                                property.SetValue(issue, Convert.ChangeType(fields["Assignee"], property.PropertyType), null);
                            } else if (fields["AssigneeName"] != null)
                            {
                                property.SetValue(issue, Convert.ChangeType(fields["AssigneeName"], property.PropertyType), null);

                            }
                        } else
                        {
                            property.SetValue(issue, Convert.ChangeType(fields[property.Name], property.PropertyType), null);
                        }
                    }
                }
            }

            return issue;
        }
Exemple #6
0
        protected override void ProcessRecord()
        {
            if (!Force)
            {
                var similarIssues =
                    IssueManagement.GetIssuesBySearch(string.Format("project: {0} \"{1}\" \"{2}\"", ProjectShortName, Summary, Description));

                // TODO: Fix this once issues work again with dynamic type
                //var issueList = from si in similarIssues
                //                select new {IssueId = si.Id, Summary = si.Summary, Description = si.Description};

                //if (issueList.Count() > 0)
                //{
                //    WriteWarning("Found similar issues. If you still want to create it, use -Force=true");
                //    WriteObject(issueList);

                //    return;
                //}
            }

            dynamic newIssue = new Issue();

            newIssue.Summary = Summary;
            newIssue.Description = Description;
            newIssue.Priority = new[] {Priority};
            newIssue.ProjectShortName = ProjectShortName;
            newIssue.ReporterName = Connection.GetCurrentAuthenticatedUser().Username;
            newIssue.State = "Submitted";
            newIssue.Type = Type;
            newIssue.Subsystem = Subsystem;

            var id = IssueManagement.CreateIssue(newIssue);

            WriteObject(string.Format("Issue Created with id: {0}", id));
        }
        public string CreateIssue(Issue issue)
        {
            if (!_connection.IsAuthenticated)
            {
                throw new InvalidRequestException(Language.YouTrackClient_CreateIssue_Not_Logged_In);
            }

            try
            {
                var fieldList = issue.ToExpandoObject();

                var response = _connection.Post("issue", fieldList, HttpContentTypes.ApplicationJson);

                var customFields = fieldList.Where(field => !PresetFields.Contains(field.Key.ToLower())).ToDictionary(field => field.Key, field => field.Value);

                foreach (var customField in customFields)
                {
                    ApplyCommand(response.id, string.Format("{0} {1}", customField.Key, customField.Value), "Applying custom field");
                }
                return response.id;
            }
            catch (HttpException httpException)
            {
                throw new InvalidRequestException(httpException.StatusDescription, httpException);
            }
        }
 private Issue BuildIssue(Error error)
 {
     dynamic issue = new Issue();
     issue.summary = error.Message;
     issue.description = BuildDescription(error);
     issue.project = _config.Project;
     issue.type = "Exception";
     return issue;
 }
Exemple #9
0
 private static Task SetTag(this IIssuesService issuesService, Issue issue, string tagForHotIssues)
 {
     return(issuesService.ApplyCommand(issue.Id, $"tag {tagForHotIssues}", disableNotifications: true));
 }
Exemple #10
0
 private static Task RemoveTag(this IIssuesService issuesService, Issue issue, string tagForHotIssues, bool disableNotifications = true)
 {
     return(issuesService.ApplyCommand(issue.Id, $"remove tag {tagForHotIssues}", disableNotifications: disableNotifications));
 }
        protected override void ProcessRecord()
        {
            if (!Force)
            {
                var similarIssues =
                    IssueManagement.GetIssuesBySearch(string.Format("project: {0} \"{1}\" \"{2}\"", ProjectShortName, Summary, Description));

                var issueList = from si in similarIssues
                                select new {IssueId = si.Id, Summary = si.Summary, Description = si.Description};

                if (issueList.Count() > 0)
                {
                    WriteWarning("Found similar issues. If you still want to create it, use -Force=true");
                    WriteObject(issueList);

                    return;
                }
            }

            var newIssue = new Issue
            {
                Summary = Summary,
                Description = Description,
                Priority = Priority,
                ProjectShortName = ProjectShortName,
                ReporterName = Connection.GetCurrentAuthenticatedUser().Username,
                State = "Submitted",
                Type = Type,
                Subsystem = Subsystem
            };

            var id = IssueManagement.CreateIssue(newIssue);

            WriteObject(string.Format("Issue Created with id: {0}", id));
        }
Exemple #12
0
        /// <inheritdoc />
        public async Task <string> CreateIssue(string projectId, Issue issue)
        {
            if (string.IsNullOrEmpty(projectId))
            {
                throw new ArgumentNullException(nameof(projectId));
            }

            var queryString = new List <string>(4)
            {
                $"project={projectId}"
            };

            if (!string.IsNullOrEmpty(issue.Summary))
            {
                queryString.Add($"summary={Uri.EscapeDataString(issue.Summary)}");
            }
            if (!string.IsNullOrEmpty(issue.Description))
            {
                queryString.Add($"description={Uri.EscapeDataString(issue.Description)}");
            }
            queryString.Add("markdown=" + (issue.IsMarkdown ? "true" : "false"));

            var query = string.Join("&", queryString);

            var client = await _connection.GetAuthenticatedHttpClient();

            var response = await client.PutAsync($"rest/issue?{query}", new MultipartFormDataContent());

            response.EnsureSuccessStatusCode();

            // Extract issue id from Location header response
            const string marker         = "rest/issue/";
            var          locationHeader = response.Headers.Location.ToString();

            var issueId = locationHeader.Substring(locationHeader.IndexOf(marker, StringComparison.OrdinalIgnoreCase) + marker.Length);

            // For every custom field, apply a command
            var customFields = issue.Fields
                               .Where(field => !ReservedFields.Contains(field.Name.ToLower()))
                               .ToDictionary(field => field.Name, field => field.Value);

            foreach (var customField in customFields)
            {
                if (!(customField.Value is string) && customField.Value is System.Collections.IEnumerable enumerable)
                {
                    await ApplyCommand(issueId, $"{customField.Key} {string.Join(" ", enumerable.OfType<string>())}", string.Empty);
                }
                else
                {
                    switch (customField.Value)
                    {
                    case DateTime dateTime:
                        await ApplyCommand(issueId, $"{customField.Key} {dateTime:s}", string.Empty);

                        break;

                    case DateTimeOffset dateTimeOffset:
                        await ApplyCommand(issueId, $"{customField.Key} {dateTimeOffset:s}", string.Empty);

                        break;

                    default:
                        await ApplyCommand(issueId, $"{customField.Key} {customField.Value}", string.Empty);

                        break;
                    }
                }
            }

            // Add comments?
            foreach (var issueComment in issue.Comments)
            {
                await ApplyCommand(issueId, "comment", issueComment.Text, runAs : issueComment.Author);
            }

            // Add tags?
            foreach (var issueTag in issue.Tags)
            {
                await ApplyCommand(issueId, $"tag {issueTag.Value}");
            }

            return(issueId);
        }
        public string CreateIssue(Issue issue)
        {
            if (!_connection.IsAuthenticated)
            {
                throw new InvalidRequestException(Language.YouTrackClient_CreateIssue_Not_Logged_In);
            }

            try
            {
                var response = _connection.Post("issue", issue.ToExpandoObject(), HttpContentTypes.ApplicationJson);

                return response.id;
            }
            catch (HttpException httpException)
            {
                throw new InvalidRequestException(httpException.StatusDescription, httpException);
            }
        }