Skip to content

Commit

Permalink
🐛 Avoid NPE for unknown group
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jul 16, 2024
1 parent 23bf63d commit ca625d5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ public boolean isLoginIncluded(String login, List<String> groups) {
for (var g : groups) {
if (g.startsWith("@")) {
TeamList team = getTeamList(g.substring(1));
if (team.isEmpty()) {
return false;
}
return team.members.stream().anyMatch(m -> m.login.equals(login));
}
return g.equals(login);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public class TeamList {

public TeamList(String name, Collection<GHUser> members) {
this.name = name;
this.members = members.stream()
.map(DataActor::new)
.collect(Collectors.toSet());
this.members = members == null
? Set.of()
: members.stream()
.map(DataActor::new)
.collect(Collectors.toSet());
}

/** testing */
public TeamList(String name, Set<DataActor> members) {
this.name = name;
this.members = members;
this.members = members == null ? Set.of() : members;
}

public TeamList removeExcludedMembers(Predicate<DataActor> predicate) {
Expand All @@ -43,4 +45,8 @@ public String toString() {
.map(actor -> actor.login)
.collect(Collectors.joining(",")));
}

public boolean isEmpty() {
return members == null || members.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ public VoteInformation(VoteEvent event) {
QueryContext qc = event.getQueryContext();
VoteConfig voteConfig = event.getVotingConfig();
String bodyString = event.getBody();
String groupValue = null;
TeamList teamList = null;

// Test body for "Voting group" followed by a team name
Matcher groupM = groupPattern.matcher(bodyString);
if (groupM.find()) {
this.group = groupM.group(1);
this.teamList = qc.getTeamList(this.group);
groupValue = groupM.group(1);
teamList = qc.getTeamList(groupValue);
if (teamList != null) {
teamList.removeExcludedMembers(
a -> qc.isBot(a.login) || voteConfig.isMemberExcluded(a.login));
}
} else {
this.group = null;
this.teamList = null;
}
this.group = groupValue;
this.teamList = teamList;

this.votingThreshold = voteConfig.votingThreshold(this.group);

// Test body for "vote::marthas" or "vote::manual"
Expand Down Expand Up @@ -108,7 +110,7 @@ public boolean isValid() {
}

public boolean invalidGroup() {
return teamList == null;
return teamList == null || teamList.isEmpty();
}

public boolean invalidReactions() {
Expand Down

0 comments on commit ca625d5

Please sign in to comment.