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())); }
/// <inheritdoc /> public async Task ProcessPayload(PullRequestEventPayload payload, CancellationToken cancellationToken) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } if (payload.Action != "opened") { throw new NotSupportedException(); } if (await gitHubManager.UserHasWriteAccess(payload.PullRequest.User).ConfigureAwait(false)) { return; } var allPrs = await gitHubManager.GetOpenPullRequests().ConfigureAwait(false); string result = null; foreach (var I in allPrs.Where(x => x.User.Id == payload.PullRequest.User.Id && x.Id != payload.PullRequest.Id).Select(x => x.Number)) { result = (result != null) ? result + String.Format(CultureInfo.InvariantCulture, ", #{0}", I) : String.Format(CultureInfo.InvariantCulture, "#{0}", I); } if (result != null) { await gitHubManager.CreateComment(payload.PullRequest.Number, stringLocalizer["TooManyPRs", result]).ConfigureAwait(false); await gitHubManager.Close(payload.PullRequest.Number).ConfigureAwait(false); } }
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()); }
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())); }
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()); }
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()); }
/// <inheritdoc /> public async Task <AutoMergeStatus> EvaluateFor(PullRequest pullRequest, CancellationToken cancellationToken) { if (gitHubManager == null) { throw new InvalidOperationException("Configure() wasn't called!"); } var reviews = await gitHubManager.GetPullRequestReviews(pullRequest).ConfigureAwait(false); var approvers = new List <User>(); var critics = new List <User>(); var userCheckups = new Dictionary <string, Task <bool> >(); foreach (var I in reviews) { void CheckupUser() { if (!userCheckups.ContainsKey(I.User.Login)) { userCheckups.Add(I.User.Login, gitHubManager.UserHasWriteAccess(I.User)); } } if (I.State.Value == PullRequestReviewState.Approved) { critics.RemoveAll(x => x.Id == I.User.Id); approvers.Add(I.User); CheckupUser(); } else if (I.State.Value == PullRequestReviewState.ChangesRequested) { approvers.RemoveAll(x => x.Id == I.User.Id); critics.Add(I.User); CheckupUser(); } } var result = new AutoMergeStatus(); await Task.WhenAll(userCheckups.Select(x => x.Value)).ConfigureAwait(false); foreach (var I in approvers) { if (!userCheckups[I.Login].Result) { continue; } ++result.Progress; result.Notes.Add(stringLocalizer["ApprovedBy", I.Login]); } if (result.Progress == 0) { result.Notes.Add(stringLocalizer["NoApproval"]); } result.RequiredProgress = result.Progress; foreach (var I in critics) { if (!userCheckups[I.Login].Result) { continue; } ++result.RequiredProgress; result.Notes.Add(stringLocalizer["RequestedChanges", I.Login]); } result.RequiredProgress = Math.Max(result.RequiredProgress, 1); return(result); }