Skip to content

Commit

Permalink
Improved pr closing and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
devedse committed Aug 9, 2020
1 parent 7ccc054 commit ae41ce8
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions WebOptimizationProject/WopRepoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DeveCoolLib.Logging;
using Octokit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebOptimizationProject.Configuration;
Expand All @@ -25,6 +26,68 @@ public void Start()
{
var consoleMenu = new ConsoleMenu(ConsoleMenuType.StringInput);

consoleMenu.MenuOptions.Add(new ConsoleMenuOption("Remove all my forks and close their active PR's", new Action(() =>
{
var myUser = _gitOctoKitHandler.GitHubClient.User.Current().Result;
var myReposAll = _gitOctoKitHandler.GitHubClient.Repository.GetAllForCurrent().Result;
var myReposTemp = myReposAll.Where(t => t.Fork).ToList();

Console.WriteLine("Actions to execute:");

var prDict = new Dictionary<Repository, List<PullRequest>>();

foreach (var repo in myReposTemp)
{
var prsHereList = new List<PullRequest>();
var thisRepo = _gitOctoKitHandler.GitHubClient.Repository.Get(repo.Id).Result;
prDict.Add(thisRepo, prsHereList);

var prsHere = _gitOctoKitHandler.GitHubClient.PullRequest.GetAllForRepository(thisRepo.Parent.Id).Result;
var prsFiltered = prsHere.Where(t => t.State.Value == ItemState.Open && t.User.Id == myUser.Id).ToList();
foreach (var pr in prsHere)
{
Console.WriteLine($"\tClose:\t{pr.HtmlUrl} ({pr.State})");
prsHereList.Add(pr);
}

Console.WriteLine($"\tDelete:\t{repo.FullName}");
}

var consMenuRemoveRepos = new ConsoleMenu(ConsoleMenuType.StringInput);

consMenuRemoveRepos.MenuOptions.Add(new ConsoleMenuOption("Yes", new Action(() =>
{
foreach (var kvp in prDict)
{
var repo = kvp.Key;
foreach (var pr in kvp.Value)
{
Console.Write($"Closing: {pr.HtmlUrl} ");
var up = new PullRequestUpdate()
{
State = ItemState.Closed
};
_gitOctoKitHandler.GitHubClient.PullRequest.Update(repo.Parent.Id, pr.Number, up).Wait();
Console.WriteLine("Done");
}

Console.Write($"Removing: {repo.FullName} ");
_gitOctoKitHandler.GitHubClient.Repository.Delete(repo.Id).Wait();
Console.WriteLine("Done");
}
})));

consMenuRemoveRepos.MenuOptions.Add(new ConsoleMenuOption("No", new Action(() =>
{

})));

Console.WriteLine();
Console.WriteLine("Are you sure you want to remove all these repositories?");
consMenuRemoveRepos.RenderMenu();
consMenuRemoveRepos.WaitForResult();
})));

consoleMenu.MenuOptions.Add(new ConsoleMenuOption("Remove all my forks", new Action(() =>
{
var myReposAll = _gitOctoKitHandler.GitHubClient.Repository.GetAllForCurrent().Result;
Expand Down

0 comments on commit ae41ce8

Please sign in to comment.