Skip to content

Commit

Permalink
WIP for issue awestruct#73
Browse files Browse the repository at this point in the history
  • Loading branch information
LightGuard committed Nov 2, 2013
1 parent e3f694d commit de0741f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 7 additions & 9 deletions helpers/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
module AwestructWebEditor
class Repository

attr_reader :name, :uri
attr_reader :name
attr_accessor :relative_path

def initialize(content = [])
@name = content['name'] || content[:name] || ''
@uri = content['uri'] || content[:uri] || ''
@relative_path = content['relative_path'] || content[:relative_path] || nil

log_file = File.new(File.join((ENV['OPENSHIFT_RUBY_LOG_DIR'] || 'log'), 'application.log' ), 'a+')
Expand Down Expand Up @@ -67,7 +66,7 @@ def clone_repo
github = create_github_client
begin
@logger.info 'creating github fork'
fork_response = github.fork(URI(@settings['repo']).path[1..-1])
fork_response = github.fork(@settings['repo'])
rescue Exception => e
return [500, e.message]
end
Expand All @@ -80,7 +79,7 @@ def clone_repo
git.add_remote('upstream', fork_response.parent.clone_url)

@logger.debug 'pulling from git'
Open3.popen3("git pull upstream master") do |_, _, stderr, wait_thr|
Open3.popen3('git pull upstream master') do |_, _, stderr, wait_thr|
exit_value = wait_thr.value
@logger.debug "pull exit status: #{exit_value}"
error = stderr.readlines.join "\n"
Expand Down Expand Up @@ -163,8 +162,7 @@ def commit(message)

def fetch_remote(remote = 'upstream')
@logger.info "Fetching remote #{remote}"
Open3.popen3("git fetch #{remote}",
:chdir => File.absolute_path(base_repository_path)) do |_, _, stderr, wait_thr|
Open3.popen3("git fetch #{remote}", :chdir => File.absolute_path(base_repository_path)) do |_, _, stderr, wait_thr|
exit_value = wait_thr.value
@logger.debug "fetch exit status: #{exit_value}"
error = stderr.readlines.join "\n"
Expand All @@ -173,15 +171,15 @@ def fetch_remote(remote = 'upstream')
end

def create_branch(branch_name)
upstream_repo = create_github_client.repository(Octokit::Repository.from_url @settings['repo'])
upstream_repo = create_github_client.repository(Octokit::Repository.new @settings['repo'])
fetch_remote
@logger.info "creating branch #{branch_name} based on 'upstream/#{upstream_repo.master_branch}'"
system("git checkout -b #{branch_name} upstream/#{upstream_repo.master_branch}")
end

def rebase(overwrite, remote = 'upstream')
fetch_remote remote
upstream_repo = create_github_client.repository(Octokit::Repository.from_url @settings['repo'])
upstream_repo = create_github_client.repository(Octokit::Repository.new @settings['repo'])
Dir.chdir(File.join @base_repo_dir) do
if overwrite
@logger.debug 'overwriting our files during the rebase'
Expand Down Expand Up @@ -216,7 +214,7 @@ def push(remote = 'origin')

def pull_request(title, body)
github = create_github_client
upstream_repo = Octokit::Repository.from_url @settings['repo']
upstream_repo = Octokit::Repository.new @settings['repo']
upstream_response = github.repository(upstream_repo)
@logger.info "Issuing a pull request with title - #{title} and body #{body}"
pull_request_result = github.create_pull_request(upstream_repo,
Expand Down
7 changes: 3 additions & 4 deletions public_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'date'
require 'digest/sha2'
require 'securerandom'
require 'uri'

# External
require 'bundler'
Expand Down Expand Up @@ -108,15 +107,15 @@ class PublicApp < Sinatra::Base
end

post '/settings' do
settings = read_settings().merge({ 'repo' => params['repo'] })
settings = read_settings().merge({ 'repo' => params['repo'].sub(%r{^((([email protected]:)|(https(s)?://github.com/)?))},'').sub(/\.git$/,'') })
write_settings settings
end

put '/settings' do
settings = read_settings().merge({ 'repo' => params['repo'] })
settings = read_settings().merge({ 'repo' => params['repo'].sub(%r{^((([email protected]:)|(https(s)?://github.com/)?))},'').sub(/\.git$/,'') })
logger.debug "Settings: #{settings}"
get_github_token settings
repo = AwestructWebEditor::Repository.new(:name => URI(settings['repo']).path.split('/').last,
repo = AwestructWebEditor::Repository.new(:name => settings['repo'].split('/').last,
:token => session[:github_auth], :username => session['username'])
repo.init_empty
repo.add_creds
Expand Down

0 comments on commit de0741f

Please sign in to comment.