Skip to content

Commit

Permalink
Add tree support, for finding lists of files at a specific revision
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Jul 6, 2011
1 parent 413f15b commit 03bc23c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/octopi/tree.rb
@@ -0,0 +1,15 @@
module Octopi
class Tree < Base
attr_accessor :name, :size, :sha, :mode, :mime_type, :type, :user, :repository

def self.find(options)
ensure_hash(options)
user, repo = gather_details(options)
route = "/tree/show/#{user}/#{repo}/#{options[:sha]}"
trees = Api.api.get(route)["tree"].map do |tree|
Tree.new(tree.merge(:user => user, :repository => repo))
end
TreeSet.new(trees)
end
end
end
11 changes: 11 additions & 0 deletions lib/octopi/tree_set.rb
@@ -0,0 +1,11 @@
require File.join(File.dirname(__FILE__), "tree")
class Octopi::TreeSet < Array
include Octopi
attr_accessor :user, :repository

def initialize(array)
self.user = array.first.user
self.repository = array.first.repository
super(array)
end
end
15 changes: 15 additions & 0 deletions test/tree_test.rb
@@ -0,0 +1,15 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))

class TreeTest < Test::Unit::TestCase
include Octopi

def setup
fake_everything
end

should "be able to find a tree set" do
shared_options = { :user => "fcoury", :repo => "octopi"}
branch = Branch.all(shared_options).detect { |b| b.name == "master" }
assert Tree.find(shared_options.merge!(:sha => branch.sha)).is_a?(TreeSet)
end
end

0 comments on commit 03bc23c

Please sign in to comment.