From 9c4767b29feeec3d4f48c332ab48abc88a2c056a Mon Sep 17 00:00:00 2001 From: Roman Kolobov Date: Tue, 6 Jul 2021 09:42:59 +0300 Subject: [PATCH] fix and improve response wikification handling #101 --- src/YouTrackSharp/Issues/IIssuesService.cs | 14 ++++++++------ src/YouTrackSharp/Issues/Issue.cs | 7 ++++--- src/YouTrackSharp/Issues/IssuesService.Querying.cs | 10 ++++++---- src/YouTrackSharp/Issues/IssuesService.cs | 6 +++--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/YouTrackSharp/Issues/IIssuesService.cs b/src/YouTrackSharp/Issues/IIssuesService.cs index ad15b38c..bb068c65 100644 --- a/src/YouTrackSharp/Issues/IIssuesService.cs +++ b/src/YouTrackSharp/Issues/IIssuesService.cs @@ -13,10 +13,10 @@ public interface IIssuesService /// Uses the REST API Get an Issue. /// Id of an issue to get. /// If set to true, then issue description in the response will be formatted ("wikified"). Defaults to false. - /// The that matches the requested . + /// If set to true, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to false./// The that matches the requested . /// When the is null or empty. /// When the call to the remote YouTrack server instance failed. - Task GetIssue(string issueId, bool wikifyDescription = false); + Task GetIssue(string issueId, bool wikifyDescription = false, bool wikifyContents = false); /// /// Checks whether an issue exists on the server. @@ -96,11 +96,12 @@ public interface IIssuesService /// Maximum number of issues to be returned. Defaults to the server-side default of the YouTrack server instance.. /// Only issues updated after the specified date will be retrieved. /// If set to true, then issue description in the response will be formatted ("wikified"). Defaults to false. + /// If set to true, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to false. /// A of that match the specified parameters. /// When the is null or empty. /// When the call to the remote YouTrack server instance failed. - Task> GetIssuesInProject(string projectId, string filter = null, - int? skip = null, int? take = null, DateTime? updatedAfter = null, bool wikifyDescription = false); + Task> GetIssuesInProject(string projectId, string filter = null, int? skip = null, + int? take = null, DateTime? updatedAfter = null, bool wikifyDescription = false, bool wikifyContents = false); /// /// Get issues from the server. @@ -110,9 +111,10 @@ Task> GetIssuesInProject(string projectId, string filter = nu /// The number of issues to skip before getting a list of issues. /// Maximum number of issues to be returned. Defaults to the server-side default of the YouTrack server instance. /// If set to true, then issue description in the response will be formatted ("wikified"). Defaults to false. - /// A of that match the specified parameters. + /// If set to true, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to false./// A of that match the specified parameters. /// When the call to the remote YouTrack server instance failed. - Task> GetIssues(string filter = null, int? skip = null, int? take = null, bool wikifyDescription = false); + Task> GetIssues(string filter = null, int? skip = null, int? take = null, + bool wikifyDescription = false, bool wikifyContents = false); /// /// Get issue count from the server. This operation may be retried internally and take a while to complete. diff --git a/src/YouTrackSharp/Issues/Issue.cs b/src/YouTrackSharp/Issues/Issue.cs index d5c1c5fc..7ebef157 100644 --- a/src/YouTrackSharp/Issues/Issue.cs +++ b/src/YouTrackSharp/Issues/Issue.cs @@ -50,7 +50,8 @@ public class Issue /// /// Api client entity of type to convert from. /// If set to true, then issue description will be formatted ("wikified"). Defaults to false. - internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false) + /// If set to true, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to false. + internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false, bool wikifyContents = false) { var issue = new Issue { @@ -60,7 +61,7 @@ internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false) Summary = entity.Summary, Description = wikify ? entity.WikifiedDescription : entity.Description, IsMarkdown = entity.UsesMarkdown ?? true, - Comments = entity.Comments?.Select(comment => Comment.FromApiEntity(comment, false)).ToList(), + Comments = entity.Comments?.Select(comment => Comment.FromApiEntity(comment, wikifyContents)).ToList(), Tags = entity.Tags?.Select(tag => new SubValue(){Value=tag.Name}) }; @@ -165,7 +166,7 @@ internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false) case TextIssueCustomField f: if (f.Value != null) { - var rawValue = new List() {f.Value.Text}; + var rawValue = new List() {wikifyContents ? f.Value.MarkdownText : f.Value.Text}; issue._fields[f.Name] = new Field() { Name = f.Name, Value = rawValue, ValueId = JArray.FromObject(rawValue) diff --git a/src/YouTrackSharp/Issues/IssuesService.Querying.cs b/src/YouTrackSharp/Issues/IssuesService.Querying.cs index c2e77b81..aacae574 100644 --- a/src/YouTrackSharp/Issues/IssuesService.Querying.cs +++ b/src/YouTrackSharp/Issues/IssuesService.Querying.cs @@ -11,7 +11,8 @@ public partial class IssuesService { /// public async Task> GetIssuesInProject(string projectId, string filter = null, - int? skip = null, int? take = null, DateTime? updatedAfter = null, bool wikifyDescription = false) + int? skip = null, int? take = null, DateTime? updatedAfter = null, + bool wikifyDescription = false, bool wikifyContents = false) { if (string.IsNullOrEmpty(projectId)) { @@ -25,18 +26,19 @@ public async Task> GetIssuesInProject(string projectId, strin } queryString += " " + filter ?? ""; - return await GetIssues(queryString, skip, take, wikifyDescription); + return await GetIssues(queryString, skip, take, wikifyDescription, wikifyContents); } /// - public async Task> GetIssues(string filter = null, int? skip = null, int? take = null, bool wikifyDescription = false) + public async Task> GetIssues(string filter = null, int? skip = null, int? take = null, + bool wikifyDescription = false, bool wikifyContents = false) { var client = await _connection.GetAuthenticatedApiClient(); var response = await client.IssuesGetAsync(filter, (wikifyDescription ? ISSUES_FIELD_WIKIFIED_DESCRIPTION : ISSUES_FIELD_DESCRIPTION) + "," + ISSUES_FIELDS_QUERY_NO_DESCRIPTION, skip, take); - return response.Select(issue => Issue.FromApiEntity(issue, wikifyDescription)).ToList(); + return response.Select(issue => Issue.FromApiEntity(issue, wikifyDescription, wikifyContents)).ToList(); } /// diff --git a/src/YouTrackSharp/Issues/IssuesService.cs b/src/YouTrackSharp/Issues/IssuesService.cs index ae72bcc6..76544e66 100644 --- a/src/YouTrackSharp/Issues/IssuesService.cs +++ b/src/YouTrackSharp/Issues/IssuesService.cs @@ -23,7 +23,7 @@ public partial class IssuesService : IIssuesService private static string ISSUES_FIELDS_QUERY_NO_DESCRIPTION = "comments(" + COMMENTS_FIELDS_QUERY + "),links(" + LINKS_FIELDS_QUERY + "),attachments(" + ATTACHMENTS_FIELDS_QUERY + - "),id,idReadable,externalIssue(id),project(id,name,shortName),usesMarkdown,reporter(id,login,fullName),created,updated,resolved,votes,watchers(hasStar),numberInProject,updater(id,login,fullName),commentsCount,summary,tags(id,name),customFields(id,name,value(id,name,fullName,localizedName,text,login,minutes,color(id,background,foreground))),visibility(permittedGroups(id,name))"; + "),id,idReadable,externalIssue(id),project(id,name,shortName),usesMarkdown,reporter(id,login,fullName),created,updated,resolved,votes,watchers(hasStar),numberInProject,updater(id,login,fullName),commentsCount,summary,tags(id,name),customFields(id,name,value(id,name,fullName,localizedName,text,markdownText,login,minutes,color(id,background,foreground))),visibility(permittedGroups(id,name))"; private static readonly string[] ReservedFields = { @@ -40,7 +40,7 @@ public IssuesService(Connection connection) } /// - public async Task GetIssue(string issueId, bool wikifyDescription = false) + public async Task GetIssue(string issueId, bool wikifyDescription = false, bool wikifyContents = false) { if (string.IsNullOrEmpty(issueId)) { @@ -53,7 +53,7 @@ public async Task GetIssue(string issueId, bool wikifyDescription = false var response = await client.IssuesGetAsync(issueId, (wikifyDescription ? ISSUES_FIELD_WIKIFIED_DESCRIPTION : ISSUES_FIELD_DESCRIPTION) + "," + ISSUES_FIELDS_QUERY_NO_DESCRIPTION, default(System.Threading.CancellationToken)); - return Issue.FromApiEntity(response); + return Issue.FromApiEntity(response, wikifyDescription, wikifyContents); } catch (YouTrackErrorException e) {