Skip to content

Commit

Permalink
Merge pull request #59 from JetBrains/develop
Browse files Browse the repository at this point in the history
Prepare 3.1.0 release
  • Loading branch information
maartenba authored Sep 12, 2017
2 parents 338860d + c39f952 commit e15339a
Show file tree
Hide file tree
Showing 27 changed files with 1,025 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ The following API's are currently supported:
* [Projects-related methods](https://www.jetbrains.com/help/youtrack/standalone/Projects-Related-Methods.html) through `ProjectsService`
* [Issues-related methods](https://www.jetbrains.com/help/youtrack/standalone/Issues-Related-Methods.html) through `IssuesService`
* [Time-tracking-related methods](https://www.jetbrains.com/help/youtrack/standalone/Time-Tracking-User-Methods.html) through `TimeTrackingService`

* Administration API's
* [User management](https://www.jetbrains.com/help/youtrack/standalone/Users.html) through `UserManagementService`
* [Time Tracker management](https://www.jetbrains.com/help/youtrack/standalone/Time-Tracking-Settings-Methods.html) through `TimeTrackingManagementService`

Many other API's are not included yet - feel free to [tackle one of the `UpForGrabs` issues](https://github.com/JetBrains/YouTrackSharp/issues?q=is%3Aissue+is%3Aopen+label%3AUpForGrabs) and make YouTrackSharp better!


Expand Down
1 change: 1 addition & 0 deletions build/YouTrackSharp.Build.csproj.dotsettings
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
6 changes: 1 addition & 5 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"sdk": {
"version": "1.0.4"
}
}
{"sdk":{"version":"1.1.0"}}
25 changes: 23 additions & 2 deletions src/YouTrackSharp/ConnectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using YouTrackSharp.Issues;
using YouTrackSharp.Management;
using YouTrackSharp.Projects;
using YouTrackSharp.TimeTracking;

namespace YouTrackSharp
{
/// <summary>
/// Extension methods for <see cref="Connection" /> , providing easy access to all services.
/// Extension methods for <see cref="Connection" />, providing easy access to all services.
/// </summary>
public static class ConnectionExtensions
{
Expand Down Expand Up @@ -33,10 +34,30 @@ public static IssuesService CreateIssuesService(this Connection connection)
/// Creates a <see cref="TimeTrackingService" />.
/// </summary>
/// <param name="connection">The <see cref="Connection" /> to create a service with.</param>
/// <returns><see cref="TimeTrackingService" /> for working with YouTrack issues.</returns>
/// <returns><see cref="TimeTrackingService" /> for working with YouTrack time tracking.</returns>
public static TimeTrackingService CreateTimeTrackingService(this Connection connection)
{
return new TimeTrackingService(connection);
}

/// <summary>
/// Creates a <see cref="UserManagementService" />.
/// </summary>
/// <param name="connection">The <see cref="Connection" /> to create a service with.</param>
/// <returns><see cref="UserManagementService" /> for managing YouTrack users.</returns>
public static UserManagementService CreateUserManagementService(this Connection connection)
{
return new UserManagementService(connection);
}

/// <summary>
/// Creates a <see cref="TimeTrackingManagementService" />.
/// </summary>
/// <param name="connection">The <see cref="Connection" /> to create a service with.</param>
/// <returns><see cref="TimeTrackingManagementService" /> for managing YouTrack time tracking settings.</returns>
public static TimeTrackingManagementService CreateTimeTrackingManagementService(this Connection connection)
{
return new TimeTrackingManagementService(connection);
}
}
}
28 changes: 28 additions & 0 deletions src/YouTrackSharp/Management/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;

namespace YouTrackSharp.Management
{
/// <summary>
/// A class that represents YouTrack group information.
/// </summary>
public class Group
{
/// <summary>
/// Id of the group.
/// </summary>
[JsonProperty("entityId")]
public string Id { get; set; }

/// <summary>
/// Name of the group.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// URL of the group.
/// </summary>
[JsonProperty("url")]
public string Url { get; set; }
}
}
37 changes: 37 additions & 0 deletions src/YouTrackSharp/Management/SystemWideTimeTrackingSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace YouTrackSharp.Management
{
/// <summary>
/// A class that represents YouTrack system wide time settings information.
/// </summary>
public class SystemWideTimeTrackingSettings
{
/// <summary>
/// Creates an instance of the <see cref="SystemWideTimeTrackingSettings" /> class.
/// </summary>
public SystemWideTimeTrackingSettings()
{
WorkDays = new List<SubValue<int>>();
}

/// <summary>
/// Hours A Day.
/// </summary>
[JsonProperty("hoursADay")]
public int HoursADay { get; set; }

/// <summary>
/// Days A Week.
/// </summary>
[JsonProperty("daysAWeek")]
public int DaysAWeek { get; set; }

/// <summary>
/// WorkDays A Week.
/// </summary>
[JsonProperty("workWeek")]
public ICollection<SubValue<int>> WorkDays { get; set; }
}
}
153 changes: 153 additions & 0 deletions src/YouTrackSharp/Management/TimeTrackingManagementService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using YouTrackSharp.TimeTracking;

namespace YouTrackSharp.Management
{
/// <summary>
/// A class that represents a REST API client for <a href="https://www.jetbrains.com/help/youtrack/standalone/Time-Tracking-Settings-Methods.html">administering Time Tracking Settings in YouTrack</a>.
/// It uses a <see cref="Connection" /> implementation to connect to the remote YouTrack server instance.
/// </summary>
public class TimeTrackingManagementService
{
private readonly Connection _connection;

/// <summary>
/// Creates an instance of the <see cref="TimeTrackingManagementService" /> class.
/// </summary>
/// <param name="connection">A <see cref="Connection" /> instance that provides a connection to the remote YouTrack server instance.</param>
public TimeTrackingManagementService(Connection connection)
{
_connection = connection ?? throw new ArgumentNullException(nameof(connection));
}

/// <summary>
/// Get the current system-wide time tracking settings.
/// </summary>
/// <remarks>Uses the REST API <a href="https://www.jetbrains.com/help/youtrack/standalone/GET-System-wide-Time-Tracking-Settings.html">Get System-wide Time Tracking Settings</a>.</remarks>
/// <returns>System-wide <see cref="SystemWideTimeTrackingSettings" />.</returns>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
public async Task<SystemWideTimeTrackingSettings> GetSystemWideTimeTrackingSettings()
{
var client = await _connection.GetAuthenticatedHttpClient();
var response = await client.GetAsync($"rest/admin/timetracking");

response.EnsureSuccessStatusCode();

return JsonConvert.DeserializeObject<SystemWideTimeTrackingSettings>(await response.Content.ReadAsStringAsync());
}


/// <summary>
/// Updates the system-wide time tracking settings.
/// </summary>
/// <remarks>Uses the REST API <a href="https://www.jetbrains.com/help/youtrack/standalone/PUT-System-wide-Time-Tracking-Settings.html">Set system-wide time tracking settings: a list of working days in a week, and a number of hours in a working day</a>.</remarks>
/// <param name="timeSettings"><see cref="SystemWideTimeTrackingSettings" />Parameter daysAWeek is ignored since Youtrack 5.1</param>
/// <exception cref="T:YouTrackErrorException">When the call to the remote YouTrack server instance failed and YouTrack reported an error message.</exception>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
public async Task UpdateSystemWideTimeTrackingSettings(SystemWideTimeTrackingSettings timeSettings)
{
if (timeSettings == null)
{
throw new ArgumentNullException(nameof(timeSettings));
}

var stringContent = new StringContent(JsonConvert.SerializeObject(timeSettings));
stringContent.Headers.ContentType = new MediaTypeHeaderValue(Constants.HttpContentTypes.ApplicationJson);

var client = await _connection.GetAuthenticatedHttpClient();
var response = await client.PutAsync($"rest/admin/timetracking", stringContent);

if (response.StatusCode == HttpStatusCode.BadRequest)
{
// Try reading the error message
var responseJson = JObject.Parse(await response.Content.ReadAsStringAsync());
if (responseJson["value"] != null)
{
throw new YouTrackErrorException(responseJson["value"].Value<string>());
}
else
{
throw new YouTrackErrorException(Strings.Exception_UnknownError);
}
}

response.EnsureSuccessStatusCode();
}


/// <summary>
/// Get the current time tracking settings for a specific project.
/// </summary>
/// <remarks>Uses the REST API <a href="https://www.jetbrains.com/help/youtrack/standalone/GET-Time-Tracking-Settings-for-a-Project.html">Get Time Tracking Settings for a Project</a>.</remarks>
/// <param name="projectId">Id of the project to get timetracking settings for.</param>
/// <returns><see cref="TimeTrackingSettings" />.</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>
public async Task<TimeTrackingSettings> GetTimeTrackingSettingsForProject(string projectId)
{
if (string.IsNullOrEmpty(projectId))
{
throw new ArgumentNullException(nameof(projectId));
}

var client = await _connection.GetAuthenticatedHttpClient();
var response = await client.GetAsync($"rest/admin/project/{projectId}/timetracking");

response.EnsureSuccessStatusCode();

return JsonConvert.DeserializeObject<TimeTrackingSettings>(await response.Content.ReadAsStringAsync());
}


/// <summary>
/// Updates the current time tracking settings for a specific project.
/// </summary>
/// <remarks>Uses the REST API <a href="https://www.jetbrains.com/help/youtrack/standalone/PUT-Time-Tracking-Settings-for-a-Project.html">Configure time tracking settings for a specific project</a>.</remarks>
/// <param name="projectId">Id of the project to update.</param>
/// <param name="timeTrackingSettings">Timetracking settings for this project.</param>
/// <exception cref="T:System.ArgumentNullException">When the <paramref name="projectId"/> is null or empty.</exception>
/// <exception cref="T:System.ArgumentNullException">When the <paramref name="timeTrackingSettings"/> is null.</exception>
/// <exception cref="T:YouTrackErrorException">When the call to the remote YouTrack server instance failed and YouTrack reported an error message.</exception>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
public async Task UpdateTimeTrackingSettingsForProject(string projectId, TimeTrackingSettings timeTrackingSettings)
{
if (string.IsNullOrEmpty(projectId))
{
throw new ArgumentNullException(nameof(projectId));
}

if (timeTrackingSettings == null)
{
throw new ArgumentNullException(nameof(timeTrackingSettings));
}

var stringContent = new StringContent(JsonConvert.SerializeObject(timeTrackingSettings));
stringContent.Headers.ContentType = new MediaTypeHeaderValue(Constants.HttpContentTypes.ApplicationJson);

var client = await _connection.GetAuthenticatedHttpClient();
var response = await client.PutAsync($"rest/admin/project/{projectId}/timetracking", stringContent);

if (response.StatusCode == HttpStatusCode.BadRequest)
{
// Try reading the error message
var responseJson = JObject.Parse(await response.Content.ReadAsStringAsync());
if (responseJson["value"] != null)
{
throw new YouTrackErrorException(responseJson["value"].Value<string>());
}
else
{
throw new YouTrackErrorException(Strings.Exception_UnknownError);
}
}

response.EnsureSuccessStatusCode();
}
}
}
43 changes: 43 additions & 0 deletions src/YouTrackSharp/Management/TimeTrackingSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Newtonsoft.Json;

namespace YouTrackSharp.Management
{
/// <summary>
/// A class that represents YouTrack timetracking settings information.
/// </summary>
public class TimeTrackingSettings
{
/// <summary>
/// Is time tracking enabled?
/// </summary>
[JsonProperty("enabled")]
public bool Enabled { get; set; }

/// <summary>
/// Field that contains Estimation data.
/// </summary>
[JsonProperty("estimation")]
public TimeField Estimation { get; set; }

/// <summary>
/// Field that contains SpentTime data.
/// </summary>
[JsonProperty("spentTime")]
public TimeField SpentTime { get; set; }

public class TimeField
{
/// <summary>
/// Name of the field.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Url of the field.
/// </summary>
[JsonProperty("url")]
public string Url { get; set; }
}
}
}
34 changes: 34 additions & 0 deletions src/YouTrackSharp/Management/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Newtonsoft.Json;

namespace YouTrackSharp.Management
{
/// <summary>
/// A class that represents YouTrack user information.
/// </summary>
public class User
{
/// <summary>
/// Username of the user.
/// </summary>
[JsonProperty("login")]
public string Username { get; set; }

/// <summary>
/// Full name of the user.
/// </summary>
[JsonProperty("fullName")]
public string FullName { get; set; }

/// <summary>
/// Email address of the user.
/// </summary>
[JsonProperty("email")]
public string Email { get; set; }

/// <summary>
/// Jabber of the user.
/// </summary>
[JsonProperty("jabber")]
public string Jabber { get; set; }
}
}
Loading

0 comments on commit e15339a

Please sign in to comment.