Skip to content

WIP: Issues should be added to Examine for better performance #357

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion OurUmbraco.Site/Views/Dashboard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
<small>
@{
var dateCssClass = string.Empty;
var businessDays = issue.CreateDateTime.ToLocalTime().BusinessDaysSince();
var businessDays = issue.CreateDateTime.ToLocalTime().DateTime.BusinessDaysSince();
}
@if (category.CategoryKey == RepositoryManagementService.CategoryKey.NoReply)
{
Expand Down
9 changes: 5 additions & 4 deletions OurUmbraco/Our/Api/IssuesStatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OurUmbraco.Our.Extensions;
using OurUmbraco.Our.Models;
using OurUmbraco.Our.Services;
using Skybrud.Social.GitHub.Models.Issues;
using Umbraco.Web.WebApi;

namespace OurUmbraco.Our.Api
Expand Down Expand Up @@ -58,24 +59,24 @@ public List<IssuesInPeriod> GetGroupedIssuesData(int fromDay, int fromMonth, int

foreach (var issue in allCommunityIssues)
{
if (issue.CreateDateTime <= periodLastDay && issue.State != "closed")
if (issue.CreateDateTime <= periodLastDay && issue.State != GitHubIssueState.Closed)
issuesList.NumberOpen = issuesList.NumberOpen + 1;
}

var allClosingTimesInHours = new List<double>();
foreach (var issue in issuesInPeriod.Value)
{
if (issue.State == "closed" && issue.ClosedDateTime.HasValue)
if (issue.State == GitHubIssueState.Closed && issue.ClosedDateTime != null)
{
var createDateTime = issue.CreateDateTime;
var closedDateTime = issue.ClosedDateTime.Value;
var closedDateTime = issue.ClosedDateTime;

if (closedDateTime < periodFirstDay || closedDateTime > periodLastDay)
continue;

issuesList.NumberClosed = issuesList.NumberClosed + 1;

var hoursOpen = createDateTime.BusinessHoursUntil(closedDateTime);
var hoursOpen = createDateTime.DateTime.BusinessHoursUntil(closedDateTime.DateTime);
allClosingTimesInHours.Add(hoursOpen);
}
}
Expand Down
67 changes: 36 additions & 31 deletions OurUmbraco/Our/Models/GitHub/Issue.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Time;
using Skybrud.Social.GitHub.Models.Issues;
using Skybrud.Social.GitHub.Models.Labels;
using Skybrud.Social.GitHub.Models.Users;

namespace OurUmbraco.Our.Models.GitHub
{
public class Issue
{
[JsonProperty("html_url")]
public string Link { get; set; }

[JsonProperty("number")]
public int Number { get; set; }
private readonly GitHubIssue _issue;
private Comments[] _comments;
private Event[] _events;

[JsonProperty("title")]
public string Title { get; set; }
public string Link => _issue.Urls.HtmlUrl;

[JsonProperty("user")]
public User User { get; set; }
public int Number => _issue.Number;

[JsonProperty("labels")]
public Label[] Labels { get; set; }
public string Title => _issue.Title;

[JsonProperty("state")]
public string State { get; set; }
public GitHubUserItem User => _issue.User;

[JsonProperty("assignees")]
public User[] Assignees { get; set; }
public GitHubLabel[] Labels => _issue.Labels;

[JsonProperty("comments")]
public int CommentCount { get; set; }
public GitHubIssueState State => _issue.State;

[JsonProperty("created_at")]
public DateTime CreateDateTime { get; set; }
public GitHubUserItem[] Assignees => _issue.Assignees;

[JsonProperty("updated_at")]
public DateTime UpdateDateTime { get; set; }
public int CommentCount => _issue.Comments;

[JsonProperty("closed_at")]
public DateTime? ClosedDateTime { get; set; }
public EssentialsDateTime CreateDateTime => _issue.CreatedAt;

[JsonProperty("body")]
public string Description { get; set; }
public EssentialsDateTime UpdateDateTime => _issue.UpdatedAt;

[JsonProperty("_comments")]
public Comments[] Comments { get; set; }
public EssentialsDateTime ClosedDateTime => _issue.ClosedAt;

[JsonProperty("events")]
public Event[] Events { get; set; }
public string Description => _issue.Body;

public Comments[] Comments => _comments ?? (_comments = _issue.JObject.Value<Comments[]>("comments"));

public Event[] Events => _events ?? (_events = _issue.JObject.Value<Event[]>("events"));

// Custom properties

public string RepositoryName { get; set; }
public string RepositoryName => Link.Split('/')[4];

public DateTime? FirstPrTeamOrHqComment { get; set; }

public DateTime? InThisCategorySince { get; set; }

public bool NeedsTeamUmbracoReply { get; set; }

protected Issue(JObject obj) {
_issue = GitHubIssue.Parse(obj);
}

public static Issue Parse(JObject obj) {
return obj == null ? null : new Issue(obj);
}

// Note: leaving the other properties commented out in case we need them later

Expand All @@ -69,5 +72,7 @@ public class Issue
//public User assignee { get; set; }
//public object milestone { get; set; }
//public string author_association { get; set; }

}
}

}
22 changes: 22 additions & 0 deletions OurUmbraco/Our/Models/GitHub/PullRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json.Linq;

namespace OurUmbraco.Our.Models.GitHub
{

public class PullRequest : Issue
{

public PullRequest(JObject obj) : base(obj)
{


}

public new static PullRequest Parse(JObject obj)
{
return obj == null ? null : new PullRequest(obj);
}

}

}
3 changes: 2 additions & 1 deletion OurUmbraco/Our/Services/ReleasesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using OurUmbraco.Our.Extensions;
using OurUmbraco.Our.Models;
using OurUmbraco.Our.Models.GitHub;
using Skybrud.Social.GitHub.Models.Issues;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web;
Expand Down Expand Up @@ -205,7 +206,7 @@ private static void AddItemsToReleases(PerformContext context, List<Release> rel
if (stateLabel != null)
// if there's a label with a state then use that as the state
state = stateLabel.Name.Replace("state/", string.Empty);
else if (item.State == "closed" && item.Labels.Any(x => x.Name.StartsWith("release")))
else if (item.State == GitHubIssueState.Closed && item.Labels.Any(x => x.Name.StartsWith("release")))
// there is no state label applied
// if the item is closed and has a release label on it then we set it to fixed
state = "fixed";
Expand Down
13 changes: 7 additions & 6 deletions OurUmbraco/Our/Services/RepositoryManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Newtonsoft.Json;
using OurUmbraco.Community.GitHub;
using OurUmbraco.Our.Models.GitHub;
using Skybrud.Essentials.Json;
using Skybrud.Social.GitHub.Models.Issues;
using Skybrud.Social.GitHub.Models.Labels;
using Umbraco.Core;

namespace OurUmbraco.Our.Services
Expand Down Expand Up @@ -44,15 +47,13 @@ public List<Issue> GetAllCommunityIssues(bool pulls)

foreach (var file in issueFiles)
{
var fileContent = File.ReadAllText(file);
var item = JsonConvert.DeserializeObject<Issue>(fileContent);

Issue item = pulls ? JsonUtils.LoadJsonObject(file, PullRequest.Parse) : JsonUtils.LoadJsonObject(file, Issue.Parse);

// Exclude issues created by HQ
if (hqMembers.Contains(item.User.Login.ToLowerInvariant()))
continue;

item.RepositoryName = repositoryName;

foreach (var comment in item.Comments)
{
var commenter = comment.User.Login.ToLowerInvariant();
Expand Down Expand Up @@ -101,7 +102,7 @@ public List<GitHubCategorizedIssues> GetAllOpenIssues(bool pulls)

foreach (var item in allIssues)
{
if (item.State == "closed")
if (item.State == GitHubIssueState.Closed)
continue;

var pullRequestService = new GitHubService();
Expand Down Expand Up @@ -223,7 +224,7 @@ public List<GitHubCategorizedIssues> GetAllOpenIssues(bool pulls)
return openIssues.OrderBy(x => x.SortOrder).ToList();
}

private static void AddCategoryCreatedDate(Issue item, Models.GitHub.Label label, string[] labelNames)
private static void AddCategoryCreatedDate(Issue item, GitHubLabel label, string[] labelNames)
{
if (item.Events != null)
{
Expand Down
1 change: 1 addition & 0 deletions OurUmbraco/OurUmbraco.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@
<Compile Include="Our\Models\GitHub\Comment.cs" />
<Compile Include="Our\Models\GitHub\Issue.cs" />
<Compile Include="Our\Models\GitHub\Label.cs" />
<Compile Include="Our\Models\GitHub\PullRequest.cs" />
<Compile Include="Our\Models\GitHub\User.cs" />
<Compile Include="Our\Models\PullRequestContributor.cs" />
<Compile Include="Our\Models\IssuesInPeriod.cs" />
Expand Down