Skip to content
Open
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
6 changes: 4 additions & 2 deletions PluginJira/API/Factory/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ public async Task<HttpResponseMessage> GetAsync(string path)
try
{
var token = await Authenticator.GetToken();
var uri = new Uri($"{Constants.BaseApiUrl.TrimEnd('/')}/{path.TrimStart('/')}");
var uri = new Uri($"{Settings.GetBaseUri().TrimEnd('/')}/{path.TrimStart('/')}");

var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = uri,
};
request.Headers.Add(_tokenHeaderName, token);

// Add basic authentication
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", token);

return await Client.SendAsync(request);
}
Expand Down
2 changes: 1 addition & 1 deletion PluginJira/API/Utility/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace PluginJira.API.Utility
public static class Constants
{
public static string BaseApiUrl = "https://test.atlassian.net/rest/api/2";
public static string TestConnectionPath = "/applicationrole";
public static string TestConnectionPath = "applicationrole";
public static string CustomProperty = "CustomProperty";
public static string EmptySchemaDescription = "This schema has no properties. This is likely due to to there being no data.";
}
Expand Down
14 changes: 2 additions & 12 deletions PluginJira/API/Utility/EndpointHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class EndpointHelper
static EndpointHelper()
{
IssuesEndpointHelper.IssuesEndpoints.ToList().ForEach(x => Endpoints.TryAdd(x.Key, x.Value));
ApplicationRolesEndpointHelper.ApplicationRolesEndpoints.ToList().ForEach(x => Endpoints.TryAdd(x.Key, x.Value));
}

public static Dictionary<string, Endpoint> GetAllEndpoints()
Expand Down Expand Up @@ -65,24 +66,13 @@ public abstract class Endpoint

public virtual async Task<Count> GetCountOfRecords(IApiClientFactory factory, Settings settings)
{
var response = await factory.CreateApiClient(settings).GetAsync($"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}");

var recordsList = JsonConvert.DeserializeObject<DataWrapper>(await response.Content.ReadAsStringAsync());

return new Count
{
Kind = Count.Types.Kind.Exact,
Value = (int) recordsList.TotalRecords
};
throw new NotImplementedException();
}

public virtual IAsyncEnumerable<Record> ReadRecordsAsync(IApiClientFactory factory, Settings settings,
DateTime? lastReadTime = null, TaskCompletionSource<DateTime>? tcs = null, bool isDiscoverRead = false)
{

throw new NotImplementedException();


}

