Skip to content

Commit

Permalink
fix and improve response wikification handling #101
Browse files Browse the repository at this point in the history
  • Loading branch information
rekolobov committed Jul 6, 2021
1 parent 5bdaf70 commit 9c4767b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
14 changes: 8 additions & 6 deletions src/YouTrackSharp/Issues/IIssuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public interface IIssuesService
/// <remarks>Uses the REST API <a href="https://www.jetbrains.com/help/youtrack/standalone/Get-an-Issue.html">Get an Issue</a>.</remarks>
/// <param name="issueId">Id of an issue to get.</param>
/// <param name="wikifyDescription">If set to <value>true</value>, then issue description in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>
/// <returns>The <see cref="Issue" /> that matches the requested <paramref name="issueId"/>.</returns>
/// <param name="wikifyContents">If set to <value>true</value>, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>/// <returns>The <see cref="Issue" /> that matches the requested <paramref name="issueId"/>.</returns>
/// <exception cref="T:System.ArgumentNullException">When the <paramref name="issueId"/> is null or empty.</exception>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
Task<Issue> GetIssue(string issueId, bool wikifyDescription = false);
Task<Issue> GetIssue(string issueId, bool wikifyDescription = false, bool wikifyContents = false);

/// <summary>
/// Checks whether an issue exists on the server.
Expand Down Expand Up @@ -96,11 +96,12 @@ public interface IIssuesService
/// <param name="take">Maximum number of issues to be returned. Defaults to the server-side default of the YouTrack server instance..</param>
/// <param name="updatedAfter">Only issues updated after the specified date will be retrieved.</param>
/// <param name="wikifyDescription">If set to <value>true</value>, then issue description in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>
/// <param name="wikifyContents">If set to <value>true</value>, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>
/// <returns>A <see cref="T:System.Collections.Generic.ICollection`1" /> of <see cref="Issue" /> that match the specified parameters.</returns>
/// <exception cref="T:System.ArgumentNullException">When the <paramref name="projectId"/> is null or empty.</exception>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
Task<ICollection<Issue>> GetIssuesInProject(string projectId, string filter = null,
int? skip = null, int? take = null, DateTime? updatedAfter = null, bool wikifyDescription = false);
Task<ICollection<Issue>> GetIssuesInProject(string projectId, string filter = null, int? skip = null,
int? take = null, DateTime? updatedAfter = null, bool wikifyDescription = false, bool wikifyContents = false);

/// <summary>
/// Get issues from the server.
Expand All @@ -110,9 +111,10 @@ Task<ICollection<Issue>> GetIssuesInProject(string projectId, string filter = nu
/// <param name="skip">The number of issues to skip before getting a list of issues.</param>
/// <param name="take">Maximum number of issues to be returned. Defaults to the server-side default of the YouTrack server instance.</param>
/// <param name="wikifyDescription">If set to <value>true</value>, then issue description in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>
/// <returns>A <see cref="T:System.Collections.Generic.ICollection`1" /> of <see cref="Issue" /> that match the specified parameters.</returns>
/// <param name="wikifyContents">If set to <value>true</value>, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>/// <returns>A <see cref="T:System.Collections.Generic.ICollection`1" /> of <see cref="Issue" /> that match the specified parameters.</returns>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
Task<ICollection<Issue>> GetIssues(string filter = null, int? skip = null, int? take = null, bool wikifyDescription = false);
Task<ICollection<Issue>> GetIssues(string filter = null, int? skip = null, int? take = null,
bool wikifyDescription = false, bool wikifyContents = false);

/// <summary>
/// Get issue count from the server. This operation may be retried internally and take a while to complete.
Expand Down
7 changes: 4 additions & 3 deletions src/YouTrackSharp/Issues/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class Issue
/// </summary>
/// <param name="entity">Api client entity of type <see cref="Generated.Issue"/> to convert from.</param>
/// <param name="wikify">If set to <value>true</value>, then issue description will be formatted ("wikified"). Defaults to <value>false</value>.</param>
internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false)
/// <param name="wikifyContents">If set to <value>true</value>, then comments and issue text fields in the response will be formatted ("wikified"). Defaults to <value>false</value>.</param>
internal static Issue FromApiEntity(Generated.Issue entity, bool wikify = false, bool wikifyContents = false)
{
var issue = new Issue
{
Expand All @@ -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<string>(){Value=tag.Name})
};

Expand Down Expand Up @@ -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<string>() {f.Value.Text};
var rawValue = new List<string>() {wikifyContents ? f.Value.MarkdownText : f.Value.Text};
issue._fields[f.Name] = new Field()
{
Name = f.Name, Value = rawValue, ValueId = JArray.FromObject(rawValue)
Expand Down
10 changes: 6 additions & 4 deletions src/YouTrackSharp/Issues/IssuesService.Querying.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public partial class IssuesService
{
/// <inheritdoc />
public async Task<ICollection<Issue>> 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))
{
Expand All @@ -25,18 +26,19 @@ public async Task<ICollection<Issue>> GetIssuesInProject(string projectId, strin
}
queryString += " " + filter ?? "";

return await GetIssues(queryString, skip, take, wikifyDescription);
return await GetIssues(queryString, skip, take, wikifyDescription, wikifyContents);
}

/// <inheritdoc />
public async Task<ICollection<Issue>> GetIssues(string filter = null, int? skip = null, int? take = null, bool wikifyDescription = false)
public async Task<ICollection<Issue>> 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();
}

/// <inheritdoc />
Expand Down
6 changes: 3 additions & 3 deletions src/YouTrackSharp/Issues/IssuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand All @@ -40,7 +40,7 @@ public IssuesService(Connection connection)
}

/// <inheritdoc />
public async Task<Issue> GetIssue(string issueId, bool wikifyDescription = false)
public async Task<Issue> GetIssue(string issueId, bool wikifyDescription = false, bool wikifyContents = false)
{
if (string.IsNullOrEmpty(issueId))
{
Expand All @@ -53,7 +53,7 @@ public async Task<Issue> 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)
{
Expand Down

0 comments on commit 9c4767b

Please sign in to comment.