Skip to content

Commit ba5ad8d

Browse files
committed
WIP for issue awestruct#73
1 parent 37c2f14 commit ba5ad8d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

Diff for: helpers/repository.rb

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
module AwestructWebEditor
1212
class Repository
1313

14-
attr_reader :name, :uri
14+
attr_reader :name
1515
attr_accessor :relative_path
1616

1717
def initialize(content = [])
1818
@name = content['name'] || content[:name] || ''
19-
@uri = content['uri'] || content[:uri] || ''
2019
@relative_path = content['relative_path'] || content[:relative_path] || nil
2120

2221
log_file = File.new(File.join((ENV['OPENSHIFT_RUBY_LOG_DIR'] || 'log'), 'application.log' ), 'a+')
@@ -67,7 +66,7 @@ def clone_repo
6766
github = create_github_client
6867
begin
6968
@logger.info 'creating github fork'
70-
fork_response = github.fork(URI(@settings['repo']).path[1..-1])
69+
fork_response = github.fork(@settings['repo'])
7170
rescue Exception => e
7271
return [500, e.message]
7372
end
@@ -80,7 +79,7 @@ def clone_repo
8079
git.add_remote('upstream', fork_response.parent.clone_url)
8180

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

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

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

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

217215
def pull_request(title, body)
218216
github = create_github_client
219-
upstream_repo = Octokit::Repository.from_url @settings['repo']
217+
upstream_repo = Octokit::Repository.new @settings['repo']
220218
upstream_response = github.repository(upstream_repo)
221219
@logger.info "Issuing a pull request with title - #{title} and body #{body}"
222220
pull_request_result = github.create_pull_request(upstream_repo,

Diff for: public_app.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'date'
44
require 'digest/sha2'
55
require 'securerandom'
6-
require 'uri'
76

87
# External
98
require 'bundler'
@@ -108,15 +107,15 @@ class PublicApp < Sinatra::Base
108107
end
109108

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

115114
put '/settings' do
116-
settings = read_settings().merge({ 'repo' => params['repo'] })
115+
settings = read_settings().merge({ 'repo' => params['repo'].sub(%r{^((([email protected]:)|(https(s)?://github.com/)?))},'').sub(/\.git$/,'') })
117116
logger.debug "Settings: #{settings}"
118117
get_github_token settings
119-
repo = AwestructWebEditor::Repository.new(:name => URI(settings['repo']).path.split('/').last,
118+
repo = AwestructWebEditor::Repository.new(:name => settings['repo'].split('/').last,
120119
:token => session[:github_auth], :username => session['username'])
121120
repo.init_empty
122121
repo.add_creds

0 commit comments

Comments
 (0)