Permalink
Browse files

Initial import:

  - bringing over from old repo
  - no cuke features work -- ignoring those for now
  - simple info and display work
  • Loading branch information...
0 parents commit 2039dd25f1e92c417610e42bccac340624b6da8e @rsanheim committed Aug 6, 2010
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
@@ -0,0 +1,21 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+
+## PROJECT::SPECIFIC
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Rob Sanheim
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
+= nachos
+
+Description goes here.
+
+== Workflow
+
+* watch a project on github
+* run 'nachos sync'
+* magic - it is now up to date in your local repo and ready to go
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2010 Rob Sanheim. See LICENSE for details.
@@ -0,0 +1,52 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "nachos"
+ gem.summary = %Q{TODO: one-line summary of your gem}
+ gem.description = %Q{TODO: longer description of your gem}
+ gem.email = "rsanheim@gmail.com"
+ gem.homepage = "http://github.com/rsanheim/nachos"
+ gem.authors = ["Rob Sanheim"]
+ gem.add_dependency "octopussy"
+ # may want to vendor this...could conflict with the manual install folks
+ gem.add_dependency "git-hub"
+ gem.add_development_dependency "rspec", "~> 2.0.0.beta.12"
+ gem.add_development_dependency "faker"
+ gem.add_development_dependency "mocha"
+ gem.add_development_dependency "fakeweb"
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+if RUBY_VERSION <= "1.8.7"
+ RSpec::Core::RakeTask.new(:coverage) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
+ spec.rcov = true
+ end
+else
+ task :coverage => :spec
+end
+
+task :spec => :check_dependencies
+
+task :default => [:check_dependencies, :coverage]
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "nachos #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'nachos'
+rescue LoadError => e
+ require File.join(File.dirname(__FILE__), *%w[.. lib nachos])
+end
+Nachos.execute(*ARGV)
@@ -0,0 +1,29 @@
+Feature: General diagnostic info
+ In order to something something
+ A user something something
+ something something something
+
+ Scenario: Displaying user info
+ Given I am locally configured for Github as "john-doe"
+ When I execute nachos "info"
+ Then I should see "You are running nachos as john-doe"
+ And the exit status should be 0
+
+ Scenario: Syncing watched repos
+ Given I am locally configured for Github as "john-doe"
+ And I have "3" watched repositories on Github
+ And I expect nachos to clone all watched repositories
+ When I execute nachos "sync"
+ Then the exit status should be 0
+ And the stdout should contain "About to sync 3 repositories"
+
+ @announce @wip
+ Scenario: Syncing watched repos when some are already cloned
+ Given I am locally configured for Github as "john-doe"
+ And I have a watched repo named "jdoe/twitter" that is cloned locally
+ And I have a watched repo named "rspec/rspec" that is not cloned locally
+ And I expect nachos to fetch "jdoe/twitter"
+ And I expect nachos to clone "rspec/rspec"
+ When I execute nachos "sync"
+ Then the exit status should be 0
+
@@ -0,0 +1,49 @@
+Given /^I am locally configured for Github as "([^\"]*)"$/ do |username|
+ Helper.current_user = username
+ Nachos.any_instance.stubs(:github_user).returns(username)
+ Nachos.any_instance.stubs(:github_token).returns("some-valid-token")
+end
+
+When /^I execute nachos "([^"]*)"$/ do |args|
+ require 'stringio'
+ begin # emulating how Aruba works, so we can use the same matchers
+ Nachos.stdout, @original_stdout = StringIO.new, Nachos.stdout
+ nachos = Nachos.execute(args)
+ output = nachos.out
+ output.rewind
+ @last_stdout = output.read
+ # @last_stderr...
+ @last_exit_status = nachos.exit_code
+ rescue => e
+ p e; e.message
+ puts e.backtrace[0..10].join("\n")
+ ensure
+ Nachos.stdout = @original_stdout
+ end
+end
+
+Given /^I have "([^\"]*)" watched repositories on Github$/ do |num_repos|
+ Helper.watched_repos = []
+ num_repos.to_i.times do |i|
+ Helper.watched_repos << {
+ "url" => "http://github.com/jnunemaker/twitter_#{i}",
+ "description" => "API wrapper for Twitter and Twitter Search API's",
+ "open_issues" => 7,
+ "homepage" => "http://twitter.rubyforge.org/",
+ "watchers" => 609,
+ "fork" => false,
+ "forks" => 120,
+ "private" => false,
+ "name" => "twitter_#{i}",
+ "owner" => "jnunemaker",
+ "pledgie" => 1193
+ }
+ end
+ body = { "repositories" => Helper.watched_repos }.to_json
+ url = "http://github.com/api/v2/json/repos/watched/#{Helper.current_user}?"
+ FakeWeb.register_uri(:get, url, :body => body)
+end
+
+Given /^I expect nachos to clone all watched repositories$/ do
+ Nachos.any_instance.stubs(:system).with(includes("git clone"))
+end
@@ -0,0 +1,38 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
+require 'log_buddy'
+require 'nachos'
+require 'aruba'
+require 'mocha'
+require 'json'
+require 'rspec/core'
+
+Before do
+ bin_path = File.join(File.dirname(__FILE__), *%w[.. .. bin])
+ ENV["PATH"] = "#{ENV["PATH"]}:#{bin_path}"
+ system('which nachos > /dev/null') || abort('nachos not on the path - binary features will not work')
+end
+
+module ArubaOverrides
+ def detect_ruby_script(cmd)
+ if cmd =~ /^nachos/
+ "ruby -I../../lib -I./fakeweb -S ../../bin/#{cmd}"
+ else
+ super(cmd)
+ end
+ end
+end
+
+module Helper
+ extend self
+ attr_accessor :watched_repos
+ def current_user=(user)
+ @current_user = user
+ end
+ def current_user
+ @current_user || raise("No current user set")
+ end
+end
+
+World(Mocha::API)
+World(ArubaOverrides)
+World(Helper)
@@ -0,0 +1,2 @@
+require 'fakeweb'
+FakeWeb.allow_net_connect = false
@@ -0,0 +1,38 @@
+require "octopussy"
+require "hub"
+require "thor"
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
+
+class Nachos; end
+
+require 'nachos/cli'
+require 'nachos/github'
+
+class Nachos
+
+ attr_reader :args, :command
+ attr_accessor :out, :err, :exit_code
+
+ def initialize(*args)
+ @args = args
+ @command = args.first || "help"
+ @exit_code = 0
+ end
+
+ def self.execute(*args)
+ new(*args).execute
+ end
+
+ def runner
+ @runner ||= Runner.new
+ end
+
+ def execute
+ Nachos::CLI.start
+ exit 0
+ end
+
+ def Hub(args)
+ Hub::Runner.new(*args.split(' '))
+ end
+end
@@ -0,0 +1,76 @@
+class Nachos::CLI < Thor
+
+ LGHCONF = "http://github.com/guides/local-github-config"
+ GIT_CONFIG = Hash.new do |cache, cmd|
+ result = %x{git #{cmd}}.chomp
+ cache[cmd] = $?.success? && !result.empty? ? result : nil
+ end
+
+ desc "info", "Displays current setup for Nachos"
+ def info
+ shell.say <<-EOL
+You are running nachos as #{github_user}.
+#{github_summary}
+Current configuration: #{config}
+EOL
+ end
+
+ desc "watched", "Display your watched repos on Github"
+ def watched
+ github.watched.each do |repo|
+ shell.say "#{repo.owner}/#{repo.name} - #{repo.description}"
+ end
+ end
+
+ desc "sync", "Sync repositories"
+ def sync
+ repos = github.watched
+ shell.say "About to sync #{repos.size} repositories"
+ repos.each do |repo|
+ system Hub("clone #{repo.url}").command
+ end
+ end
+
+ private
+
+ def github_summary
+ "You have #{github.watched.size} watched repos, and #{github.client.list_repos.size} owned repos."
+ end
+
+ def config
+ config_path.exist? ? load_config : "No config found - run nachos config to create one"
+ end
+
+ def config_path
+ Pathname(ENV["HOME"]).join(".nachos")
+ end
+
+ def load_config
+ YAML.load_file(config_path)
+ end
+
+ def github
+ @github ||= Nachos::Github.new(github_user, github_token)
+ end
+
+ # Either returns the GitHub user as set by git-config(1) or aborts
+ # with an error message.
+ def github_user(fatal = true)
+ if user = GIT_CONFIG['config github.user']
+ user
+ elsif fatal
+ abort("** No GitHub user set. See #{LGHCONF}")
+ end
+ end
+
+ def github_token(fatal = true)
+ if token = GIT_CONFIG['config github.token']
+ token
+ elsif fatal
+ abort("** No GitHub token set. See #{LGHCONF}")
+ end
+ end
+
+
+
+end
@@ -0,0 +1,17 @@
+class Nachos
+
+ class Github
+ attr_reader :client
+
+ def initialize(github_user, github_token)
+ @client = Octopussy::Client.new(:login => github_user, :token => github_token)
+ end
+
+ def watched
+ client.watched.sort_by do |repo|
+ [repo["owner"], repo["name"]].join("/")
+ end
+ end
+
+ end
+end
Oops, something went wrong.

0 comments on commit 2039dd2

Please sign in to comment.