Skip to content

Commit

Permalink
Initial commit for issue awestruct#77 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LightGuard committed Nov 4, 2013
1 parent b7b7216 commit 38aacbc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion helpers/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def create_branch(branch_name)
system("git checkout -b #{branch_name} upstream/#{upstream_repo.master_branch}")
end

def switch_branch(branch_name)
@git_repo.checkout branch_name, {:force => true}
[200, '']
end

def rebase(overwrite, remote = 'upstream')
fetch_remote remote
upstream_repo = create_github_client.repository(Octokit::Repository.from_url @settings['repo'])
Expand Down Expand Up @@ -206,7 +211,23 @@ def remove_branch(branch_name)
end

def branches
@git_repo.branches
@logger.debug "Fetching local branches and notes"
Open3.popen3('git show --format="||%d||%h||%N" --notes=pull $(git notes --ref=pull | awk "{ print $2 }") | awk "{ if ($1 ~ /\|\|/) { print $0 } }',
:chdir => File.absolute_path(base_repository_path)) do |_, stdout, stderr, wait_thr|
exit_value = wait_thr.value
@logger.debug "fetch exit status: #{exit_value}"
error = stderr.readlines.join "\n"
@logger.debug "fetch error: #{error}" unless error.empty?

returns = []
stdout.readlines.each do |line|
_, branches, pull = line.split '||'
branches = branches.strip.gsub(/[()]/, '').split(',').last.strip
returns << {:pull => pull, :branch => branches}
end

returns
end
end

def push(remote = 'origin')
Expand Down
9 changes: 9 additions & 0 deletions public_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ class PublicApp < Sinatra::Base
[200, JSON.dump(return_links)]
end

get '/repo/:repo_name/branches' do |repo_name|
repo = create_repo(repo_name)
[200, JSON.dump(repo.branches)]
end

post '/repo/:repo_name/branches/:branch_name' do |repo_name, branch_name|
repo = create_repo(repo_name).switch_branch branch_name
end

get '/repo/:repo_name/*' do |repo_name, path|
repo = create_repo(repo_name)
json_return = { :content => repo.file_content(path), :links => links_for_file(repo.file_info(path), repo_name) }
Expand Down

0 comments on commit 38aacbc

Please sign in to comment.