Skip to content

Commit

Permalink
Refactor script constants and add new env var
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kb0rg committed Jul 3, 2019
1 parent 2b04376 commit f18cd40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions env-var.list
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions k8s/hubot-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 18 additions & 13 deletions scripts/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,24 +24,27 @@ 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 {
let user = res.message.user
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") {
Expand All @@ -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}).`
Expand Down

0 comments on commit f18cd40

Please sign in to comment.