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

Add p1 Issue query and separate issues by repo #56

Merged
merged 1 commit into from
Sep 30, 2021
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
17 changes: 17 additions & 0 deletions GithubIssueTagger/IssueUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ public static async Task<IEnumerable<Issue>> GetAllIssues(GitHubClient client, s
return issuesForMilestone;
}

public static async Task<IEnumerable<Issue>> GetOpenPriority1Issues(GitHubClient client, string org, string repo)
{
var nugetRepos = new RepositoryCollection();
nugetRepos.Add(org, repo);

var queryLabels = new string[] { "priority:1" };

var request = new SearchIssuesRequest()
{
Repos = nugetRepos,
State = ItemState.Open,
Labels = queryLabels
};
var issuesForMilestone = await client.Search.SearchIssues(request);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SearchIssues is a workaround for the other api we were using.
Had weird JSON deserialization issues, and found this bug: octokit/octokit.net#1762

return issuesForMilestone.Items;
}

/// <summary>
/// Get all the issues considered unprocessed. This means that either the issue does not have any labels, or only has the pipeline labels.
/// </summary>
Expand Down
98 changes: 71 additions & 27 deletions GithubIssueTagger/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Octokit;
using Newtonsoft.Json;
using Octokit;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -9,8 +11,10 @@ namespace GithubIssueTagger
public class Program
{
private static IList<Issue> _unprocessedIssues;
private static IReadOnlyList<Label> _allLabels;
private static IEnumerable<Issue> _allIssues;
private static IReadOnlyList<Label> _allHomeLabels;
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to add more to work for, but these statics make me cringe :)

It'd be neater if you were using return values/passed collections etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change really has nothing to do with the statics, but I simply had to split them into 2 collections. Someone can separately PR refactoring if we think that's needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, more of a general comment.

I might do the refactoring opportunistically if you don't mind.

private static IReadOnlyList<Label> _allClientEngineeringLabels;
private static IEnumerable<Issue> _allHomeIssues;
private static IEnumerable<Issue> _allClientEngineeringIssues;
private static GitHubClient _client;

static async Task Main(string[] args)
Expand Down Expand Up @@ -56,6 +60,8 @@ private static async Task PromptForQuery()
Console.WriteLine("2: " + nameof(AllLabels));
Console.WriteLine("3: " + nameof(AreaLabels));
Console.WriteLine("4: " + nameof(AreaOwnerReport));
Console.WriteLine("5: " + nameof(ClientEngineeringPriority1Issues));
Console.WriteLine("6: " + nameof(HomePriority1Issues));
}
while (null != await RunQueryOrReturnUnknownInput(Console.ReadLine()));
}
Expand Down Expand Up @@ -88,6 +94,16 @@ private static async Task<string> RunQueryOrReturnUnknownInput(string v)
Console.WriteLine(executedMethod + "***");
await AreaOwnerReport();
break;
case "5":
executedMethod = nameof(ClientEngineeringPriority1Issues);
Console.WriteLine(executedMethod + "***");
await ClientEngineeringPriority1Issues();
break;
case "6":
executedMethod = nameof(HomePriority1Issues);
Console.WriteLine(executedMethod + "***");
await HomePriority1Issues();
break;
case "quit":
return null;
default:
Expand All @@ -111,12 +127,12 @@ private static async Task AllUnprocessed()

