Skip to content

Instantly share code, notes, and snippets.

@Supernats
Last active June 29, 2021 10:17
Show Gist options
  • Save Supernats/781e6239690834b391f098624a4f8530 to your computer and use it in GitHub Desktop.
Save Supernats/781e6239690834b391f098624a4f8530 to your computer and use it in GitHub Desktop.
Mention the user responsible for a build on Circle
commands:
notify-slack-deploy-complete:
steps:
- slack/status:
mentions: "$(.circleci/utility/github_username_to_slack_uid $CIRCLE_USERNAME)"
#!/usr/bin/env ruby
class GithubUsernameToSlackUid
class << self
def call(github_handle)
new(github_handle).call
end
end
PREFIX = "GITHUB_TO_SLACK_"
private_constant :PREFIX
def initialize(github_handle)
@github_handle = github_handle
end
def call
print slack_id
end
private
attr_reader :github_handle
def environment_settings
@environment_settings ||= `printenv`.split("\n")
end
def matching_setting
environment_settings.
find { |el| (/#{PREFIX}#{github_handle}/i).match(el) }
end
def slack_id
matching_setting.split("=").last
end
end
GithubUsernameToSlackUid.call(ARGV.first)
@Supernats
Copy link
Author

Supernats commented May 23, 2019

This assumes you have environment variables defined on your system of the following form.

Variable:

"#{PREFIX}#{GITHUB_USERNAME}"

Value: Slack UID

We used a context that defines a variable like that for each member of our team, and mixed it into any job that was touching Slack.

This requires Ruby available on your build container. If that is a problem, it shouldn't be hard to reimplement in the language of your choice. You really just want something that will return a Slack UID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment