Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2014 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/f8bf864a7f6b40383278 to your computer and use it in GitHub Desktop.
Save anonymous/f8bf864a7f6b40383278 to your computer and use it in GitHub Desktop.
search my bitbucket repositories
#!/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
@forficate
Copy link

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.

url = "https://bitbucket.org/#{owner}/#{name}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment