Skip to content

Instantly share code, notes, and snippets.

@jeroenbegyn
Last active December 16, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenbegyn/5385092 to your computer and use it in GitHub Desktop.
Save jeroenbegyn/5385092 to your computer and use it in GitHub Desktop.
Bitbucket followers job for Dashing

Description

Simple Dashing job to display a users Bitbucket followers. Uses Bitbucket's API. Based on Ephigenia's GitHub examples

##Usage

To use this widget put the bitbucket_user_followers.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippets to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
  <div data-id="bitbucket_user_followers" data-view="List" data-unordered="true" data-title="Bitbucket Followers" data-moreinfo="List of followers"></div>
</li>

<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
  <div data-id="bitbucket_user_followers_count" data-view="Number" data-title="Bitbucket Followers"></div>
</li>

##Settings

You'll need to add the Bitbucket username for the users you want to track to the job. This can be done by editing the 'bitbucket_username' variable in the job.

You can also change how many followers are fetched and how they are orderd by setting the 'max_lenght' and the 'orderd' properties in the job.

The followers are fetched every 5 minutes, but you can change that by editing the job schedule.

#!/usr/bin/env ruby
require 'net/http'
require 'json'
# This job will track folowers of a bitbucket organisation or user
# Config
# ------
# example for tracking single user followers
bitbucket_username = ENV['BITBUCKET_USERINFO_USERNAME'] || 'jbegyn'
# number of flowers to display in the list
max_length = 7
# order the list by the usernames
ordered = true
SCHEDULER.every '5m', :first_in => 0 do |job|
http = Net::HTTP.new("api.bitbucket.org", Net::HTTP.https_default_port())
http.use_ssl = true
req = Net::HTTP::Get.new("/1.0/users/#{bitbucket_username}/followers/")
response = http.request(req)
if response.code != "200"
puts "bitbucket api error (status-code: #{response.code})\n#{response.body}"
else
data = JSON.parse(response.body)
user_followers = Array.new
data['followers'].each do |follower|
user_followers.push({
label: 'Name',
value: follower['display_name']
})
end
if ordered
user_followers = user_followers.sort_by { |obj| obj[:value] }
end
send_event('bitbucket_user_followers_count', current: data['count'])
send_event('bitbucket_user_followers', { items: user_followers.slice(0, max_length) })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment