Skip to content

Commit ae41ce8

Browse files
committed
Improved pr closing and stuff
1 parent 7ccc054 commit ae41ce8

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

WebOptimizationProject/WopRepoManager.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using DeveCoolLib.Logging;
33
using Octokit;
44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
67
using System.Threading.Tasks;
78
using WebOptimizationProject.Configuration;
@@ -25,6 +26,68 @@ public void Start()
2526
{
2627
var consoleMenu = new ConsoleMenu(ConsoleMenuType.StringInput);
2728

29+
consoleMenu.MenuOptions.Add(new ConsoleMenuOption("Remove all my forks and close their active PR's", new Action(() =>
30+
{
31+
var myUser = _gitOctoKitHandler.GitHubClient.User.Current().Result;
32+
var myReposAll = _gitOctoKitHandler.GitHubClient.Repository.GetAllForCurrent().Result;
33+
var myReposTemp = myReposAll.Where(t => t.Fork).ToList();
34+
35+
Console.WriteLine("Actions to execute:");
36+
37+
var prDict = new Dictionary<Repository, List<PullRequest>>();
38+
39+
foreach (var repo in myReposTemp)
40+
{
41+
var prsHereList = new List<PullRequest>();
42+
var thisRepo = _gitOctoKitHandler.GitHubClient.Repository.Get(repo.Id).Result;
43+
prDict.Add(thisRepo, prsHereList);
44+
45+
var prsHere = _gitOctoKitHandler.GitHubClient.PullRequest.GetAllForRepository(thisRepo.Parent.Id).Result;
46+
var prsFiltered = prsHere.Where(t => t.State.Value == ItemState.Open && t.User.Id == myUser.Id).ToList();
47+
foreach (var pr in prsHere)
48+
{
49+
Console.WriteLine($"\tClose:\t{pr.HtmlUrl} ({pr.State})");
50+
prsHereList.Add(pr);
51+
}
52+
53+
Console.WriteLine($"\tDelete:\t{repo.FullName}");
54+
}
55+
56+
var consMenuRemoveRepos = new ConsoleMenu(ConsoleMenuType.StringInput);
57+
58+
consMenuRemoveRepos.MenuOptions.Add(new ConsoleMenuOption("Yes", new Action(() =>
59+
{
60+
foreach (var kvp in prDict)
61+
{
62+
var repo = kvp.Key;
63+
foreach (var pr in kvp.Value)
64+
{
65+
Console.Write($"Closing: {pr.HtmlUrl} ");
66+
var up = new PullRequestUpdate()
67+
{
68+
State = ItemState.Closed
69+
};
70+
_gitOctoKitHandler.GitHubClient.PullRequest.Update(repo.Parent.Id, pr.Number, up).Wait();
71+
Console.WriteLine("Done");
72+
}
73+
74+
Console.Write($"Removing: {repo.FullName} ");
75+
_gitOctoKitHandler.GitHubClient.Repository.Delete(repo.Id).Wait();
76+
Console.WriteLine("Done");
77+
}
78+
})));
79+
80+
consMenuRemoveRepos.MenuOptions.Add(new ConsoleMenuOption("No", new Action(() =>
81+
{
82+
83+
})));
84+
85+
Console.WriteLine();
86+
Console.WriteLine("Are you sure you want to remove all these repositories?");
87+
consMenuRemoveRepos.RenderMenu();
88+
consMenuRemoveRepos.WaitForResult();
89+
})));
90+
2891
consoleMenu.MenuOptions.Add(new ConsoleMenuOption("Remove all my forks", new Action(() =>
2992
{
3093
var myReposAll = _gitOctoKitHandler.GitHubClient.Repository.GetAllForCurrent().Result;

0 commit comments

Comments
 (0)