Skip to content

Commit 28d7325

Browse files
committed
/deploy <package>: do not assume that req.body.comment.body is a string
Apparently it is not, as I got this response for git-for-windows/build-extra#455 (comment): TypeError: Cannot read properties of undefined (reading 'startsWith') Let's just do the same as for the `/mention` command: use regular expressions. If we use only greedy expressions, we should not run into the same issues as caused the scary StackOverflow outage described in https://stackstatus.tumblr.com/post/147710624694/outage-postmortem-july-20-2016. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 1cf6d04 commit 28d7325

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

GitForWindowsHelper/slash-commands.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ module.exports = async (context, req) => {
103103
return `I edited the comment: ${commentURL}`
104104
}
105105

106-
const deployArg = command.startsWith('/deploy ') ? command.substring(8).trim() : undefined
107-
if (deployArg || command === '/deploy') {
106+
const deployMatch = command.match(/^\/deploy(\s+(\S+)\s*)?$/)
107+
if (deployMatch) {
108108
if (owner !== 'git-for-windows'
109109
|| !req.body.issue.pull_request
110110
|| !['build-extra', 'MINGW-packages', 'MSYS2-packages'].includes(repo)) {
@@ -114,7 +114,7 @@ module.exports = async (context, req) => {
114114
await checkPermissions()
115115

116116
const { guessComponentUpdateDetails, isMSYSPackage } = require('./component-updates')
117-
const { package_name } = deployArg || guessComponentUpdateDetails(req.body.issue.title, req.body.issue.body)
117+
const { package_name } = deployMatch[2] || guessComponentUpdateDetails(req.body.issue.title, req.body.issue.body)
118118

119119
// The commit hash of the tip commit is sadly not part of the
120120
// "comment.created" webhook's payload. Therefore, we have to get it

0 commit comments

Comments
 (0)