Last active
June 29, 2021 10:17
-
-
Save Supernats/781e6239690834b391f098624a4f8530 to your computer and use it in GitHub Desktop.
Mention the user responsible for a build on Circle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commands: | |
notify-slack-deploy-complete: | |
steps: | |
- slack/status: | |
mentions: "$(.circleci/utility/github_username_to_slack_uid $CIRCLE_USERNAME)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.