From f18cd404cc11259ca3ad3ec8764cc1e9ea3dd98d Mon Sep 17 00:00:00 2001 From: Kristen Borges Date: Wed, 3 Jul 2019 16:47:31 -0700 Subject: [PATCH] Refactor script constants and add new env var Use existing RELEASE_NOTIFICATION_ROOM env var in place of adding a an additional constant for the default target flow Add an env var FLOWDOCK_ORGANIZATION_NAME to use in url construction --- env-var.list | 1 + k8s/hubot-deployment.yaml | 5 +++++ scripts/suggest.js | 31 ++++++++++++++++++------------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/env-var.list b/env-var.list index fcf26fab..a557cada 100644 --- a/env-var.list +++ b/env-var.list @@ -4,3 +4,4 @@ GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET HUBOT_FLOWDOCK_API_TOKEN=$HUBOT_FLOWDOCK_API_TOKEN ZOOM_API_KEY=$ZOOM_API_KEY ZOOM_API_SECRET=$ZOOM_API_SECRET +FLOWDOCK_ORGANIZATION_NAME=$FLOWDOCK_ORGANIZATION_NAME diff --git a/k8s/hubot-deployment.yaml b/k8s/hubot-deployment.yaml index 8c0aa670..c4bc0b68 100644 --- a/k8s/hubot-deployment.yaml +++ b/k8s/hubot-deployment.yaml @@ -38,6 +38,11 @@ spec: secretKeyRef: name: heimdall-hubot key: release_notification_room + - name: FLOWDOCK_ORGANIZATION_NAME + valueFrom: + secretKeyRef: + name: heimdall-hubot + key: flowdock_organization_name - name: REDIS_URL value: $(HEIMDALL_REDIS_SERVICE_PORT) - name: GITHUB_CLIENT_ID diff --git a/scripts/suggest.js b/scripts/suggest.js index 0addf91f..ae2a3b0e 100644 --- a/scripts/suggest.js +++ b/scripts/suggest.js @@ -5,8 +5,8 @@ // // // Configuration: -// TARGET_FLOW_PER_ROBOT - dict - collection of robot name: flow name to determine TARGET_FLOW -// DEFAULT_TARGET_FLOW - flow name to use if robot name not found in TARGET_FLOW_PER_ROBOT +// RELEASE_NOTIFICATION_ROOM - id of flow to use for suggestion posts if robot name not found in TARGET_FLOW_PER_ROBOT +// FLOWDOCK_ORGANIZATION_NAME - name of flowdock organization for constructing urls // // Commands: // hubot suggest - Posts a message to the main hubot flow, with content of the suggestion & name of the user, and replies to the command with a link to that flow @@ -24,14 +24,17 @@ const TARGET_FLOW_PER_ROBOT = { valkyrie: "Playground", heimdall: "Bifrost", } -const DEFAULT_TARGET_FLOW = "Bifrost" -const FLOW_URL = `https://www.flowdock.com/app/cardforcoin/{flowName}` -const THREAD_URL = `https://www.flowdock.com/app/cardforcoin/{flowName}/threads/{threadId}` + +const FLOW_URL = `https://www.flowdock.com/app/{orgName}/{flowName}` +const THREAD_URL = `https://www.flowdock.com/app/{orgName}/{flowName}/threads/{threadId}` module.exports = function(robot) { const targetFlowName = - TARGET_FLOW_PER_ROBOT[robot.name] || DEFAULT_TARGET_FLOW - const targetFlowId = getRoomIdFromName(robot, targetFlowName) + TARGET_FLOW_PER_ROBOT[robot.name] || + getRoomNameFromId(process.env["RELEASE_NOTIFICATION_ROOM"]) + const targetFlowId = TARGET_FLOW_PER_ROBOT[robot.name] + ? getRoomIdFromName(robot, targetFlowName) + : process.env["RELEASE_NOTIFICATION_ROOM"] robot.respond(/suggest ?((?:.|\s)*)$/i, res => { try { @@ -39,9 +42,9 @@ module.exports = function(robot) { let userSuggestion = res.match[1] let targetFlowLink = FLOW_URL.replace( - /{flowName}/, - targetFlowName.toLowerCase(), - ) + /{orgName}/, + process.env["FLOWDOCK_ORGANIZATION_NAME"].toLowerCase(), + ).replace(/{flowName}/, targetFlowName.toLowerCase()) let redirectToTargetFlowMessage = `You can try again from a public flow, or join us in [${targetFlowName}](${targetFlowLink}) and chat with us about your idea there.` if (typeof res.message.room === "undefined") { @@ -67,9 +70,11 @@ module.exports = function(robot) { let sourceFlow = getRoomNameFromId(robot, res.message.room) let sourceThreadId = res.message.metadata.thread_id let sourceThreadLink = THREAD_URL.replace( - /{flowName}/, - sourceFlow.toLowerCase(), - ).replace(/{threadId}/, sourceThreadId) + /{orgName}/, + process.env["FLOWDOCK_ORGANIZATION_NAME"].toLowerCase(), + ) + .replace(/{flowName}/, sourceFlow.toLowerCase()) + .replace(/{threadId}/, sourceThreadId) // post suggestion message & related info targetFlowName let formattedSuggestion = `@${res.message.user.name} just made a suggestion in ${sourceFlow}:\n>${userSuggestion}\n\nSee [original thread](${sourceThreadLink}).`