class Anticuado::GitHub
Attributes
client[R]
git[R]
repo_name[R]
repo_uri[R]
Public Class Methods
new(repository_name, enterprise: true, api_endpoint: nil)
click to toggle source
# File lib/anticuado/github.rb, line 8 def initialize(repository_name, enterprise: true, api_endpoint: nil) @repo_name = repository_name @client = if enterprise ::Octokit::Client.new( access_token: ENV['GHE_ACCESS_TOKEN'] || 'dummy_token', api_endpoint: api_endpoint || ENV['GHE_API_ENDPOINT'], # 'https://example.api.endpoint/api/v3/' ) else ::Octokit::Client.new(access_token: ENV['GITHUB_TOKEN']) end @repo_uri = "git@#{URI.parse(enterprise ? @client.api_endpoint : @client.web_endpoint).host}:#{@repo_name}.git" end
Public Instance Methods
clone_or_open_to(target_path)
click to toggle source
# File lib/anticuado/github.rb, line 22 def clone_or_open_to(target_path) @git = begin ::Git.clone(@repo_uri, target_path) rescue g = ::Git.open(target_path) g.pull g end end
create_a_new_pull_request(base_branch:, head_branch: (Time.now.strftime '%Y%m%d-%H%M%S'), update_libraries: nil)
click to toggle source
# File lib/anticuado/github.rb, line 32 def create_a_new_pull_request(base_branch:, head_branch: (Time.now.strftime '%Y%m%d-%H%M%S'), update_libraries: nil) remote_name = 'origin' begin create_a_branch_local head_branch commit_all_changes git_push_to_remote remote_name, head_branch create_pull_request(base_branch: base_branch, head_branch: head_branch, title: github_pr_title(head_branch), body: github_pr_body(update_libraries)) delete_a_branch_local head_branch rescue Git::GitExecuteError => e puts "no changes: #{e}, #{e.message}" end end
Private Instance Methods
commit_all_changes()
click to toggle source
# File lib/anticuado/github.rb, line 65 def commit_all_changes @git.commit_all(commit_all_changes_message) end
commit_all_changes_message()
click to toggle source
# File lib/anticuado/github.rb, line 61 def commit_all_changes_message "update libraries" end
create_a_branch_local(branch_name)
click to toggle source
# File lib/anticuado/github.rb, line 69 def create_a_branch_local(branch_name) @git.branch(branch_name).checkout end
create_pull_request(base_branch:, head_branch:, title:, body:)
click to toggle source
# File lib/anticuado/github.rb, line 82 def create_pull_request(base_branch:, head_branch:, title:, body:) @client.create_pull_request @repo_name, base_branch, head_branch, title, body end
delete_a_branch_local(branch_name)
click to toggle source
# File lib/anticuado/github.rb, line 73 def delete_a_branch_local(branch_name) @git.checkout # We should change current branch first @git.branch(branch_name).delete end
git_push_to_remote(remote_name, head_branch)
click to toggle source
# File lib/anticuado/github.rb, line 78 def git_push_to_remote(remote_name, head_branch) @git.push(remote_name, head_branch) end
github_pr_body(update_libraries)
click to toggle source
# File lib/anticuado/github.rb, line 54 def github_pr_body(update_libraries) return 'update libraries' if update_libraries.nil? update_libraries.reduce("# Update libraries\n") do |acc, library| acc << "- #{library}\n" end end
github_pr_title(message)
click to toggle source
# File lib/anticuado/github.rb, line 50 def github_pr_title(message) "update #{message}" end