Skip to content

Commit

Permalink
Updates for review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSuplizio committed Mar 17, 2023
1 parent f3a999d commit 065ea41
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MockGitHubEventClient(string productHeaderName, string? rulesConfigLocati
/// </summary>
/// <param name="repositoryId"></param>
/// <param name="issueOrPullRequestNumber"></param>
/// <returns></returns>
/// <returns>integer,the number of pending updates that would be processed</returns>
public override Task<int> ProcessPendingUpdates(long repositoryId, int issueOrPullRequestNumber = 0)
{
int numUpdates = 0;
Expand Down Expand Up @@ -81,9 +81,9 @@ public override Task<int> ProcessPendingUpdates(long repositoryId, int issueOrPu
/// <summary>
/// IsUserCollaborator override. Returns IsCollaboratorReturn value
/// </summary>
/// <param name="repositoryId"></param>
/// <param name="user"></param>
/// <returns></returns>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="user">The User.Login for the event object from the action payload</param>
/// <returns>bool, returns the IsCollaboratorReturn set for testing</returns>
public override Task<bool> IsUserCollaborator(long repositoryId, string user)
{
return Task.FromResult(IsCollaboratorReturn);
Expand All @@ -92,22 +92,22 @@ public override Task<bool> IsUserCollaborator(long repositoryId, string user)
/// <summary>
/// IsUserMemberOfOrg override. Returns IsUserMemberOfOrgReturn value
/// </summary>
/// <param name="orgName"></param>
/// <param name="user"></param>
/// <returns></returns>
/// <param name="orgName">The organization name.</param>
/// <param name="user">The User.Login for the event object from the action payload</param>
/// <returns>bool, returns IsUserMemberOfOrgReturn set for testing</returns>
public override Task<bool> IsUserMemberOfOrg(string orgName, string user)
{
return Task.FromResult(IsCollaboratorReturn);
return Task.FromResult(IsUserMemberOfOrgReturn);
}


/// <summary>
/// DoesUserHavePermissions override. Returns UserHasPermissionsReturn value
/// </summary>
/// <param name="repositoryId"></param>
/// <param name="user"></param>
/// <param name="permissionList"></param>
/// <returns></returns>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="user">The User.Login for the event object from the action payload</param>
/// <param name="permissionList">The list of permissions to check for.</param>
/// <returns>bool, returns UserHasPermissionsReturn for testing</returns>
public override Task<bool> DoesUserHavePermissions(long repositoryId, string user, List<string> permissionList)
{
return Task.FromResult(UserHasPermissionsReturn);
Expand Down Expand Up @@ -224,7 +224,7 @@ public void CreateFakeReviewsForPullRequest(int numApproved, int numNotApproved)
/// and private setters. This means everything needs to be passed into the constructor.
/// </summary>
/// <param name="fakeLogin">This will become string that'll be the User.Login</param>
/// <returns></returns>
/// <returns>Octokit.User</returns>
internal User CreateFakeUser(string fakeLogin)
{
DateTimeOffset dateTimeOffset= DateTimeOffset.Now;
Expand Down Expand Up @@ -299,7 +299,7 @@ internal User CreateFakeUser(string fakeLogin)
/// <param name="fakeUser">fake Octokit.User, created using CreateFakeUser</param>
/// <param name="prReviewState">Octokit.PullRequestReviewState, the state of the review</param>
/// <param name="prReviewId">Fake prReviewId, it'll match the number of the fakeUser{number}</param>
/// <returns></returns>
/// <returns>Octkit.PullRequestReview</returns>
internal PullRequestReview CreateFakeReview(User fakeUser, PullRequestReviewState prReviewState, long prReviewId)
{
PullRequestReview prReview = new PullRequestReview(
Expand Down Expand Up @@ -381,7 +381,7 @@ public void CreateFakePullRequestFiles(List<string> prFiles)
/// all rules defaulting to RuleState.On, otherwise load the rulesConfiguration from the location.
/// </summary>
/// <param name="rulesConfigLocation">Rules configuration location</param>
/// <returns></returns>
/// <returns>RulesConfiguration</returns>
public override RulesConfiguration LoadRulesConfiguration(string? rulesConfigLocation = null)
{
RulesConfiguration? rulesConfiguration = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The GitHubEventClient is a singleton used by workflow processing and any/all ext
## Live Testing
[azure-sdk/github-event-processor-test](https://github.com/azure-sdk/github-event-processor-test) is a repository which was specifically setup for testing purposes and can be used to generate static payloads. The .github\workflow contains the [config and workflow yml files](../YmlAndConfigFiles/) which, aside from different confi files, the final version of the workflow files. Every Action rule can be setup through creation and modification of issues and pull requests within the repository and every action has been tested this way. Scheduled events are a little different to test live because constraints dealing with time. Every scheduled event has "last modified X days ago" as part of its criteria ranging from 7 to 90 days which isn't something that can be created on the fly.
[azure-sdk/github-event-processor-test](https://github.com/azure-sdk/github-event-processor-test) is a repository which was specifically setup for testing purposes and can be used to generate static payloads. The .github\workflow contains the [config and workflow yml files](../YmlAndConfigFiles/) which, aside from different config files, the final version of the workflow files. Every Action rule can be setup through creation and modification of issues and pull requests within the repository and every action has been tested this way. Scheduled events are a little different to test live because constraints dealing with time. Every scheduled event has "last modified X days ago" as part of its criteria ranging from 7 to 90 days which isn't something that can be created on the fly.
### Other requirements of the test repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class IssueCommentProcessingTests : ProcessingTestBase
/// <param name="rule">String, RulesConstants for the rule being tested</param>
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="ruleState">Whether or not the rule is on/off</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.AuthorFeedback, "Tests.JsonEventPayloads/AuthorFeedBack_issue_comment_created.json", RuleState.On)]
[TestCase(RulesConstants.AuthorFeedback, "Tests.JsonEventPayloads/AuthorFeedBack_issue_comment_created.json", RuleState.Off)]
Expand Down Expand Up @@ -68,7 +67,6 @@ public async Task TestAuthorFeedback(string rule, string payloadFile, RuleState
/// <param name="rule">String, RulesConstants for the rule being tested</param>
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="ruleState">Whether or not the rule is on/off</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.ResetIssueActivity, "Tests.JsonEventPayloads/ResetIssueActivity_issue_comment_created.json", RuleState.On)]
[TestCase(RulesConstants.ResetIssueActivity, "Tests.JsonEventPayloads/ResetIssueActivity_issue_comment_created.json", RuleState.Off)]
Expand Down Expand Up @@ -109,7 +107,6 @@ public async Task TestResetIssueActivity(string rule, string payloadFile, RuleSt
/// <param name="rule">String, RulesConstants for the rule being tested</param>
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="ruleState">Whether or not the rule is on/off</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.ReopenIssue, "Tests.JsonEventPayloads/ReopenIssue_issue_comment_created.json", RuleState.On)]
[TestCase(RulesConstants.ReopenIssue, "Tests.JsonEventPayloads/ReopenIssue_issue_comment_created.json", RuleState.Off)]
Expand Down Expand Up @@ -157,7 +154,6 @@ public async Task TestReopenIssue(string rule, string payloadFile, RuleState rul
/// <param name="rule">String, RulesConstants for the rule being tested</param>
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="ruleState">Whether or not the rule is on/off</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.DeclineToReopenIssue, "Tests.JsonEventPayloads/DeclineToReopenIssue_issue_comment_created.json", RuleState.On)]
[TestCase(RulesConstants.DeclineToReopenIssue, "Tests.JsonEventPayloads/DeclineToReopenIssue_issue_comment_created.json", RuleState.Off)]
Expand Down Expand Up @@ -204,7 +200,6 @@ public async Task TestDeclineToReopenIssue(string rule, string payloadFile, Rule
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="ruleState">Whether or not the rule is on/off</param>
/// <param name="userHasAdminOrWritePermission">Whether or not the user has Admin or Write permission.</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.IssueAddressedCommands, "Tests.JsonEventPayloads/IssueAddressedCommands_issue_comment_created_same_user.json", RuleState.On, true)]
[TestCase(RulesConstants.IssueAddressedCommands, "Tests.JsonEventPayloads/IssueAddressedCommands_issue_comment_created_same_user.json", RuleState.On, false)]
Expand Down Expand Up @@ -257,7 +252,6 @@ public async Task TestIssueAddressedCommands_SameUser(string rule, string payloa
/// <param name="rule">String, RulesConstants for the rule being tested</param>
/// <param name="payloadFile">JSon payload file for the event being tested</param>
/// <param name="userHasAdminOrWritePermission">Whether or not the user has Admin or Write permission.</param>
/// <returns></returns>
[Category("static")]
[TestCase(RulesConstants.IssueAddressedCommands, "Tests.JsonEventPayloads/IssueAddressedCommands_issue_comment_created_different_user.json", true)]
[TestCase(RulesConstants.IssueAddressedCommands, "Tests.JsonEventPayloads/IssueAddressedCommands_issue_comment_created_different_user.json", false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ namespace Azure.Sdk.Tools.GitHubEventProcessor.Constants
/// </summary>
public class ActionConstants
{
public static readonly string Assigned = "assigned";
public static readonly string Created = "created";
public static readonly string Closed = "closed";
public static readonly string Deleted = "deleted";
public static readonly string Demilestoned = "demilestoned";
public static readonly string Dismissed = "dismissed";
public static readonly string Edited = "edited";
public static readonly string Labeled = "labeled";
public static readonly string Locked = "locked";
public static readonly string Milestoned = "milestoned";
public static readonly string Opened = "opened";
public static readonly string Pinned = "pinned";
public static readonly string Reopened = "reopened";
public static readonly string ReviewRequested = "review_requested";
public static readonly string Submitted = "submitted";
public static readonly string Synchronize = "synchronize";
public static readonly string Transferred = "transferred";
public static readonly string Unassigned = "unassigned";
public static readonly string Unlabeled = "unlabeled";
public static readonly string Unlocked = "unlocked";
public static readonly string Unpinned = "unpinned";
public const string Assigned = "assigned";
public const string Created = "created";
public const string Closed = "closed";
public const string Deleted = "deleted";
public const string Demilestoned = "demilestoned";
public const string Dismissed = "dismissed";
public const string Edited = "edited";
public const string Labeled = "labeled";
public const string Locked = "locked";
public const string Milestoned = "milestoned";
public const string Opened = "opened";
public const string Pinned = "pinned";
public const string Reopened = "reopened";
public const string ReviewRequested = "review_requested";
public const string Submitted = "submitted";
public const string Synchronize = "synchronize";
public const string Transferred = "transferred";
public const string Unassigned = "unassigned";
public const string Unlabeled = "unlabeled";
public const string Unlocked = "unlocked";
public const string Unpinned = "unpinned";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class CommentConstants
{
// /azp <command> does things like prepares new pipelines or kicks off pipelines and should
// also be ignored for comment processing.
public static readonly string Azp = "/azp";
public const string Azp = "/azp";
// Check Enforcer commands are all /check-enforcer <something>
// "What is Check Enforcer" is effectively dead
public static readonly string CheckEnforcer = "/check-enforcer";
public const string CheckEnforcer = "/check-enforcer";
// This is used to reopen an issue in a comment and causes actions to happen
public static readonly string Reopen = "/reopen";
public const string Reopen = "/reopen";
// This is part of the message that's added to a PR that's being closed as part of the cron job that
// closes stale pull requests. There's a rule that looks for this string as part of a pull request comment to
// prevent an action.
public static readonly string ScheduledCloseFragment = "Since there hasn't been recent engagement, this is being closed out.";
public const string ScheduledCloseFragment = "Since there hasn't been recent engagement, this is being closed out.";
// used to unresolve an issue in a comment and causes actions to happen
public static readonly string Unresolve = "/unresolve";
public const string Unresolve = "/unresolve";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace Azure.Sdk.Tools.GitHubEventProcessor.Constants
/// </summary>
public class EventConstants
{
public const string issues = "issues";
public const string issue_comment = "issue_comment";
public const string pull_request_review = "pull_request_review";
public const string pull_request_target = "pull_request_target";
public const string schedule = "schedule";
public const string Issues = "issues";
public const string IssueComment = "issue_comment";
public const string PullRequestReview = "pull_request_review";
public const string PullRequestTarget = "pull_request_target";
public const string Schedule = "schedule";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ namespace Azure.Sdk.Tools.GitHubEventProcessor.Constants
/// </summary>
public class LabelConstants
{
public static readonly string CommunityContribution = "Community Contribution";
public static readonly string CustomerReported = "customer-reported";
public static readonly string CXPAttention = "CXP Attention";
public static readonly string IssueAddressed = "issue-addressed";
public static readonly string NeedsAuthorFeedback = "needs-author-feedback";
public static readonly string NeedsTeamAttention = "needs-team-attention";
public static readonly string NeedsTeamTriage = "needs-team-triage";
public static readonly string NeedsTriage = "needs-triage";
public static readonly string NoRecentActivity = "no-recent-activity";
public static readonly string Question = "question";
public static readonly string ServiceAttention = "Service Attention";
public const string CommunityContribution = "Community Contribution";
public const string CustomerReported = "customer-reported";
public const string CXPAttention = "CXP Attention";
public const string IssueAddressed = "issue-addressed";
public const string NeedsAuthorFeedback = "needs-author-feedback";
public const string NeedsTeamAttention = "needs-team-attention";
public const string NeedsTeamTriage = "needs-team-triage";
public const string NeedsTriage = "needs-triage";
public const string NoRecentActivity = "no-recent-activity";
public const string Question = "question";
public const string ServiceAttention = "Service Attention";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Azure.Sdk.Tools.GitHubEventProcessor.Constants
public class OrgConstants
{
// The Azure is used to check whether or not the use is a member of Azure org.
public static readonly string Azure = "Azure";
public const string Azure = "Azure";
// The ProductHeaderName is used to register the GitHubClient, specificially, for this
// application
public static readonly string ProductHeaderName = "azure-sdk-github-event-processor";
public const string ProductHeaderName = "azure-sdk-github-event-processor";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ public static void ManualTriageAfterExternalAssignment(GitHubEventClient gitHubE
if (issueEventPayload.Action == ActionConstants.Unlabeled)
{
if (issueEventPayload.Issue.State == ItemState.Open &&
LabelUtils.HasLabel(issueEventPayload.Issue.Labels, LabelConstants.CustomerReported) &&
(issueEventPayload.Label.Name.Equals(LabelConstants.CXPAttention) ||
issueEventPayload.Label.Name.Equals(LabelConstants.ServiceAttention)) &&
!LabelUtils.HasLabel(issueEventPayload.Issue.Labels, LabelConstants.NeedsTeamTriage))
LabelUtils.HasLabel(issueEventPayload.Issue.Labels, LabelConstants.CustomerReported) &&
(issueEventPayload.Label.Name.Equals(LabelConstants.CXPAttention) ||
issueEventPayload.Label.Name.Equals(LabelConstants.ServiceAttention)) &&
!LabelUtils.HasLabel(issueEventPayload.Issue.Labels, LabelConstants.NeedsTeamTriage))
{
var issueUpdate = gitHubEventClient.GetIssueUpdate(issueEventPayload.Issue);
issueUpdate.AddLabel(LabelConstants.NeedsTeamTriage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public static async Task ProcessPullRequestReviewEvent(GitHubEventClient gitHubE
/// </summary>
/// <param name="gitHubEventClient">Authenticated GitHubEventClient</param>
/// <param name="prReviewEventPayload">PullRequestReviewEventPayload deserialized from the json event payload</param>
/// <returns></returns>
public static void ResetPullRequestActivity(GitHubEventClient gitHubEventClient,
PullRequestReviewEventPayload prReviewEventPayload)
{
Expand Down
Loading

0 comments on commit 065ea41

Please sign in to comment.