Skip to content

Commit

Permalink
🐛 avoid NPE for missing rule config
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jul 16, 2024
1 parent cc97dad commit 23bf63d
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.commonhaus.automation.github.actions.Action;
import org.commonhaus.automation.github.context.EventData;
import org.commonhaus.automation.github.rules.Rule;
import org.commonhaus.automation.github.rules.RuleConfig;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GitHub;

Expand Down Expand Up @@ -43,13 +44,15 @@ void onDiscussionEvent(GitHubEvent event, GitHub github, DynamicGraphQLClient gr

NoticeConfig noticeConfig = NoticeConfig.getNoticeConfig(repoConfigFile);
queryHelper.updateConfiguration(payload.getRepository(), repoConfigFile);
if (noticeConfig.isDisabled()) {

RuleConfig ruleConfig = noticeConfig.discussion;
if (noticeConfig.isDisabled() || ruleConfig == null) {
return;
}

EventData eventData = new EventData(event, payload);
EventQueryContext qc = queryHelper.newQueryContext(eventData, github, graphQLClient);
Set<String> desiredActions = findMatchingActions(qc, noticeConfig.discussion.rules);
Set<String> desiredActions = findMatchingActions(qc, ruleConfig.rules);

Log.infof("[%s] notice.onDiscussionEvent: triggered (%s) actions: %s", eventData.getLogId(),
desiredActions.size(), desiredActions);
Expand All @@ -71,14 +74,16 @@ void onIssueEvent(GitHubEvent event, GitHub github, DynamicGraphQLClient graphQL

NoticeConfig noticeConfig = NoticeConfig.getNoticeConfig(repoConfigFile);
queryHelper.updateConfiguration(payload.getRepository(), repoConfigFile);
if (noticeConfig.isDisabled()) {

RuleConfig ruleConfig = noticeConfig.issue;
if (noticeConfig.isDisabled() || ruleConfig == null) {
return;
}

EventData eventData = new EventData(event, payload);
EventQueryContext qc = queryHelper.newQueryContext(eventData, github, graphQLClient);

Set<String> desiredActions = findMatchingActions(qc, noticeConfig.issue.rules);
Set<String> desiredActions = findMatchingActions(qc, ruleConfig.rules);
Log.infof("[%s] notice.onIssueEvent: triggered (%s) actions: %s", eventData.getLogId(),
desiredActions.size(), desiredActions);

Expand All @@ -99,14 +104,16 @@ void onPullRequestEvent(GitHubEvent event, GitHub github, DynamicGraphQLClient g

NoticeConfig noticeConfig = NoticeConfig.getNoticeConfig(repoConfigFile);
queryHelper.updateConfiguration(payload.getRepository(), repoConfigFile);
if (noticeConfig.isDisabled()) {

RuleConfig ruleConfig = noticeConfig.pullRequest;
if (noticeConfig.isDisabled() || ruleConfig == null) {
return;
}

EventData eventData = new EventData(event, payload);
EventQueryContext qc = queryHelper.newQueryContext(eventData, github, graphQLClient);

Set<String> desiredActions = findMatchingActions(qc, noticeConfig.pullRequest.rules);
Set<String> desiredActions = findMatchingActions(qc, ruleConfig.rules);
Log.infof("[%s] notice.onPullRequestEvent: triggered (%s) actions: %s", eventData.getLogId(),
desiredActions.size(), desiredActions);

Expand Down

0 comments on commit 23bf63d

Please sign in to comment.