public async Task <IActionResult> SignOff(int prNumber, CancellationToken cancellationToken)
        {
            var token = await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false);

            if (token == null)
            {
                return(Unauthorized());
            }

            var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

            if (!await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false))
            {
                return(Forbid());
            }

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

#if !ENABLE_SELF_SIGN
            //no self signing
            if (pr.User.Id == user.Id)
            {
                return(Forbid());
            }
#endif

            await signOffModule.SignOff(pr, user, token, cancellationToken).ConfigureAwait(false);

            autoMergeHandler.RecheckPullRequest(prNumber);

            return(Json(new object()));
        }
示例#2
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.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;


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

                ViewBag.AuthHref  = String.Concat(generalConfiguration.RootURL.ToString(), "Authorize/SignOut/", number);
                ViewBag.AuthTitle = stringLocalizer["SignOut", user.Login];
            }
            return(View());
        }
        /// <inheritdoc />
        public async Task ProcessPayload(PullRequestEventPayload payload, CancellationToken cancellationToken)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            if (payload.Action != "edited")
            {
                throw new NotSupportedException();
            }

            var signOff = await dataStore.ReadData <PullRequestSignOffs>(SignOffDataKey, cancellationToken).ConfigureAwait(false);

            if (!signOff.Entries.Remove(payload.PullRequest.Number))
            {
                return;
            }

            await dataStore.WriteData(SignOffDataKey, signOff, cancellationToken).ConfigureAwait(false);

            var botLoginTask = gitHubManager.GetUserLogin(null, cancellationToken);
            var reviews      = await gitHubManager.GetPullRequestReviews(payload.PullRequest).ConfigureAwait(false);

            var botLogin = await botLoginTask.ConfigureAwait(false);

            await Task.WhenAll(
                reviews.Where(
                    x => x.User.Id == botLogin.Id &&
                    x.State.Value == PullRequestReviewState.Approved
                    ).Select(
                    x => gitHubManager.DismissReview(payload.PullRequest, x, stringLocalizer["SignOffNulled"])
                    ));
        }
示例#4
0
        public async Task <IActionResult> SetOffset(int prNumber, [FromBody] GoodBoyPointsOffset offset, CancellationToken cancellationToken)
        {
            if (offset == null)
            {
                throw new ArgumentNullException(nameof(offset));
            }

            var token = await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false);

            if (token == null)
            {
                return(Unauthorized());
            }

            var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

            if (!await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false))
            {
                return(Forbid());
            }

            await goodBoyPointsModule.SetOffset(prNumber, offset, cancellationToken).ConfigureAwait(false);

            return(Ok());
        }
示例#5
0
        /// <inheritdoc />
        public async Task <AutoMergeStatus> EvaluateFor(PullRequest pullRequest, CancellationToken cancellationToken)
        {
            if (pullRequest == null)
            {
                throw new ArgumentNullException(nameof(pullRequest));
            }
            var signOff = await dataStore.ReadData <PullRequestSignOff>(pullRequest.Number.ToString(CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);

            var result = new AutoMergeStatus()
            {
                RequiredProgress  = 1,
                Progress          = signOff.AccessToken != null ? 1 : 0,
                MergerAccessToken = signOff.AccessToken
            };

            if (signOff.AccessToken != null)
            {
                var user = await gitHubManager.GetUserLogin(signOff.AccessToken, cancellationToken).ConfigureAwait(false);

                result.Notes.Add(stringLocalizer["Signer", user.Login]);
            }
            return(result);
        }
        public async Task <IActionResult> Index(CancellationToken cancellationToken)
        {
            var token = await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false);

            if (token == null)
            {
                return(Unauthorized());
            }

            var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

            if (!await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false))
            {
                return(Forbid());
            }

            ViewBag.Title        = stringLocalizer["Title"];
            ViewBag.Modules      = ViewBag.Title;
            ViewBag.AuthHref     = String.Concat(generalConfiguration.RootURL.ToString(), "Authorize/SignOut");
            ViewBag.AuthTitle    = stringLocalizer["SignOut", user.Login];
            ViewBag.ModulesMap   = moduleManager.ModuleStatuses;
            ViewBag.IsMaintainer = true;
            return(View());
        }
        public async Task <IActionResult> SetRequirement(int prNumber, [FromBody] RequireChangelogEntry requireChangelogEntry, CancellationToken cancellationToken)
        {
            var token = await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false);

            if (token == null)
            {
                return(Unauthorized());
            }

            var user = await gitHubManager.GetUserLogin(token, cancellationToken).ConfigureAwait(false);

            if (!await gitHubManager.UserHasWriteAccess(user).ConfigureAwait(false))
            {
                return(Forbid());
            }

            await changelogModule.SetRequirement(prNumber, requireChangelogEntry, cancellationToken).ConfigureAwait(false);

            autoMergeHandler.RecheckPullRequest(prNumber);

            return(Json(new object()));
        }
示例#8
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());
        }
示例#9
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());
        }