-
Notifications
You must be signed in to change notification settings - Fork 0
Branch test 2 #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
1110982
28c30b6
4eacc64
a95fd49
8ae5328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
roehlerw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| yield return new Record | ||
| { | ||
| Action = Record.Types.Action.Upsert, | ||
| DataJson = JsonConvert.SerializeObject(recordMap) | ||
| }; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
| } | ||
| }}, | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if blocks should always have curly braces |
||
| { | ||
| 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); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
||
| 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; } | ||
|
|
||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra new line |
||
| /// <summary> | ||
| /// Validates the settings input object | ||
|
|
@@ -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"); | ||
| } | ||
|
|
@@ -45,5 +50,10 @@ public string GetBaseUri() | |
| { | ||
| return $"https://{Tenant}.atlassian.net/rest/api/2"; | ||
| } | ||
|
|
||
| public string GetProject() | ||
| { | ||
| return $"{Project}"; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.