module Gitx::Github
Constants
- CLIENT_URL
- GLOBAL_CONFIG_FILE
- PULL_REQEST_TEMPLATE_FILE
- PULL_REQUEST_FOOTER
- REVIEW_CONTEXT
Public Instance Methods
ask_without_echo(message)
click to toggle source
# File lib/gitx/github.rb, line 187 def ask_without_echo(message) value = ask(message, echo: false) say '' value end
branch_status(branch)
click to toggle source
Get the current commit status of a branch @see developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
# File lib/gitx/github.rb, line 50 def branch_status(branch) response = github_client.status(github_slug, branch) response.state end
create_pull_request(branch)
click to toggle source
@see developer.github.com/v3/pulls/
# File lib/gitx/github.rb, line 66 def create_pull_request(branch) say 'Creating pull request for ' say "#{branch} ", :green say 'against ' say "#{config.base_branch} ", :green say 'in ' say github_slug, :green title = pull_request_title(branch) body = pull_request_body(branch) github_client.create_pull_request(github_slug, config.base_branch, branch, title, body) end
find_or_create_pull_request(branch)
click to toggle source
# File lib/gitx/github.rb, line 22 def find_or_create_pull_request(branch) pull_request = find_pull_request(branch) pull_request ||= begin checkout_branch(branch) run_git_cmd 'update' pull_request = create_pull_request(branch) say 'Created pull request: ' say pull_request.html_url, :green pull_request end pull_request end
find_pull_request(branch)
click to toggle source
@return [Sawyer::Resource] data structure of pull request info if found @return nil if no pull request found
# File lib/gitx/github.rb, line 38 def find_pull_request(branch) head_reference = "#{github_organization}:#{branch}" params = { head: head_reference, state: 'open' } pull_requests = github_client.pull_requests(github_slug, params) pull_requests.first end
github_client()
click to toggle source
# File lib/gitx/github.rb, line 140 def github_client @github_client ||= Octokit::Client.new(access_token: authorization_token) end
github_client_name()
click to toggle source
# File lib/gitx/github.rb, line 135 def github_client_name timestamp = Time.now.utc.strftime('%FT%R:%S%z') "Git eXtensions #{timestamp}" end
github_organization()
click to toggle source
# File lib/gitx/github.rb, line 163 def github_organization github_slug.split('/').first end
github_slug()
click to toggle source
@return the github slug for the current repository's remote origin url. @example
git@github.com:socialcast/wireframe/gitx.git #=> wireframe/gitx
@example
https://github.com/wireframe/gitx.git #=> wireframe/gitx
# File lib/gitx/github.rb, line 158 def github_slug remote = repo.config['remote.origin.url'] remote.to_s.gsub(/\.git$/, '').split(%r{[:/]}).last(2).join('/') end
global_config()
click to toggle source
# File lib/gitx/github.rb, line 171 def global_config @global_config ||= File.exist?(global_config_file) ? YAML.load_file(global_config_file) : {} end
global_config_file()
click to toggle source
# File lib/gitx/github.rb, line 167 def global_config_file File.expand_path(GLOBAL_CONFIG_FILE) end
label_pull_request(pull_request, label)
click to toggle source
# File lib/gitx/github.rb, line 61 def label_pull_request(pull_request, label) github_client.add_labels_to_an_issue(github_slug, pull_request.number, [label]) end
pull_request_body(branch)
click to toggle source
# File lib/gitx/github.rb, line 79 def pull_request_body(branch) changelog = run_git_cmd('log', "origin/#{config.base_branch}...#{branch}", '--reverse', '--no-merges', '--pretty=format:* %B') description = options[:description] description_template = [] description_template << "#{description}\n" if description description_template << changelog description_template << "#{pull_request_template}\n" if pull_request_template ask_editor(description_template.join("\n"), editor: repo.config['core.editor'], footer: PULL_REQUEST_FOOTER) end
pull_request_template()
click to toggle source
# File lib/gitx/github.rb, line 99 def pull_request_template @pull_request_template ||= File.exist?(pull_request_template_file) ? File.read(pull_request_template_file) : nil end
pull_request_template_file()
click to toggle source
# File lib/gitx/github.rb, line 95 def pull_request_template_file File.expand_path(PULL_REQEST_TEMPLATE_FILE) end
pull_request_title(branch)
click to toggle source
# File lib/gitx/github.rb, line 91 def pull_request_title(branch) options[:title] || branch.gsub(/[-_]/, ' ') end
save_global_config(options)
click to toggle source
# File lib/gitx/github.rb, line 175 def save_global_config(options) config_dir = File.dirname(global_config_file) ::FileUtils.mkdir_p(config_dir, mode: 0o700) unless File.exist?(config_dir) @config = global_config.merge(options) File.open(global_config_file, 'a+') do |file| file.truncate(0) file.write(@config.to_yaml) end File.chmod(0o600, global_config_file) end
update_review_status(pull_request, state, description)
click to toggle source
Update build status with peer review status
# File lib/gitx/github.rb, line 56 def update_review_status(pull_request, state, description) commit_sha = pull_request.head.sha github_client.create_status(github_slug, commit_sha, state, context: REVIEW_CONTEXT, description: description) end
username()
click to toggle source
@return [String] github username (ex: 'wireframe') of the current github.user @raise error if github.user is not configured
# File lib/gitx/github.rb, line 146 def username username = repo.config['github.user'] raise "Github user not configured. Run: `git config --global github.user 'me@email.com'`" unless username username end