private static async Task AllLabels()
{
if (_allLabels is null)
if (_allHomeLabels is null)
{
_allLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
_allHomeLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
}
Console.WriteLine("(ID\tName)");
foreach (var label in _allLabels)
foreach (var label in _allHomeLabels)
{
Console.WriteLine(label.Id + "\t" + label.Name);
}
Expand All @@ -134,53 +150,53 @@ private static async Task AreaLabels()

private static async Task AreaOwnerReport()
{
if (_allIssues is null)
if (_allHomeIssues is null)
{
_allIssues = await IssueUtilities.GetAllIssues(_client, "nuget", "home");
_allHomeIssues = await IssueUtilities.GetAllIssues(_client, "nuget", "home");
}

if (_allLabels is null)
if (_allHomeLabels is null)
{
_allLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
_allHomeLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
}

List<Label> ignoreLabels = new List<Label>()
{
//2671458320 Type:Tracking
_allLabels.SingleOrDefault(label => label.Id == 2671458320),
_allHomeLabels.SingleOrDefault(label => label.Id == 2671458320),

//801160517 Type: Spec
_allLabels.SingleOrDefault(label => label.Id == 801160517),
_allHomeLabels.SingleOrDefault(label => label.Id == 801160517),

//1593926950 Type: DeveloperDocs
_allLabels.SingleOrDefault(label => label.Id == 1593926950),
_allHomeLabels.SingleOrDefault(label => label.Id == 1593926950),

//249737088 Type: Docs
_allLabels.SingleOrDefault(label => label.Id == 249737088),
_allHomeLabels.SingleOrDefault(label => label.Id == 249737088),

//180116592 Type: Feature
_allLabels.SingleOrDefault(label => label.Id == 180116592),
_allHomeLabels.SingleOrDefault(label => label.Id == 180116592),

//2185215650 Type: Learning
_allLabels.SingleOrDefault(label => label.Id == 2185215650),
_allHomeLabels.SingleOrDefault(label => label.Id == 2185215650),
};

List<Label> validTypeLabels = new List<Label>()
{
//180116450 Type:Bug
_allLabels.SingleOrDefault(label => label.Id == 180116450),
_allHomeLabels.SingleOrDefault(label => label.Id == 180116450),

//386656158 Type: DataAnalysis
_allLabels.SingleOrDefault(label => label.Id == 386656158),
_allHomeLabels.SingleOrDefault(label => label.Id == 386656158),

//180970997 Type: DCR
_allLabels.SingleOrDefault(label => label.Id == 180970997),
_allHomeLabels.SingleOrDefault(label => label.Id == 180970997),

//979424473 Type: Test
_allLabels.SingleOrDefault(label => label.Id == 979424473),
_allHomeLabels.SingleOrDefault(label => label.Id == 979424473),
};

IEnumerable<Issue> includedIssues = _allIssues.Where(issue => !issue.Labels.Any(label => ignoreLabels.Any(ignoreLabel => ignoreLabel.Id == label.Id)));
IEnumerable<Issue> includedIssues = _allHomeIssues.Where(issue => !issue.Labels.Any(label => ignoreLabels.Any(ignoreLabel => ignoreLabel.Id == label.Id)));

//263262236 Functionality:VisualStudioUI = PM UI
Label pmuiLabel = await GetLabelById(263262236);
Expand Down Expand Up @@ -272,6 +288,34 @@ private static async Task AreaOwnerReport()
Console.WriteLine("Core\t" + coreIssues.Count() + GetUntypedIssueCountString(coreIssues, validTypeLabels));
}

private static async Task ClientEngineeringPriority1Issues()
{
if (_allClientEngineeringIssues is null)
{
_allClientEngineeringIssues = await IssueUtilities.GetOpenPriority1Issues(_client, "nuget", "client.engineering");
}

var outputFileName = "clientEngineeringIssues.json";
var json = JsonConvert.SerializeObject(_allClientEngineeringIssues, Formatting.Indented);
File.WriteAllText(outputFileName, json);

Console.WriteLine(nameof(ClientEngineeringPriority1Issues) + " wrote to " + outputFileName);
}

private static async Task HomePriority1Issues()
{
if (_allHomeIssues is null)
{
_allHomeIssues = await IssueUtilities.GetOpenPriority1Issues(_client, "nuget", "home");
}

var outputFileName = "homeIssues.json";
var json = JsonConvert.SerializeObject(_allHomeIssues, Formatting.Indented);
File.WriteAllText(outputFileName, json);

Console.WriteLine(nameof(HomePriority1Issues) + " wrote to " + outputFileName);
}

private static string GetUntypedIssueCountString(IEnumerable<Issue> issues, List<Label> validTypeLabels)
{
IEnumerable<long> validTypeLabelIds = validTypeLabels.Select(label => label.Id);
Expand All @@ -288,23 +332,23 @@ private static string GetUntypedIssueCountString(IEnumerable<Issue> issues, List
#region Helpers
private static async Task<IEnumerable<Label>> GetAreaLabels()
{
if (_allLabels is null)
if (_allHomeLabels is null)
{
_allLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
_allHomeLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
}

IEnumerable<Label> areaLabels = _allLabels?.Where(l => l.Name.StartsWith("Area:", StringComparison.OrdinalIgnoreCase));
IEnumerable<Label> areaLabels = _allHomeLabels?.Where(l => l.Name.StartsWith("Area:", StringComparison.OrdinalIgnoreCase));
return areaLabels;
}

private static async Task<Label> GetLabelById(long id)
{
if (_allLabels is null)
if (_allHomeLabels is null)
{
_allLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
_allHomeLabels = await LabelUtilities.GetLabelsForRepository(_client, "nuget", "home");
}

Label foundLabel = _allLabels?.SingleOrDefault(l => l.Id == id);
Label foundLabel = _allHomeLabels?.SingleOrDefault(l => l.Id == id);
return foundLabel;
}
#endregion
Expand Down