public virtual async Task<string> WriteRecordAsync(IApiClient apiClient, Schema schema, Record record,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Grpc.Core;
using Naveego.Sdk.Plugins;
using Newtonsoft.Json;
using PluginJira.API.Factory;
using PluginJira.API.Utility.EndpointHelperEndpoints;
using PluginJira.DataContracts;
using PluginJira.Helper;

namespace PluginJira.API.Utility.EndpointHelperEndpoints
{
public static class ApplicationRolesEndpointHelper
{
private class ApplicationRolesEndpoint : Endpoint
{
public override async IAsyncEnumerable<Record> ReadRecordsAsync(IApiClientFactory factory, Settings settings,
DateTime? lastReadTime = null, TaskCompletionSource<DateTime>? tcs = null, bool isDiscoverRead = false)
{
// fetch all records
var jira = factory.CreateApiClient(settings);

var response = await jira.GetAsync("applicationrole");

var recordsList = JsonConvert.DeserializeObject<List<ApplicationEndpointWrapper>>(await response.Content.ReadAsStringAsync());

foreach (var item in recordsList)
{
var recordMap = new Dictionary<string, object>();

recordMap["key"] = item.Key;
recordMap["groups"] = item.Groups;
recordMap["name"]= item.Name;

yield return new Record
{
Action = Record.Types.Action.Upsert,
DataJson = JsonConvert.SerializeObject(recordMap)
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is incorrect


}

public override async Task<Count> GetCountOfRecords(IApiClientFactory factory, Settings settings)
{
var response = await factory.CreateApiClient(settings).GetAsync($"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}");

var recordsList = JsonConvert.DeserializeObject <List<ApplicationEndpointWrapper>>(await response.Content.ReadAsStringAsync());

return new Count
{
Kind = Count.Types.Kind.Unavailable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return unavailable you should not perform any other actions in the count method

};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra new line

}
}

public static readonly Dictionary<string, Endpoint> ApplicationRolesEndpoints = new Dictionary<string, Endpoint>
{
{"AllApplicationRoles", new ApplicationRolesEndpoint
{
Id = "AllApplicationRoles",
Name = "All Application Roles",
BasePath = "/applicationrole",
AllPath = "/",
DetailPath = "/",
DetailPropertyId = "",
SupportedActions = new List<EndpointActions>
{
EndpointActions.Get
},
PropertyKeys = new List<string>
{
"BounceID"
}
}},
};
}
}
76 changes: 52 additions & 24 deletions PluginJira/API/Utility/EndpointHelperEndpoints/IssuesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,66 @@ public override async IAsyncEnumerable<Record> ReadRecordsAsync(IApiClientFactor
// fetch all records
var jira = factory.CreateJiraClient(settings);

// var issues = jira.Issues.Queryable
// .Select(i => i)
// .GroupBy(i => i.Key);
var projectKey = settings.GetProject();

var issues = from i in jira.Issues.Queryable
select i;
// Adding logic for pagination
var itemsPerPage = 50;

// iterate and return each record
// foreach on results of JQL
foreach (var issue in issues)
var startAt = 0;

while (true)
{
var recordMap = new Dictionary<string, object>();
var issues = await jira.Issues.GetIssuesFromJqlAsync($"project = {projectKey} ORDER BY created DESC", itemsPerPage, startAt);

if (issues.Count() == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if blocks should always have curly braces

if (...)
{
    ...
}

{
break;
}

// iterate and return each record
// foreach on results of JQL
foreach (var issue in issues)
{
var recordMap = new Dictionary<string, object>();

// pull in all desired properties
recordMap["Key"] = issue.Key.Value;
recordMap["Project"] = issue.Project;
recordMap["Issuetype"] = issue.Type.Name;
recordMap["Description"] = issue.Description;
recordMap["Reporter"] = issue.ReporterUser.DisplayName;
recordMap["Created"] = issue.Created.Value;
recordMap["Status"] = issue.Status.Name;
recordMap["Resolution"] = issue.Resolution;
recordMap["Updated"] = issue.Updated.Value;
// pull in all desired properties
recordMap["Key"] = Convert.ToString(issue.Key.Value);
recordMap["Project"] = Convert.ToString(issue.Project);
recordMap["Issuetype"] = Convert.ToString(issue.Type.Name);
recordMap["Description"] = Convert.ToString(issue.Description);
recordMap["Reporter"] = Convert.ToString(issue.ReporterUser.DisplayName);
recordMap["Created"] = Convert.ToString(issue.Created.Value);
recordMap["Status"] = Convert.ToString(issue.Status.Name);
recordMap["Resolution"] = Convert.ToString(issue.Resolution);
recordMap["Updated"] = Convert.ToString(issue.Updated.Value);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra new line

yield return new Record
{
Action = Record.Types.Action.Upsert,
DataJson = JsonConvert.SerializeObject(recordMap)
};
}

yield return new Record
{
Action = Record.Types.Action.Upsert,
DataJson = JsonConvert.SerializeObject(recordMap)
};
startAt += itemsPerPage;
}
}

public override async Task<Count> GetCountOfRecords(IApiClientFactory factory, Settings settings)
{
var jira = factory.CreateJiraClient(settings);

var projectKey = settings.GetProject();

var issues = await jira.Issues.GetIssuesFromJqlAsync($"project = {projectKey} ORDER BY created DESC");

var total = issues.TotalItems;

return new Count
{
Kind = Count.Types.Kind.Exact,
Value = (int) total
};
}
}

public static readonly Dictionary<string, Endpoint> IssuesEndpoints = new Dictionary<string, Endpoint>
Expand Down
45 changes: 45 additions & 0 deletions PluginJira/DataContracts/ApplicationEndpointWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace PluginJira.DataContracts
{
public class ApplicationEndpointWrapper
{
[JsonProperty("key")]
public string Key { get; set; }

[JsonProperty("groups")]
public List<string> Groups { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("defaultGroups")]
public List<string> DefaultGroups { get; set; }

[JsonProperty("selectedByDefault")]
public bool SelectedByDefault { get; set; }

[JsonProperty("defined")]
public bool Defined { get; set; }

[JsonProperty("numberOfSeats")]
public long NumberOfSeats { get; set; }

[JsonProperty("remainingSeats")]
public long RemainingSeats { get; set; }

[JsonProperty("userCount")]
public long UserCount { get; set; }

[JsonProperty("userCountDescription")]
public string UserCountDescription { get; set; }

[JsonProperty("hasUnlimitedSeats")]
public bool HasUnlimitedSeats { get; set; }

[JsonProperty("platform")]
public bool Platform { get; set; }

}
}
13 changes: 0 additions & 13 deletions PluginJira/DataContracts/DataWrapper.cs

This file was deleted.

14 changes: 12 additions & 2 deletions PluginJira/Helper/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace PluginJira.Helper
{
public class Settings
{

public string Username { get; set; }
public string ApiKey { get; set; }
public string Tenant { get; set; }
public string Project { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make this a List to allow multiple projects to be selected in one connection


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra new line

/// <summary>
/// Validates the settings input object
Expand All @@ -30,7 +30,12 @@ public void Validate()
throw new Exception("The Api Key property must be set");
}

if (string.IsNullOrWhiteSpace(Tenant))
if (string.IsNullOrWhiteSpace(Tenant))
{
throw new Exception("The Tenant is not set properly");
}

if (string.IsNullOrWhiteSpace(Project))
{
throw new Exception("The Tenant is not set properly");
}
Expand All @@ -45,5 +50,10 @@ public string GetBaseUri()
{
return $"https://{Tenant}.atlassian.net/rest/api/2";
}

public string GetProject()
{
return $"{Project}";
}
}
}
Loading