forked from fcoury/octopi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tree support, for finding lists of files at a specific revision
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |