Esempio n. 1
0
        private PullRequest FromPullRequest(OctokitPullRequest octokitPr)
        {
            if (octokitPr is null)
            {
                throw new ArgumentNullException(nameof(octokitPr));
            }

            return(new PullRequest
            {
                Number = octokitPr.Number,
                Id = octokitPr.Id,
                HtmlUrl = octokitPr.HtmlUrl,
                Submitter = new User
                {
                    Id = octokitPr.User.Id.ToString(),
                    Login = octokitPr.User.Login,
                    HtmlUrl = octokitPr.User.HtmlUrl,
                },
                Title = octokitPr.Title,
                Body = _bodyNormalizer.Normalize(octokitPr.Body)?.Trim(),
                State = octokitPr.State.ToString(),
                OpenedAt = octokitPr.CreatedAt,
                UpdatedAt = octokitPr.UpdatedAt,
                ClosedAt = octokitPr.ClosedAt ?? DateTimeOffset.MaxValue,
                MergedAt = octokitPr.MergedAt ?? DateTimeOffset.MaxValue,
            });
        }
        public OpenPullRequestMonitor(TimeSpan timespan, ItemState state=ItemState.Open)
        {
            var pollingPeriod = timespan.TotalMilliseconds;
            _timer = new Timer(pollingPeriod) {AutoReset = true};
            _timer.Elapsed += (sender, eventArgs) =>
            {
                var prs = 0;
                Task.Run(async () =>
                {
                    var requests = await PollGitHub(state);
                    prs = requests.Count;
                    _pr = requests.FirstOrDefault();
                    Console.WriteLine("Polled PR count:" + prs);
                }).Wait();

                if (prs > OpenPrs)
                {
                    var soundPlayer = new SoundPlayer("fanfare3.wav");
                    soundPlayer.PlaySync();
                    if (_pr != null)
                    {
                        var speech = new SpeechSynthesizer();
                        speech.Speak("New pull request.");
                        speech.Speak(_pr.Title);
                    }

                    OpenPrs = prs;
                }
                else if (prs < OpenPrs)
                {
                    OpenPrs = prs;
                }
            };
        }
Esempio n. 3
0
        public void ShouldGetPR()
        {
            var pr = new PullRequest(1337);
            GitHubClientMock.Setup(m => m.PullRequest.Get(_owner, _repo, _number))
                .Returns(() => Task.FromResult(pr));

            var vm = new PullRequestViewModel(_repo, _owner, _number);
            GitHubClientMock.Verify(m => m.PullRequest.Get(_owner,_repo,_number), Times.Once());
            Assert.AreEqual(pr, vm.PR);
        }
Esempio n. 4
0
        internal PullRequestItemViewModel(PullRequest pullRequest) 
        {
            PullRequest = pullRequest;

            var login = pullRequest?.User.Login ?? "Unknonwn User";
            var avatar = pullRequest?.User.AvatarUrl;
            Title = pullRequest.Title ?? "No Title";
            Avatar = new GitHubAvatar(avatar);
            Details = string.Format("#{0} opened {1} by {2}", pullRequest.Number, pullRequest.CreatedAt.UtcDateTime.Humanize(), login);
            GoToCommand = ReactiveCommand.Create();
        }
Esempio n. 5
0
        public IObservable<PullRequest> GetPullRequest()
        {
            return Observable.Create<PullRequest>(x => {
                if (_cachedPullRequest != null)
                    x.OnNext(_cachedPullRequest);

                return _sessionService.GitHubClient.Repository.PullRequest.Get(RepositoryOwner, RepositoryName, Id).ToObservable()
                    .Subscribe(y => {
                        _cachedPullRequest = y;
                        x.OnNext(y);
                    }, x.OnError, x.OnCompleted);
            });
        }
Esempio n. 6
0
 public Issue(Uri url, Uri htmlUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList<Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt)
 {
     Url = url;
     HtmlUrl = htmlUrl;
     Number = number;
     State = state;
     Title = title;
     Body = body;
     User = user;
     Labels = labels;
     Assignee = assignee;
     Milestone = milestone;
     Comments = comments;
     PullRequest = pullRequest;
     ClosedAt = closedAt;
     CreatedAt = createdAt;
     UpdatedAt = updatedAt;
 }
