Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠 refactoring client APIs #11

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions jwl.core/JwlCoreProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class JwlCoreProcess : IDisposable
private HttpClient _httpClient;
private IJiraClient _jiraClient;

private jwl.jira.api.rest.common.JiraUserInfo? _userInfo;

public JwlCoreProcess(AppConfig config, ICoreProcessInteraction interaction)
{
_config = config;
Expand Down Expand Up @@ -59,6 +57,7 @@ public JwlCoreProcess(AppConfig config, ICoreProcessInteraction interaction)
*/
}

#pragma warning disable CS1998
public async Task PreProcess()
{
Feedback?.OverallProcessStart();
Expand All @@ -76,11 +75,8 @@ public async Task PreProcess()
throw new ArgumentNullException($"Jira credentials not supplied");

_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(jiraUserName + ":" + jiraUserPassword)));

Feedback?.PreloadUserInfoStart(jiraUserName);
_userInfo = await _jiraClient.GetUserInfo();
Feedback?.PreloadUserInfoEnd();
}
#pragma warning restore

public async Task Process(IEnumerable<string> inputFiles)
{
Expand Down Expand Up @@ -143,7 +139,7 @@ private async Task FillJiraWithWorklogs(InputWorkLog[] inputWorklogs, WorkLog[]
{
Feedback?.FillJiraWithWorklogsSetTarget(inputWorklogs.Length, worklogsForDeletion.Length);

if (_userInfo == null || _userInfo.Key == null)
if (_jiraClient.UserInfo?.Key is null)
throw new ArgumentNullException(@"Unresolved Jira key for the logged-on user");

Task[] fillJiraWithWorklogsTasks = worklogsForDeletion
Expand Down Expand Up @@ -228,9 +224,7 @@ private async Task<WorkLog[]> RetrieveWorklogsForDeletion(InputWorkLog[] inputWo
{
WorkLog[] result;

if (_userInfo == null)
throw new ArgumentNullException(@"User info not preloaded from Jira server");
if (string.IsNullOrEmpty(_userInfo.Key))
if (string.IsNullOrEmpty(_jiraClient.UserInfo?.Key))
throw new ArgumentNullException(@"Empty user key preloaded from Jira server");

DateTime[] inputWorklogDays = inputWorklogs
Expand Down
4 changes: 3 additions & 1 deletion jwl.jira/IJiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

public interface IJiraClient
{
Task<api.rest.common.JiraUserInfo> GetUserInfo();
api.rest.common.JiraUserInfo UserInfo { get; }

Task<WorkLogType[]> GetAvailableActivities();

Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, string issueKey);

Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, IEnumerable<string>? issueKeys);

Task AddWorklog(string issueKey, DateOnly day, int timeSpentSeconds, string? activity, string? comment);
Expand Down
12 changes: 6 additions & 6 deletions jwl.jira/JiraWithICTimePluginApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class JiraWithICTimePluginApi
: IJiraClient
{
public string UserName { get; }
public api.rest.common.JiraUserInfo UserInfo => _vanillaJiraApi.UserInfo;

private readonly HttpClient _httpClient;
private readonly VanillaJiraClient _vanillaJiraApi;

public JiraWithICTimePluginApi(HttpClient httpClient, string userName)
{
Expand All @@ -24,16 +26,14 @@ public JiraWithICTimePluginApi(HttpClient httpClient, string userName)
_vanillaJiraApi = new VanillaJiraClient(httpClient, userName);
}

private readonly VanillaJiraClient _vanillaJiraApi;

public async Task<JiraUserInfo> GetUserInfo()
public async Task<WorkLogType[]> GetAvailableActivities()
{
return await _vanillaJiraApi.GetUserInfo();
return await _vanillaJiraApi.GetAvailableActivities();
}

public async Task<WorkLogType[]> GetAvailableActivities()
public async Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, string issueKey)
{
return await _vanillaJiraApi.GetAvailableActivities();
return await _vanillaJiraApi.GetIssueWorklogs(from, to, issueKey);
}

public async Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, IEnumerable<string>? issueKeys)
Expand Down
Loading
Loading