-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ check organization/team before labeling
- Loading branch information
Showing
9 changed files
with
292 additions
and
27 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
54 changes: 54 additions & 0 deletions
54
commonhaus-bot/src/main/java/org/commonhaus/automation/github/rules/MatchMember.java
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.commonhaus.automation.github.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.commonhaus.automation.github.EventQueryContext; | ||
import org.commonhaus.automation.github.context.DataActor; | ||
import org.commonhaus.automation.github.context.EventData; | ||
import org.kohsuke.github.GHOrganization; | ||
import org.kohsuke.github.GHUser; | ||
|
||
public class MatchMember { | ||
public final List<String> include = new ArrayList<>(); | ||
public final List<String> exclude = new ArrayList<>(); | ||
|
||
public MatchMember(List<String> groups) { | ||
groups.forEach(x -> { | ||
if (x.startsWith("!")) { | ||
exclude.add(x.substring(1)); | ||
} else { | ||
include.add(x); | ||
} | ||
}); | ||
} | ||
|
||
public boolean matches(EventQueryContext qc) { | ||
EventData eventData = qc.getEventData(); | ||
if (eventData == null) { | ||
return false; // unlikely/bad event; fail match | ||
} | ||
DataActor author = eventData.getAuthor(); | ||
if (author == null) { | ||
return false; // unlikely/bad event; fail match | ||
} | ||
GHUser user = qc.getUser(author.login); // cached lookup | ||
|
||
if (!exclude.isEmpty() && exclude.stream().anyMatch(group -> userIsMember(qc, user, group))) { | ||
return false; | ||
} | ||
|
||
return include.isEmpty() || include.stream().anyMatch(group -> userIsMember(qc, user, group)); | ||
} | ||
|
||
private boolean userIsMember(EventQueryContext qc, GHUser user, String group) { | ||
if (group.contains("/")) { | ||
// Check for team membership | ||
return qc.isTeamMember(user, group); | ||
} | ||
// Check for org membership | ||
GHOrganization org = qc.getOrganization(group); | ||
return org.hasMember(user); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,6 @@ [email protected] | |
|
||
%dev.automation.error-email-address=[email protected] | ||
|
||
%dev.quarkus.keycloak.devservices.enabled=false | ||
%test.quarkus.keycloak.devservices.enabled=false | ||
|
||
# For use with mailpit | ||
# %dev.quarkus.mailer.host=localhost | ||
# %dev.quarkus.mailer.port=56504 | ||
|
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.