Esempio n. 7
0
        public static PullRequest ToDBPullRequest(this Octokit.PullRequest pr, PullRequest inPR, long repo)
        {
            inPR.Id        = pr.Id;
            inPR.Title     = pr.Title;
            inPR.CreatedAt = pr.CreatedAt;
            inPR.UpdatedAt = pr.UpdatedAt;
            inPR.MergedAt  = pr.MergedAt;
            inPR.ClosedAt  = pr.ClosedAt;
            if (pr.Assignee != null)
            {
                inPR.Assignee = pr.Assignee.Id;
            }
            inPR.Repository   = repo;
            inPR.Locked       = pr.Locked;
            inPR.Number       = pr.Number;
            inPR.State        = pr.State.StringValue;
            inPR.Additions    = pr.Additions;
            inPR.Deletions    = pr.Deletions;
            inPR.Body         = pr.Body;
            inPR.ChangedFiles = pr.ChangedFiles;

            return(inPR);
        }
Esempio n. 8
0
 public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User closedBy, User user, IReadOnlyList<Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt, int id, bool locked, Repository repository)
 {
     Id = id;
     Url = url;
     HtmlUrl = htmlUrl;
     CommentsUrl = commentsUrl;
     EventsUrl = eventsUrl;
     Number = number;
     State = state;
     Title = title;
     Body = body;
     ClosedBy = closedBy;
     User = user;
     Labels = labels;
     Assignee = assignee;
     Milestone = milestone;
     Comments = comments;
     PullRequest = pullRequest;
     ClosedAt = closedAt;
     CreatedAt = createdAt;
     UpdatedAt = updatedAt;
     Locked = locked;
     Repository = repository;
 }
            public PullRequestCacheItem(PullRequest pr)
            {
                Title = pr.Title;
                Number = pr.Number;
                CommentCount = pr.Comments;
                Author = new AccountCacheItem(pr.User);
                CreatedAt = pr.CreatedAt;
                UpdatedAt = pr.UpdatedAt;

                Key = Number.ToString(CultureInfo.InvariantCulture);
                Timestamp = UpdatedAt;
            }
Esempio n. 10
0
 static PullRequestStateEnum GetState(PullRequest pullRequest)
 {
     if (pullRequest.State == ItemState.Open)
     {
         return PullRequestStateEnum.Open;
     }
     else if (pullRequest.Merged)
     {
         return PullRequestStateEnum.Merged;
     }
     else
     {
         return PullRequestStateEnum.Closed;
     }
 }
Esempio n. 11
0
 public PullRequestCacheItem(PullRequest pr, IReadOnlyList<PullRequestFile> files)
 {
     Title = pr.Title;
     Number = pr.Number;
     Base = new GitReferenceCacheItem
     {
         Label = pr.Base.Label,
         Ref = pr.Base.Ref,
         Sha = pr.Base.Sha,
         RepositoryCloneUrl = pr.Base.Repository.CloneUrl,
     };
     Head = new GitReferenceCacheItem
     {
         Label = pr.Head.Label,
         Ref = pr.Head.Ref,
         Sha = pr.Head.Sha,
         RepositoryCloneUrl = pr.Head.Repository?.CloneUrl
     };
     CommentCount = pr.Comments + pr.ReviewComments;
     CommitCount = pr.Commits;
     Author = new AccountCacheItem(pr.User);
     Assignee = pr.Assignee != null ? new AccountCacheItem(pr.Assignee) : null;
     CreatedAt = pr.CreatedAt;
     UpdatedAt = pr.UpdatedAt;
     Body = pr.Body;
     ChangedFiles = files.Select(x => new PullRequestFileCacheItem(x)).ToList();
     State = GetState(pr);
     IsOpen = pr.State == ItemState.Open;
     Merged = pr.Merged;
     Key = Number.ToString(CultureInfo.InvariantCulture);
     Timestamp = UpdatedAt;
 }
Esempio n. 12
0
 public PullRequestCacheItem(PullRequest pr)
     : this(pr, new PullRequestFile[0])
 {
 }
Esempio n. 13
0
 public static PullRequestCacheItem Create(PullRequest pr, IReadOnlyList<PullRequestFile> files)
 {
     return new PullRequestCacheItem(pr, files);
 }
Esempio n. 14
0
 public static PullRequestCacheItem Create(PullRequest pr)
 {
     return new PullRequestCacheItem(pr, new PullRequestFile[0]);
 }
Esempio n. 15
0
 private static IssueCommentItemViewModel CreateInitialComment(PullRequest pullRequest)
 {
     var str = new StringBuilder();
     var login = pullRequest.User.Login;
     var loginHtml = pullRequest.User.HtmlUrl;
     str.AppendFormat("<a href='{0}'>{1}</a> wants to merge ", loginHtml, login);
     str.AppendFormat("{0} commit{1} ", pullRequest.Commits, (pullRequest.Commits > 1 ? "s" : string.Empty));
     str.AppendFormat("{0} commit{1} into ", pullRequest.Commits, (pullRequest.Commits > 1 ? "s" : string.Empty));
     str.Append(CreateLink(pullRequest.Base));
     str.Append(" from ");
     str.Append(CreateLink(pullRequest.Head));
     return new IssueCommentItemViewModel(str.ToString(), login, pullRequest.User.AvatarUrl, pullRequest.CreatedAt);
 }
Esempio n. 16
0
 public PullRequestViewModel Init(string repositoryOwner, string repositoryName, int id, PullRequest pullRequest = null, Issue issue = null)
 {
     RepositoryOwner = repositoryOwner;
     RepositoryName = repositoryName;
     Id = id;
     PullRequest = pullRequest;
     Issue = issue;
     return this;
 }
Esempio n. 17
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();
            }
        }
        private async Task <IEnumerable <Recommending.Candidate> > GetExpertCandidates(SophiaDbContext dbContext, long subscriptionId, Octokit.PullRequest pullRequest, IReadOnlyList <Octokit.PullRequestFile> pullRequestFiles, int topCandidatesLength)
        {
            var recommender = new CodeReviewerRecommender(RecommenderType.Chrev, dbContext);
            var candidates  = await recommender.Recommend(subscriptionId, pullRequest, pullRequestFiles, topCandidatesLength);

            return(candidates);
        }
Esempio n. 19
0
 public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList <Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset?closedAt, DateTimeOffset createdAt, DateTimeOffset?updatedAt, int id, bool locked, Repository repository)
 {
     Id          = id;
     Url         = url;
     HtmlUrl     = htmlUrl;
     CommentsUrl = commentsUrl;
     EventsUrl   = eventsUrl;
     Number      = number;
     State       = state;
     Title       = title;
     Body        = body;
     User        = user;
     Labels      = labels;
     Assignee    = assignee;
     Milestone   = milestone;
     Comments    = comments;
     PullRequest = pullRequest;
     ClosedAt    = closedAt;
     CreatedAt   = createdAt;
     UpdatedAt   = updatedAt;
     Locked      = locked;
     Repository  = repository;
 }
Esempio n. 20
0
 public Issue(string url, string htmlUrl, string commentsUrl, string eventsUrl, int number, ItemState state, string title, string body, User closedBy, User user, IReadOnlyList<Label> labels, User assignee, IReadOnlyList<User> assignees, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt, int id, string nodeId, bool locked, Repository repository, ReactionSummary reactions)
 {
     Id = id;
     NodeId = nodeId;
     Url = url;
     HtmlUrl = htmlUrl;
     CommentsUrl = commentsUrl;
     EventsUrl = eventsUrl;
     Number = number;
     State = state;
     Title = title;
     Body = body;
     ClosedBy = closedBy;
     User = user;
     Labels = labels;
     Assignee = assignee;
     Assignees = assignees;
     Milestone = milestone;
     Comments = comments;
     PullRequest = pullRequest;
     ClosedAt = closedAt;
     CreatedAt = createdAt;
     UpdatedAt = updatedAt;
     Locked = locked;
     Repository = repository;
     Reactions = reactions;
 }
Esempio n. 21
0
 public MikesPullRequest(PullRequest pullRequest, string shortBranchName)
 {
     this.pullRequest = pullRequest;
     this.shortBranchName = shortBranchName;
 }
Esempio n. 22
0
 public Issue(Uri url, Uri htmlUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList <Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset?closedAt, DateTimeOffset createdAt, DateTimeOffset?updatedAt)
 {
     Url         = url;
     HtmlUrl     = htmlUrl;
     Number      = number;
     State       = state;
     Title       = title;
     Body        = body;
     User        = user;
     Labels      = labels;
     Assignee    = assignee;
     Milestone   = milestone;
     Comments    = comments;
     PullRequest = pullRequest;
     ClosedAt    = closedAt;
     CreatedAt   = createdAt;
     UpdatedAt   = updatedAt;
 }