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()));
        }
Exemple #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());
        }
Exemple #3
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());
        }
Exemple #4
0
        public async Task <IActionResult> Begin(int prNumber, CancellationToken cancellationToken)
        {
            if (await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false) != null)
            {
                return(RedirectToAction("ReviewPullRequest", "PullRequest", new { number = prNumber }));
            }
            var redirectURI = new Uri(generalConfiguration.RootURL, Url.Action(nameof(Complete), prNumber));

            return(Redirect(String.Concat(gitHubManager.GetAuthorizationURL(redirectURI).ToString())));
        }
        public async Task <IActionResult> Begin(int prNumber, CancellationToken cancellationToken)
        {
            if (await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false) != null)
            {
                return(RedirectToAction("ReviewPullRequest", "PullRequest", new { number = prNumber }));
            }

            var redirectURI = Url.Action(nameof(Complete), new { prNumber });

            return(Redirect(gitHubManager.GetAuthorizationURL(new Uri(String.Format(CultureInfo.InvariantCulture, "https://{0}{1}", Request.Host, redirectURI))).ToString()));
        }
        public async Task <IActionResult> Index(long repositoryId, CancellationToken cancellationToken)
        {
            try
            {
                var loadRepoTask = gitHubManager.LoadInstallation(repositoryId, cancellationToken);
                var authedTask   = gitHubManager.CheckAuthorization(repositoryId, Request.Cookies, cancellationToken);
                await loadRepoTask.ConfigureAwait(false);

                ViewBag.ConfiguredDme = await databaseContext.InstallationRepositories.Where(x => x.Id == repositoryId).Select(x => x.TargetDme).ToAsyncEnumerable().First(cancellationToken).ConfigureAwait(false);

                var authLevel = await authedTask.ConfigureAwait(false);

                ViewBag.SignIn = stringLocalizer[authLevel == AuthenticationLevel.LoggedOut ? "Sign-In with GitHub" : "Log Out"];
                if (authLevel == AuthenticationLevel.LoggedOut)
                {
                    ViewBag.SignInHref = gitHubManager.GetAuthorizationURL(new Uri(String.Concat(generalConfiguration.ApplicationPrefix, '/', Route, '/', nameof(Authorize))), repositoryId.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    ViewBag.SignInHref = Url.Action(nameof(SignOut), new { repositoryId });
                }

                ViewBag.AuthLevel  = authLevel;
                ViewBag.Title      = stringLocalizer["DME Configuration"];
                ViewBag.HideLogin  = false;
                ViewBag.EditHeader = stringLocalizer["Set the path to the .dme MapDiffBot should use for rendering"];
                ViewBag.AutoDme    = stringLocalizer["Auto-Detect"];
                ViewBag.Submit     = stringLocalizer["Submit"];
                ViewBag.OnlyMemes  = stringLocalizer["Only maintainers can perform this action!"];

                return(View());
            }
            catch
            {
                return(NotFound());
            }
        }
        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()));
        }
Exemple #9
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());
        }
Exemple #10
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());
        }