Skip to content

Commit

Permalink
Merge pull request #224 from hubot-archive/check-empty-match
Browse files Browse the repository at this point in the history
Check for empty match on incident lookup
  • Loading branch information
stephenyeargin authored Apr 4, 2024
2 parents cfd8ee2 + 4fc0cdf commit 0ea0d87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/scripts/pagerduty.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = function (robot) {
msg.send("Okay, I've forgotten your PagerDuty email");
});

robot.respond(/(pager|major)( me)? incident (.*)$/i, function (msg) {
robot.respond(/(pager|major)( me)? incident ([a-z0-9]+)$/i, function (msg) {
msg.finish();

if (pagerduty.missingEnvironmentForApi(msg)) {
Expand All @@ -105,6 +105,12 @@ module.exports = function (robot) {
return;
}

if (!incident || !incident['incident']) {
logger.debug(incident);
msg.send('No matching incident found for `msg.match[3]`.');
return;
}

msg.send(formatIncident(incident['incident']));
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/pager-me-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('pagerduty', function () {
});

it('registers a pager incident listener', function () {
expect(this.robot.respond).to.have.been.calledWith(/(pager|major)( me)? incident (.*)$/i);
expect(this.robot.respond).to.have.been.calledWith(/(pager|major)( me)? incident ([a-z0-9]+)$/i);
});

it('registers a pager sup listener', function () {
Expand Down

0 comments on commit 0ea0d87

Please sign in to comment.