Skip to content

Commit

Permalink
Started working on a Github Integration for Issue Tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
omegaleo committed Nov 26, 2023
1 parent c0fb2c0 commit f943ff3
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 0 deletions.
148 changes: 148 additions & 0 deletions Editor/Models/Issue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OmegaLeo.Toolbox.Editor.Settings;
using OmegaLeo.Toolbox.Runtime.Extensions;
using UnityEditor;
using UnityEngine;

namespace OmegaLeo.Toolbox.Editor.Models
{
public class Issue
{
public string Title { get; set; }
public string Body { get; set; }
public List<Label> Labels { get; set; }

public string Html_Url { get; set; }
public string Url { get; set; }
public int Number { get; set; }

public void GenerateIssueBox()
{
var headerStyle = new GUIStyle(GUI.skin.label);
headerStyle.fontStyle = FontStyle.Bold;
headerStyle.normal.textColor = Color.white;

var bodyStyle = new GUIStyle(GUI.skin.label);
bodyStyle.normal.textColor = Color.white;
bodyStyle.stretchHeight = true;
bodyStyle.wordWrap = true;

EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField(Title, headerStyle);

if (Body.IsNotNullOrEmpty())
{
EditorGUILayout.LabelField(Body.Replace("\n", Environment.NewLine), bodyStyle);
}

EditorGUILayout.BeginHorizontal();
foreach (var label in Labels)
{
label.GenerateLabel();
}
EditorGUILayout.EndHorizontal();

EditorGUILayout.EndVertical();
}

public bool CanGoBack()
{
var order = GithubSettingsProvider.GithubTagOrder.Split(',').ToList();

var value = false;

foreach (var label in Labels)
{
if (order.Any(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)))
{
if (order.FindIndex(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)) > 0)
{
return true;
}
}
}

return false;
}

public void GoBack()
{
var order = GithubSettingsProvider.GithubTagOrder.Split(',').ToList();

var nextValue = "";
var labelToReplace= Labels.FirstOrDefault();

foreach (var label in Labels)
{
if (order.Any(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)))
{
var currentOrder = order.FindIndex(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase));
var nextOrder = currentOrder - 1;
nextValue = order[nextOrder];
labelToReplace = label;
}
}

Labels = Labels.Replace(labelToReplace, new Label() { Color = "", Name = nextValue }).ToList();
}

public void GoForward()
{
var order = GithubSettingsProvider.GithubTagOrder.Split(',').ToList();

var nextValue = "";
var labelToReplace= Labels.FirstOrDefault();

foreach (var label in Labels)
{
if (order.Any(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)))
{
var currentOrder = order.FindIndex(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase));
var nextOrder = currentOrder + 1;
nextValue = order[nextOrder];
labelToReplace = label;
}
}

Labels = Labels.Replace(labelToReplace, new Label() { Color = "", Name = nextValue }).ToList();
}

public bool CanGoForward()
{
var order = GithubSettingsProvider.GithubTagOrder.Split(',').ToList();

var value = false;

foreach (var label in Labels)
{
if (order.Any(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)))
{
if (order.FindIndex(x => x.Equals(label.Name, StringComparison.OrdinalIgnoreCase)) < order.Count)
{
return true;
}
}
}

return false;
}
}

public class Label
{
public string Name { get; set; }
public string Color { get; set; }

public void GenerateLabel()
{
GUIStyle style = new GUIStyle(GUI.skin.label);
var color = $"#{Color}";
style.normal.textColor = color.ColorFromHex();

EditorGUILayout.LabelField(Name, style);
}
}
}
3 changes: 3 additions & 0 deletions Editor/Models/Issue.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/Settings.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions Editor/Settings/GithubSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace OmegaLeo.Toolbox.Editor.Settings
{
public class GithubSettingsProvider : SettingsProvider
{
private const string TOKEN_OPTION_PREF = "GithubToken";
private const string USERNAME_OPTION_PREF = "GithubUsername";
private const string REPOSITORY_OPTION_PREF = "GithubRepo";
private const string TAG_FILTER_OPTION_PREF = "GithubTagFilter";
private const string TAG_ORDER_OPTION_PREF = "GithubTagOrder";

public static string GithubToken
{
get
{
return EditorPrefs.GetString(TOKEN_OPTION_PREF);
}
set
{
EditorPrefs.SetString(TOKEN_OPTION_PREF, value);
}
}

public static string GithubUsername
{
get
{
return EditorPrefs.GetString(USERNAME_OPTION_PREF);
}
set
{
EditorPrefs.SetString(USERNAME_OPTION_PREF, value);
}
}

public static string GithubRepo
{
get
{
return EditorPrefs.GetString(REPOSITORY_OPTION_PREF);
}
set
{
EditorPrefs.SetString(REPOSITORY_OPTION_PREF, value);
}
}

public static string GithubTagFilter
{
get
{
return EditorPrefs.GetString(TAG_FILTER_OPTION_PREF);
}
set
{
EditorPrefs.SetString(TAG_FILTER_OPTION_PREF, value);
}
}

public static string GithubTagOrder
{
get
{
return EditorPrefs.GetString(TAG_ORDER_OPTION_PREF);
}
set
{
EditorPrefs.SetString(TAG_ORDER_OPTION_PREF, value);
}
}

public GithubSettingsProvider(string path, SettingsScope scopes, IEnumerable<string> keywords = null) : base(path, scopes, keywords)
{
}

public override void OnGUI(string searchContext)
{
base.OnGUI(searchContext);

GUILayout.Space(20f);

string token = GithubToken;
string value = EditorGUILayout.PasswordField("Token", token);

if (!token.Equals(value))
{
GithubToken = value;
}

string username = GithubUsername;
string value1 = EditorGUILayout.TextField("Username", username);

if (!username.Equals(value1))
{
GithubUsername = value1;
}

string repo = GithubRepo;
string value2 = EditorGUILayout.TextField("Repository", repo);

if (!repo.Equals(value2))
{
GithubRepo = value2;
}

string tags = GithubTagFilter;
string value3 = EditorGUILayout.TextField("Tags to show (Comma Separated)", tags);

if (!tags.Equals(value3))
{
GithubTagFilter = value3;
}

string tagOrder = GithubTagOrder;
string value4 = EditorGUILayout.TextField("Tag Order (Comma Separated)", tagOrder);

if (!tagOrder.Equals(value4))
{
GithubTagOrder = value4;
}
}

[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
return new GithubSettingsProvider("Omega Leo/Github Integration", SettingsScope.Project);
}
}
}
3 changes: 3 additions & 0 deletions Editor/Settings/GithubSettingsProvider.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f943ff3

Please sign in to comment.