Skip to content

Commit

Permalink
Working on branch name setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Coutu authored and Julian Coutu committed Dec 23, 2010
1 parent 5d4c030 commit 1b8e011
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
24 changes: 20 additions & 4 deletions lib/gitnetworkitis/network_data.rb
Expand Up @@ -2,20 +2,36 @@ module GitNetworkitis
class NetworkData < Base
base_uri 'https://github.com/'

attr_accessor :commits
attr_accessor :commits, :network_meta

def find(options={})
if options.has_key?(:owner) & options.has_key?(:repo) & options.has_key?(:nethash)
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{options[:nethash]}")
if options.has_key?(:owner) & options.has_key?(:repo) & options.has_key?(:network_meta)
self.network_meta = options[:network_meta]
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
result.push parse_attributes(commit, Commit.new(self.username, self.token))
#result.push parse_attributes(commit, Commit.new(self.username, self.token))
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
result.push temp_commit
end
self.commits = result
set_branch_names
#This seems weird but what if later the api adds more data at this level? We could just return commits and change the name.
return self
end
end

def set_branch_names()
branch_number = 0
network_meta.branches.each do |branch|
current = commits.select{|v| v.id == branch.id} #=> ["a", "e"]}
if !current.empty?
current.each
puts current.first.parents[0][0].inspect
end
branch_number.next
end
end
end
end
20 changes: 20 additions & 0 deletions spec/commit_spec.rb
Expand Up @@ -6,4 +6,24 @@
fake_responses
end

context "branch" do
let(:tester){GitNetworkitis::NetworkMeta.new(@username, @token)}
let(:network_meta){tester.find({:owner=>"turingstudio", :repo => "loupe"})}
let(:network_data){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_data.find({:owner=>"turingstudio", :repo => "loupe", :network_meta => network_meta})}

it "should set the commits branch to correct name for the 'master' branch" do
test.commits.should_not be_empty
test.commits.first.branch.name.should == "master"
end

it "should set the commits branch to correct name for the 'git_network_api' branch" do
test.commits.should_not be_empty
test.commits.last.parents.should_not be_empty
test.commits.last.branch.name.should == "git_network_api"
test.commits.each do |commit|
puts commit.parents.inspect
end
end
end
end
10 changes: 8 additions & 2 deletions spec/network_data_spec.rb
Expand Up @@ -7,8 +7,10 @@
end

context "find" do
let(:network_meta){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_meta.find({:owner=>"turingstudio", :repo => "loupe", :nethash => "26fb01d365a6f7ea57be92299803cae7b95ae25a"})}
let(:tester){GitNetworkitis::NetworkMeta.new(@username, @token)}
let(:network_meta){tester.find({:owner=>"turingstudio", :repo => "loupe"})}
let(:network_data){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_data.find({:owner=>"turingstudio", :repo => "loupe", :network_meta => network_meta})}

before :each do
fake_responses
Expand All @@ -19,5 +21,9 @@
test.commits.first.parents.should be_empty
test.commits.first.login.should == "stephenjudkins"
end

it "should set the network_meta" do
test.network_meta.should == network_meta
end
end
end
2 changes: 1 addition & 1 deletion spec/responses/repos_show_turingstudio_loupe_branches.json
@@ -1 +1 @@
{"branches":{"test_branch_1":"c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e","master":"51ac36280d2dfe16c37b66ef344859c9c714c8e1","git_network_api":"bec7b23dc57b14d89fa2829e8c32a108a18e7248"}}
{"branches":{"master":"51ac36280d2dfe16c37b66ef344859c9c714c8e1","git_network_api":"bec7b23dc57b14d89fa2829e8c32a108a18e7248","test_branch_1":"c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e"}}
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -29,7 +29,7 @@ def response_file(*path)

def fake_responses
if @fake_web_requests
FakeWeb.allow_net_connect = false
FakeWeb.allow_net_connect = true
FakeWeb.clean_registry
auth = "#{@username}%2Ftoken:#{@token}@"
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/watched/jcoutu", :body => response_file('repos_watched_jcoutu.json'))
Expand Down

0 comments on commit 1b8e011

Please sign in to comment.