diff --git a/lib/git-jira-commit-msg.js b/lib/git-jira-commit-msg.js index 093eeb6..14b34f5 100644 --- a/lib/git-jira-commit-msg.js +++ b/lib/git-jira-commit-msg.js @@ -12,8 +12,8 @@ const verbose = !process.env.GIT_JIRA_SILENT; const username = process.env.GIT_JIRA_USER; const password = process.env.GIT_JIRA_PASSWORD; const url = process.env.GIT_JIRA_URL; -const timeout = +process.env.GIT_JIRA_TIMEOUT || 5000; -const eol = process.env.GIT_JIRA_EOL; +const timeout = +process.env.GIT_JIRA_TIMEOUT || 6000; +const eol = !!eval(process.env.GIT_JIRA_EOL); function print(io, message) { io.write(`${message}${eol ? '' : EOL}`); @@ -54,9 +54,9 @@ const auth = `${username}:${password}`; const headers = { 'Content-Type': 'application/json' }; const path = `/rest/api/2/search?jql=assignee=${username}`; -const request = { auth, headers, hostname, port, path, timeout }; +const requestOpts = { auth, headers, hostname, port, path, timeout }; -get(request, (message) => { +const request = get(requestOpts, (message) => { let data = ''; message.on('data', (chunk) => { @@ -68,7 +68,12 @@ get(request, (message) => { }); message.on('timeout', () => { - error(6, 'Request timeout.'); + error(6, 'Incomming message timeout.'); + }); + + message.on('socket', (socket) => { + socket.setTimeout(timeout, () => socket.destroy()); + error(6, 'Incomming message socket timeout'); }); message.on('end', () => { @@ -97,3 +102,10 @@ get(request, (message) => { } }); }); + +request.on('socket', (socket) => { + socket.setTimeout(timeout, () => { + socket.destroy(); + error(10, 'Request socket timeout.'); + }); +});