Skip to content

Commit

Permalink
Merge pull request #41 from lsst-sqre/tickets/DM-42885
Browse files Browse the repository at this point in the history
Parameterize Jira URL
  • Loading branch information
athornton authored Feb 14, 2024
2 parents 2d01338 + e37c128 commit e8ef61f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/linkticket.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TICKET_PREFIXES = TICKET_PREFIXES + "|SITCOM|BLOCK"

user = process.env.LSST_JIRA_USER
pwd = process.env.LSST_JIRA_PWD
url = process.env.LSST_JIRA_URL or "https://jira.lsstcorp.org"

module.exports = (robot) ->
rootCas = require('ssl-root-cas').create()
Expand All @@ -36,7 +37,9 @@ module.exports = (robot) ->
# Remove inline code
txt = txt.replace(/`.*?`/g, "")
# Protect explicit Jira URLs by making them non-URLs
txt = txt.replace(/https:\/\/jira\.lsstcorp\.org\/browse\//g, "")
txt = txt.replace(///
(#{url}/\browse\/)
///g, "")
# Protect "tickets/DM-" (only) when not part of a URL or path
txt = txt.replace(/tickets\/DM-/g, "DM-")
# Remove URLs and pathnames (approximately)
Expand Down Expand Up @@ -68,19 +71,19 @@ issueResponses = (robot, msg) ->
robot.brain.set(brainId, now)
if last and now.isBefore last.add(5, 'minute')
return
urlstr="https://jira.lsstcorp.org/rest/api/latest/issue/#{ticketId}"
urlstr="#{url}/rest/api/latest/issue/#{ticketId}"
robot.http(urlstr,{ecdhCurve: 'auto'}).auth(user, pwd).get() (err, res, body) ->
# The callback only sees the latest versions of these variables,
# so regenerate them from the response
urlstr = "https://jira.lsstcorp.org#{res.req.path}"
urlstr = url + "#{url}#{res.req.path}"
ticketId = res.req.path
ticketId = ticketId.replace(/.*\//, "")
if (not res)
msg.send("Null response from GET #{urlstr}")
msg.send("Error: #{err}")
return
if res.statusCode in [401, 403]
msg.send("Protected: <https://jira.lsstcorp.org/browse/#{ticketId}|#{ticketId}>")
msg.send("Protected: <#{url}"/browse/#{ticketId}|#{ticketId}>")
return
if res.statusCode == 404
# Do Nothing
Expand All @@ -102,7 +105,7 @@ getAttachment = (issue) ->
response.color = "#88bbdd"
response.mrkdwn_in = [ 'text' ]
# Parse text as markdown
issue_md = "<https://jira.lsstcorp.org/browse/#{issue.key}|#{issue.key}>"
issue_md = "<#{url}/browse/#{issue.key}|#{issue.key}>"
status_md = "`#{issue.fields.status.name}`"
response.text = issue_md + ": " + status_md + " " + issue.fields.summary
response.footer = 'Unassigned'
Expand Down

0 comments on commit e8ef61f

Please sign in to comment.