-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from JetBrains/develop
Prepare 3.1.0 release
- Loading branch information
Showing
27 changed files
with
1,025 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
{ | ||
"sdk": { | ||
"version": "1.0.4" | ||
} | ||
} | ||
{"sdk":{"version":"1.1.0"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
src/YouTrackSharp/Management/SystemWideTimeTrackingSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
153
src/YouTrackSharp/Management/TimeTrackingManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.