Skip to content

Instantly share code, notes, and snippets.

@Gerg
Last active August 29, 2015 13:56
Show Gist options
  • Save Gerg/8922478 to your computer and use it in GitHub Desktop.
Save Gerg/8922478 to your computer and use it in GitHub Desktop.
Set HipChat display name when using Git-Pair

Git Pair + HipChat

This script makes your git pair automatically update the display name for your workstation's HipChat account.

Dependencies

  1. You need a (HipChat)[https://www.hipchat.com/] account for each workstation
  2. You need to have (git pair)[https://github.com/pivotal/git_scripts] set up

Setup

  1. Install hipchat-api gem gem install hipchat-api
  2. Rename your existing git-pair script to git-pair-original
  3. Put this script where your old pair script was
  4. Add your HipChat API key to the gist on line 8
  5. Add your email domain to the gitst on line 13

Use

Type git pair bla blu as usual

Acknowledgments

Built at Pivotal Labs

#!/usr/bin/env ruby
require 'hipchat-api'
`/usr/local/bin/git-pair-original #{ARGV.join(' ')}`
hostname = `hostname`.strip
api = HipChat::API.new('<API KEY GOES HERE>')
api.set_timeout(10)
response = api.users_list
users = response['users']
target_email = "#{hostname}@<EMAIL>.com"
machine_user = users.find { |x| x['email'] == target_email }
machine_id = machine_user['user_id']
git_username = `git config user.name`.strip
just_names = git_username.split(/,|and/).map(&:strip).keep_if { |x| x.length > 0 }
just_first_names = just_names.map { |n| n.split()[0] }
friendly_first_names = just_first_names.join " & "
hipchat_name = friendly_first_names + " (@#{hostname})"
api.users_update(machine_id, nil, hipchat_name)
puts "Changed HipChat name for this machine to: #{hipchat_name}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment