Created
September 11, 2014 10:00
-
-
Save anonymous/f8bf864a7f6b40383278 to your computer and use it in GitHub Desktop.
search my bitbucket repositories
This file contains hidden or 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 | |
# encoding: utf-8 | |
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8 | |
require_relative "bundle/bundler/setup" | |
require "alfred" | |
require 'json' | |
basic_user = ENV['BB_USER_NAME'] | |
basic_password = ENV['BB_PASSWORD'] | |
cache = "/tmp/bb-repositories.json" | |
Alfred.with_friendly_error do |alfred| | |
alfred.with_rescue_feedback = true | |
fb = alfred.feedback | |
if File.exists?(cache) and File.stat(cache).mtime > Time.now - 60*60*2 | |
j = File.read(cache) | |
else | |
j = `curl --silent --user #{basic_user}:#{basic_password} https://bitbucket.org/api/1.0/user/repositories` | |
File.write(cache, j) | |
end | |
added = [] | |
JSON.load(j).sort_by{|o| o['name']}.each do |o| | |
name = o['name'] | |
next if added.include? name | |
added << name | |
url = "https://bitbucket.org/#{basic_user}/#{name}" | |
fb.add_item({ | |
:uid => "", | |
:title => "#{name}", | |
:subtitle => "#{o['description']} #{url}", | |
:arg => url, | |
:valid => "yes", | |
}) | |
end | |
if ARGV[0].eql? "failed" | |
alfred.with_rescue_feedback = true | |
raise Alfred::NoBundleIDError, "Wrong Bundle ID Test!" | |
end | |
puts fb.to_xml(ARGV) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this script. I made a small tweak at https://gist.github.com/ajevans85/5225e851a8171610cca3
Basically the url value uses the owner value from the json response rather than user so you can open repositories shared with you that you do not own.