예제 #1
0
        public async Task <IActionResult> ReviewPullRequest(int number, CancellationToken cancellationToken)
        {
            var token = await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false);

            ViewBag.Title     = stringLocalizer["PullRequest", number];
            ViewBag.Modules   = stringLocalizer["ManageModules"];
            ViewBag.PRNumber  = number;
            ViewBag.RepoOwner = gitHubConfiguration.RepoOwner;
            ViewBag.RepoName  = gitHubConfiguration.RepoName;

            var pr = await gitHubManager.GetPullRequest(number).ConfigureAwait(false);

            ViewBag.PullRequestAuthor   = pr.User.Login;
            ViewBag.PullRequestAuthorID = pr.User.Id;
            ViewBag.PullRequestTitle    = pr.Title;
            ViewBag.PullRequestNumber   = pr.Number;

            if (token == null)
            {
                ViewBag.AuthHref     = String.Concat(generalConfiguration.RootURL.ToString(), "Authorize/Login/", number);
                ViewBag.AuthTitle    = stringLocalizer["SignIn"];
                ViewBag.IsMaintainer = false;
            }
            else
            {
                var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

                ViewBag.IsMaintainer = await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false);

                ViewBag.AuthHref  = String.Concat(generalConfiguration.RootURL.ToString(), "Authorize/SignOut/", number);
                ViewBag.AuthTitle = stringLocalizer["SignOut", user.Login];
            }

            ViewBag.ModuleViews = new List <string>();

            await componentProvider.AddViewVars(pr, ViewBag, cancellationToken);

            return(View());
        }
예제 #2
0
        public async Task <IActionResult> ReviewPullRequest(int number, CancellationToken cancellationToken)
        {
            var prTask    = gitHubManager.GetPullRequest(number);
            var tokenTask = gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken);
            var componentInitializeTask = componentProvider.Initialize(cancellationToken);
            var pr = await prTask.ConfigureAwait(false);

            await componentInitializeTask.ConfigureAwait(false);

            if (pr.State.Value == ItemState.Open)
            {
                var tasks = componentProvider.MergeRequirements.Select(x => x.EvaluateFor(pr, cancellationToken));
                await Task.WhenAll(tasks).ConfigureAwait(false);


                var resultDic = new Dictionary <IMergeRequirement, AutoMergeStatus>();
                foreach (var I in Enumerable.Zip(componentProvider.MergeRequirements, tasks, (x, y) => new Tuple <IMergeRequirement, AutoMergeStatus>(x, y.Result)))
                {
                    ++I.Item2.RequiredProgress;
                    ++I.Item2.Progress;
                    resultDic.Add(I.Item1, I.Item2);
                }

                ViewBag.Statuses          = resultDic;
                ViewBag.PullRequestClosed = false;
            }
            else
            {
                ViewBag.PullRequestClosed = true;
            }

            ViewBag.Title                  = stringLocalizer["PullRequest", number];
            ViewBag.Modules                = stringLocalizer["ManageModules"];
            ViewBag.PRNumber               = number;
            ViewBag.RepoOwner              = gitHubConfiguration.RepoOwner;
            ViewBag.RepoName               = gitHubConfiguration.RepoName;
            ViewBag.PullRequestAuthor      = pr.User.Login;
            ViewBag.PullRequestAuthorID    = pr.User.Id;
            ViewBag.PullRequestTitle       = pr.Title;
            ViewBag.PullRequestNumber      = pr.Number;
            ViewBag.PullRequestHref        = pr.HtmlUrl;
            ViewBag.PullRequestAuthorLogin = pr.User.Login;

            ViewBag.CloseMessage      = stringLocalizer["CloseMessage"];
            ViewBag.MergeRequirements = stringLocalizer["MergeRequirements"];


            var token = await tokenTask.ConfigureAwait(false);

            if (token == null)
            {
                ViewBag.AuthHref     = Url.Action("Begin", "Authorization", new { prNumber = number });
                ViewBag.AuthTitle    = stringLocalizer["SignIn"];
                ViewBag.IsMaintainer = false;
                ViewBag.UserIsAuthor = false;
            }
            else
            {
                var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

                ViewBag.UserIsAuthor = pr.User.Id == user.Id;
                ViewBag.IsMaintainer = await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false);

                ViewBag.UserLogin = user.Login;
                ViewBag.AuthHref  = Url.Action("SignOut", "Authorization", new { prNumber = number });
                ViewBag.AuthTitle = stringLocalizer["SignOut", user.Login];
            }

            ViewBag.ModuleViews = new List <string>();

            await componentProvider.AddViewVars(pr, (object)ViewBag, cancellationToken).ConfigureAwait(false);

            return(View());
        }