Skip to content

Commit

Permalink
[Tools] [JiraReporting] made it more flexible with JQL input as a par…
Browse files Browse the repository at this point in the history
…ameter
  • Loading branch information
leandromonaco committed May 10, 2022
1 parent 8e9c60c commit 939322f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Tools/src/JiraReporting/JiraReporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 6 additions & 8 deletions Tools/src/JiraReporting/Model/Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ public class Fields
public IssueType IssueType { get; set; }
public Assignee Assignee { get; set; }

[JsonPropertyName("customfield_10263")]
public Severity Severity { get; set; }

[JsonPropertyName("customfield_10018")]
public Priority Priority { get; set; }

//TODO: Make this customizable
[JsonPropertyName("customfield_10020")]
public List<Sprint> Sprints { get; set; }

[JsonPropertyName("customfield_10281")]
public Points Points { get; set; }
[JsonPropertyName("customfield_10026")]
public double? Points { get; set; }

[JsonPropertyName("customfield_10283")]
public RaidType RaidType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace JiraReporting.Model
{
public class Points
public class Priority
{
public string Value { get; set; }
}
Expand Down
7 changes: 0 additions & 7 deletions Tools/src/JiraReporting/Model/Severity.cs

This file was deleted.

10 changes: 3 additions & 7 deletions Tools/src/JiraReporting/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ public class Options
[Option("JiraEndpoint", Required = true, HelpText = "JIRA Endpoint")]
public string JiraEndpoint { get; set; }

[Option("JiraProject", Required = true, HelpText = "JIRA Project")]
public string JiraProject { get; set; }
[Option("JQL", Required = true, HelpText = "JIRA Query Language (https://support.atlassian.com/jira-software-cloud/docs/use-advanced-search-with-jira-query-language-jql/)")]
public string JQL { get; set; }

[Option("JiraUsername", Required = true, HelpText = "JIRA Username")]
public string JiraUsername { get; set; }

[Option("JiraAuthenticationToken", Required = true, HelpText = "JIRA Authentication Token")]
[Option("JiraAuthenticationToken", Required = true, HelpText = "JIRA Authentication Token (https://id.atlassian.com/manage-profile/security/api-tokens)")]
public string JiraAuthenticationToken { get; set; }

[Option("PowerBiDatasetEndpoint", Required = true, HelpText = "PowerBI Endpoint")]
public string PowerBiDatasetEndpoint { get; set; }

}
}
27 changes: 13 additions & 14 deletions Tools/src/JiraReporting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static void Main(string[] args)
Parser.Default.ParseArguments<Options>(args)
.WithParsed(o =>
{
ExecuteJob(o.JiraEndpoint, o.JiraProject, o.JiraUsername, o.JiraAuthenticationToken, o.PowerBiDatasetEndpoint);
//ExecuteJob(o.JiraEndpoint, o.JiraProject, o.JiraUsername, o.JiraAuthenticationToken, o.PowerBiDatasetEndpoint);
ExecuteJob(o.JiraEndpoint, o.JQL, o.JiraUsername, o.JiraAuthenticationToken);
//RecurringJob.AddOrUpdate("JiraReportJob",
// () => ExecuteJob(o.JiraEndpoint, o.JiraProject, o.JiraUsername, o.JiraAuthenticationToken, o.PowerBiDatasetEndpoint),
// Cron.Hourly);
Expand All @@ -33,7 +34,7 @@ static void Main(string[] args)
Console.ReadLine();
}

public static void ExecuteJob(string jiraEndpoint, string jiraProject, string jiraUsername, string jiraAuthenticationToken, string powerBiDatasetEndpoint)
public static void ExecuteJob(string jiraEndpoint, string jql, string jiraUsername, string jiraAuthenticationToken)
{
Console.WriteLine($"Jira Report started {DateTime.Now}");

Expand Down Expand Up @@ -73,24 +74,22 @@ public static void ExecuteJob(string jiraEndpoint, string jiraProject, string ji
while (startAt <= finishAt)
{
var query = $@"{{
""jql"": ""project={jiraProject}"",
""jql"": ""{jql}"",
""maxResults"": {increment},
""startAt"": {startAt}
}}";

var response = httpConnector.PostAsync($"{jiraEndpoint}/rest/api/2/search", query).Result;
var jqlQueryResult = JsonSerializer.Deserialize<JqlQueryResult>(response, jsonSerializerOptions);

Console.WriteLine($"Processing {startAt} of {jqlQueryResult.Total} {DateTime.Now}");

startAt += increment;
finishAt = jqlQueryResult.Total - 1;

foreach (var issue in jqlQueryResult.Issues)
{
var issueType = issue.Fields.IssueType.Name;
if (issueType.Equals("RAID") && !string.IsNullOrEmpty(issue.Fields.RaidType?.Value))
{
issueType = issue.Fields.RaidType?.Value;
}

var row = new BacklogItem
{
Expand All @@ -101,9 +100,9 @@ public static void ExecuteJob(string jiraEndpoint, string jiraProject, string ji
EpicId = issue.Fields.Parent?.Key,
EpicTitle = issue.Fields.Parent?.Fields.Summary,
IssueType = issueType,
Severity = issue.Fields.Severity?.Value,
Priority = issue.Fields.Priority?.Value,
Status = issue.Fields.Status.Name,
Points = issue.Fields.Points?.Value,
Points = Convert.ToInt32(issue.Fields.Points),
AssignedTo = issue.Fields.Assignee == null ? "Unassigned" : issue.Fields.Assignee.DisplayName
};

Expand Down Expand Up @@ -137,13 +136,13 @@ public static void ExecuteJob(string jiraEndpoint, string jiraProject, string ji
var outputFile = $"{Environment.CurrentDirectory}\\report_{DateTime.Now.Date.ToString(dateFormat)}";

ExcelHelper.Export(latestBacklog, null, $"{outputFile}.xlsx", jiraEndpoint);
ExcelHelper.Export(changedStories, null, $"ChangedStories.xlsx", jiraEndpoint);
ExcelHelper.Export(changedBugs, null, $"ChangedBugs.xlsx", jiraEndpoint);
ExcelHelper.Export(changedRaids, null, $"ChangedRaids.xlsx", jiraEndpoint);
//ExcelHelper.Export(changedStories, null, $"ChangedStories.xlsx", jiraEndpoint);
//ExcelHelper.Export(changedBugs, null, $"ChangedBugs.xlsx", jiraEndpoint);
//ExcelHelper.Export(changedRaids, null, $"ChangedRaids.xlsx", jiraEndpoint);

File.WriteAllText($"{outputFile}.json", JsonSerializer.Serialize(latestBacklog));

var result = httpConnector.PostAsync(powerBiDatasetEndpoint, JsonSerializer.Serialize(latestBacklog)).Result;
//var result = httpConnector.PostAsync(powerBiDatasetEndpoint, JsonSerializer.Serialize(latestBacklog)).Result;

Console.WriteLine($"Jira Report stopped {DateTime.Now}");
}
Expand Down
4 changes: 2 additions & 2 deletions Tools/src/JiraReporting/Report/BacklogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public BacklogItem()
public string IssueType { get; set; }
public string Sprint { get; set; }
public string Status { get; set; }
public string Points { get; set; }
public int Points { get; set; }
public string AssignedTo { get; set; }
public DateTime Date { get; set; }
public string IssueId { get; set; }
public string IssueTitle { get; set; }
public string Severity { get; set; }
public string Priority { get; set; }

}
}
2 changes: 1 addition & 1 deletion Tools/src/JiraReporting/Report/ExcelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void Export(List<BacklogItem> backlogItems, List<BacklogItem> newB

row.CreateCell(5).SetCellValue(backlogItem.IssueTitle);
row.CreateCell(6).SetCellValue(backlogItem.IssueType);
row.CreateCell(7).SetCellValue(backlogItem.Severity);
row.CreateCell(7).SetCellValue(backlogItem.Priority);
row.CreateCell(8).SetCellValue(backlogItem.Status);
row.CreateCell(9).SetCellValue(Convert.ToDouble(backlogItem.Points));
row.CreateCell(10).SetCellValue(backlogItem.AssignedTo);
Expand Down

0 comments on commit 939322f

Please sign in to comment.