Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -226,6 +226,15 @@ class PublicApp < Sinatra::Base
[200, JSON.dump(json_return)]
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