From 23bf63dccd98e4ac0a10b671541787b87693203b Mon Sep 17 00:00:00 2001 From: Erin Schnabel Date: Mon, 15 Jul 2024 21:20:33 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20avoid=20NPE=20for=20missing=20ru?= =?UTF-8?q?le=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/github/notice/Notice.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/commonhaus-bot/src/main/java/org/commonhaus/automation/github/notice/Notice.java b/commonhaus-bot/src/main/java/org/commonhaus/automation/github/notice/Notice.java index 3d77cf7..8efe9d4 100644 --- a/commonhaus-bot/src/main/java/org/commonhaus/automation/github/notice/Notice.java +++ b/commonhaus-bot/src/main/java/org/commonhaus/automation/github/notice/Notice.java @@ -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; @@ -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 desiredActions = findMatchingActions(qc, noticeConfig.discussion.rules); + Set desiredActions = findMatchingActions(qc, ruleConfig.rules); Log.infof("[%s] notice.onDiscussionEvent: triggered (%s) actions: %s", eventData.getLogId(), desiredActions.size(), desiredActions); @@ -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 desiredActions = findMatchingActions(qc, noticeConfig.issue.rules); + Set desiredActions = findMatchingActions(qc, ruleConfig.rules); Log.infof("[%s] notice.onIssueEvent: triggered (%s) actions: %s", eventData.getLogId(), desiredActions.size(), desiredActions); @@ -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 desiredActions = findMatchingActions(qc, noticeConfig.pullRequest.rules); + Set desiredActions = findMatchingActions(qc, ruleConfig.rules); Log.infof("[%s] notice.onPullRequestEvent: triggered (%s) actions: %s", eventData.getLogId(), desiredActions.size(), desiredActions);