Skip to content

Instantly share code, notes, and snippets.

@thomet
Created January 23, 2017 12:08
Show Gist options
  • Save thomet/3fc834ba60464f9ea54ea0b8042a7082 to your computer and use it in GitHub Desktop.
Save thomet/3fc834ba60464f9ea54ea0b8042a7082 to your computer and use it in GitHub Desktop.
BitBar plugin: Amount of Github PR's and Commits for a specific search term
#!/usr/bin/env ruby
#
# <bitbar.title>Amount of Github PR's and Commits for a specific search term</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Thomas Metzmacher</bitbar.author>
# <bitbar.author.github>thomet</bitbar.author.github>
# <bitbar.desc>Shows the count of Github PR's and Commits which matches a specifc search term.</bitbar.desc>
# <bitbar.dependencies>ruby</bitbar.dependencies>
#
require 'json'
require 'net/http'
### CONFIG ###
# Create a personal access token: https://github.com/settings/tokens
GITHUB_AUTH_TOKEN = ''
# Only for repos from this user/company
REPO_USER = ''
SEARCH_TERM = ''
### END CONFIG ###
def get_json(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri, {'Authorization' => 'token ' + GITHUB_AUTH_TOKEN, 'Accept' => 'application/vnd.github.cloak-preview'})
response = http.request(request)
JSON.parse(response.body)
end
pnh_prs = get_json("https://api.github.com/search/issues?q=type:pr+user:#{REPO_USER}+#{SEARCH_TERM}")
pnh_commits = get_json("https://api.github.com/search/commits?q=user:#{REPO_USER}+#{SEARCH_TERM}")
puts "PNH PRs: #{pnh_prs['total_count']}, Commits': #{pnh_commits['total_count']}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment