-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-apilayer3' into upgrade_mud
# Conflicts: # grade-management-new/GradeManagement.Bll/Services/CourseService.cs
- Loading branch information
Showing
74 changed files
with
978 additions
and
794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 31 additions & 18 deletions
49
github-monitor/Ahk.GitHub.Monitor/EventHandlers/BranchProtectionRuleHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,58 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Ahk.GitHub.Monitor.Services; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.Logging; | ||
using Octokit; | ||
|
||
namespace Ahk.GitHub.Monitor.EventHandlers | ||
{ | ||
public class BranchProtectionRuleHandler : RepositoryEventBase<CreateEventPayload> | ||
public class BranchProtectionRuleHandler( | ||
IGitHubClientFactory gitHubClientFactory, | ||
IMemoryCache cache, | ||
ILogger logger) | ||
: RepositoryEventBase<CreateEventPayload>(gitHubClientFactory, cache, logger) | ||
{ | ||
public const string GitHubWebhookEventName = "create"; | ||
|
||
public BranchProtectionRuleHandler(Services.IGitHubClientFactory gitHubClientFactory, Microsoft.Extensions.Caching.Memory.IMemoryCache cache, Microsoft.Extensions.Logging.ILogger logger) | ||
: base(gitHubClientFactory, cache, logger) | ||
{ | ||
} | ||
|
||
protected override async Task<EventHandlerResult> executeCore(CreateEventPayload webhookPayload) | ||
{ | ||
if (!webhookPayload.RefType.StringValue.Equals("branch", StringComparison.OrdinalIgnoreCase)) | ||
return EventHandlerResult.NoActionNeeded($"create event for ref {webhookPayload.RefType} is not of interest"); | ||
{ | ||
return EventHandlerResult.NoActionNeeded( | ||
$"create event for ref {webhookPayload.RefType} is not of interest"); | ||
} | ||
|
||
await GitHubClient.Repository.Branch.UpdateBranchProtection( | ||
webhookPayload.Repository.Id, webhookPayload.Ref, getBranchProtectionSettingsUpdate(webhookPayload.Ref, webhookPayload.Repository.DefaultBranch)); | ||
await this.GitHubClient.Repository.Branch.UpdateBranchProtection( | ||
webhookPayload.Repository.Id, webhookPayload.Ref, | ||
getBranchProtectionSettingsUpdate(webhookPayload.Ref, webhookPayload.Repository.DefaultBranch)); | ||
return EventHandlerResult.ActionPerformed("branch protection rule applied"); | ||
} | ||
|
||
private static BranchProtectionSettingsUpdate getBranchProtectionSettingsUpdate(string branchName, string repositoryDefaultBranch) | ||
private static BranchProtectionSettingsUpdate getBranchProtectionSettingsUpdate(string branchName, | ||
string repositoryDefaultBranch) | ||
{ | ||
// For default: prohibits the merge request into default to be merged | ||
// For other branches: disables force push | ||
return new BranchProtectionSettingsUpdate( | ||
requiredStatusChecks: null, // Required. Require status checks to pass before merging. Set to null to disable. | ||
requiredPullRequestReviews: getBranchProtectionRequiredReviewsUpdate(branchName, repositoryDefaultBranch), | ||
restrictions: null, // Push access restrictions. Null to disable. | ||
enforceAdmins: false); // Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. | ||
requiredStatusChecks: null, // Required. Require status checks to pass before merging. Set to null to disable. | ||
requiredPullRequestReviews: getBranchProtectionRequiredReviewsUpdate(branchName, | ||
repositoryDefaultBranch), | ||
restrictions: null, // Push access restrictions. Null to disable. | ||
enforceAdmins: false); // Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. | ||
} | ||
|
||
private static BranchProtectionRequiredReviewsUpdate getBranchProtectionRequiredReviewsUpdate(string branchName, string repositoryDefaultBranch) | ||
private static BranchProtectionRequiredReviewsUpdate getBranchProtectionRequiredReviewsUpdate(string branchName, | ||
string repositoryDefaultBranch) | ||
{ | ||
if (branchName.Equals(repositoryDefaultBranch, StringComparison.OrdinalIgnoreCase)) | ||
return new BranchProtectionRequiredReviewsUpdate(false, false, 1); // Prohibits the student from merging the pull request. | ||
else | ||
return null; | ||
{ | ||
return | ||
new BranchProtectionRequiredReviewsUpdate(false, false, | ||
1); // Prohibits the student from merging the pull request. | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
7 changes: 2 additions & 5 deletions
7
github-monitor/Ahk.GitHub.Monitor/EventHandlers/EventHandlerResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.