Example #1
0
        public static void HandleUser(User user)
        {
            if (user == null)
            {
                return;
            }

            using (var db = new RFCContext()) {
                var existing = db.Users.Where(u => u.GithubUserId == user.Id).FirstOrDefault();
                if (existing != null)
                {
                    db.Entry(existing).CurrentValues.SetValues(user.Id);
                }
                else
                {
                    db.Users.Add(new GithubUser()
                    {
                        GithubUserId = user.Id, Login = user.Login
                    });
                }

                var xx = db.SaveChanges();
                Console.WriteLine(xx);
            }
        }
Example #2
0
        public static void HandleIssue(Octokit.Issue issue, long repo)
        {
            HandleUser(issue.User);

            bool IsSame(Issue i)
            {
                return(i.Number == issue.Number && i.Repository == repo);
            }

            using (var db = new RFCContext()) {
                var existing = db.Issues.Where(IsSame).FirstOrDefault();
                if (existing != null)
                {
                    db.Entry(existing).CurrentValues.SetValues(issue.ToDBIssue(existing, repo));
                }
                else
                {
                    existing = new Issue();
                    issue.ToDBIssue(existing, repo);
                    db.Issues.Add(existing);
                }

                db.SaveChanges();
            }
        }
Example #3
0
 public static void HandleComment(IssueComment comment, long repo)
 {
     HandleUser(comment.User);
     Console.WriteLine(comment.HtmlUrl);
     using (var db = new RFCContext()) {
         var existing = db.IssueComments.Where(c => c.Id == comment.Id).FirstOrDefault();
         if (existing != null)
         {
             db.Entry(existing).CurrentValues.SetValues(comment.ToDBIssueComment(existing, repo));
             db.SaveChanges();
         }
         else
         {
             existing = new Issuecomment();
             comment.ToDBIssueComment(existing, repo);
             db.IssueComments.Add(existing);
             db.SaveChanges();
             Nag.UpdateNags(existing, repo);
         }
     }
 }
Example #4
0
        public static void HandlePr(Octokit.PullRequest pr, long repo)
        {
            if (pr.Assignee != null)
            {
                HandleUser(pr.Assignee);
            }

            using (var db = new RFCContext()) {
                var existing = db.PullRequests.Where(c => c.Id == pr.Id).FirstOrDefault();
                if (existing != null)
                {
                    db.Entry(existing).CurrentValues.SetValues(pr.ToDBPullRequest(existing, repo));

                    // we need to check and see if this has been merged and if so then we need to rename the file to the proper magic number?
                    // essentially look of for the rfc file and rename it ?
                    if (pr.Merged)
                    {
                        Console.WriteLine("We have merged a PR we care about?");


                        var rc             = GitClient.GH.Value.client.Repository.Branch.Get(repo, "main").Result;
                        var commit         = GitClient.GH.Value.client.Git.Commit.Get(repo, rc.Commit.Sha).Result;
                        var rootTree       = GitClient.GH.Value.client.Git.Tree.GetRecursive(repo, commit.Sha).Result;
                        var textsTree      = rootTree.Tree.Where(x => x.Path == "texts").SingleOrDefault();
                        var allCurrentRFCs = GitClient.GH.Value.client.Git.Tree.Get(repo, textsTree.Sha).Result;
                        var newTextsTree   = new NewTree();
                        allCurrentRFCs.Tree
                        .ToList().ForEach(x => newTextsTree.Tree.Add(new NewTreeItem
                        {
                            Mode = x.Mode,
                            Path = x.Path,
                            Sha  = x.Sha,
                            Type = x.Type.Value
                        }));

                        var newRFCs = allCurrentRFCs.Tree.Where(x => x.Path.Contains("0000-")).ToList();

                        if (newRFCs.Count() != 0)
                        {
                            Console.WriteLine($"We have merged {newRFCs.Count()} RFC/RFAs");
                            string fmt = "0000.##";

                            foreach (var item in newRFCs)
                            {
                                var nextValue = db.GetNextSequenceValue("rfcnext");

                                var newPath = item.Path;
                                newTextsTree.Tree.Remove(newTextsTree.Tree.Where(x => x.Path == item.Path).First());
                                newTextsTree.Tree.Add(new NewTreeItem
                                {
                                    Path = newPath.Replace("0000-", $"{nextValue.ToString(fmt)}-"),
                                    Mode = "100644",
                                    Type = TreeType.Blob,
                                    Sha  = item.Sha
                                });
                                ;
                            }
                        }

                        var newTextsTreeStatePhase =
                            GitClient.GH.Value.client.Git.Tree.Create(repo, newTextsTree).Result;

                        var newRoot = new NewTree();

                        rootTree.Tree
                        .Where(x => !x.Path.Contains("texts/"))
                        .ToList().ForEach(x => newRoot.Tree.Add(new NewTreeItem
                        {
                            Mode = x.Mode,
                            Path = x.Path,
                            Sha  = x.Path == "texts" ? newTextsTreeStatePhase.Sha : x.Sha,
                            Type = x.Type.Value
                        }));

                        var newTextsTreeStatePhaseTwo =
                            GitClient.GH.Value.client.Git.Tree.Create(repo, newRoot).Result;

                        var newCommit = new NewCommit("Updating RFC Numbers", newTextsTreeStatePhaseTwo.Sha,
                                                      commit.Sha);
                        var latestCommit = GitClient.GH.Value.client.Git.Commit.Create(repo, newCommit).Result;
                        var result       = GitClient.GH.Value.client.Git.Reference.Update(repo, $"heads/{"main"}",
                                                                                          new ReferenceUpdate(latestCommit.Sha)).Result;

                        Console.WriteLine("Updated all new RFCs to new values");
                    }
                }
                else
                {
                    // this is a new PR should we auto create a RFC Merge?
                    existing = new PullRequest();
                    pr.ToDBPullRequest(existing, repo);
                    db.PullRequests.Add(existing);

                    // we should label?
                    var r      = GitClient.GH.Value.GetRepo(repo).Result;
                    var labels = Teams.SETUP.Value.DefaultIssueLabels(r.FullName);
                    foreach (var l in labels)
                    {
                        GitClient.GH.Value.AddIssueLabel(repo, pr.Number, l);
                        Thread.Sleep(TimeSpan.FromMilliseconds(1390));
                    }

                    if (Teams.SETUP.Value.ShouldAutoCreateMerge(r.FullName))
                    {
                        _ = GitClient.GH.Value.AddIssueComment(repo, pr.Number, "@rfcbot merge").Result;
                    }
                }

                db.SaveChanges();
            }
        }