Class: GitHubBasecampExtractor
- Inherits:
-
Object
- Object
- GitHubBasecampExtractor
- Defined in:
- lib/gitbc.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
File.('~/.gitbc')
- DEFAULT_END_TAG =
'HEAD'- MAX_PR_BODY_LENGTH =
235
Instance Method Summary collapse
- #get_basecamp_todos(pull_requests) ⇒ Object
- #get_pull_requests_from_git_logs ⇒ Object
- #git_branch ⇒ Object
- #git_branch_exists?(branch) ⇒ Boolean
- #git_repository ⇒ Object
-
#initialize(params) ⇒ GitHubBasecampExtractor
constructor
A new instance of GitHubBasecampExtractor.
- #is_git_installed? ⇒ Boolean
- #is_git_repo? ⇒ Boolean
- #is_github_alive? ⇒ Boolean
- #remote_matches?(repo) ⇒ Boolean
- #repo_exists?(repo) ⇒ Boolean
- #revision_exists?(rev) ⇒ Boolean
- #update_options(options) ⇒ Object
Constructor Details
#initialize(params) ⇒ GitHubBasecampExtractor
Returns a new instance of GitHubBasecampExtractor.
15 16 17 18 |
# File 'lib/gitbc.rb', line 15 def initialize(params) @params = params @github_client = Octokit::Client.new(access_token: @params[:github_access_token]) end |
Instance Method Details
#get_basecamp_todos(pull_requests) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gitbc.rb', line 75 def get_basecamp_todos(pull_requests) basecamp_todos = pull_requests.inject({}) do |memo, pull_request_id| pr = @github_client.pull_request(@params[:repository], pull_request_id) basecamp_lines = pr.attrs[:body].split("\r\n").grep(/.*https\:\/\/basecamp\.com.*/) memo[pull_request_id] = {body: pr.attrs[:body][0..MAX_PR_BODY_LENGTH].strip, lines: []} if basecamp_lines.count > 0 memo[pull_request_id][:lines] = basecamp_lines.map { |line| {url: line[/.*(https\:\/\/basecamp\.com[^!?#:;,.\s]*)/, 1]} }.uniq if @params[:basecamp_content] memo[pull_request_id][:lines].each do |line| line[:url].match /(https\:\/\/basecamp\.com\/\d+\/)(.*)/ do |match| begin ret = HTTParty.get "#{match[1]}api/v1/#{match[2]}.json", {basic_auth: {username: @params[:basecamp_user], password: @params[:basecamp_password]}, headers: {'Content-Type' => 'application/json', 'User-Agent' => "gitbc API (#{@params[:basecamp_user]})"}} line[:content] = JSON.parse(ret.body)['content'] if ret != nil && ret.body.length > 0 rescue end end end end end yield(pull_request_id, memo[pull_request_id]) if block_given? memo end basecamp_todos end |
#get_pull_requests_from_git_logs ⇒ Object
20 21 22 23 |
# File 'lib/gitbc.rb', line 20 def get_pull_requests_from_git_logs lines = `git --no-pager log #{@params[:branch]} #{@params[:start_tag]}..#{@params[:end_tag]} --merges | grep 'Merge pull request #'`.split("\n") lines.map {|l| l[/.*#([0-9]+)/,1].to_i} end |
#git_branch ⇒ Object
38 39 40 |
# File 'lib/gitbc.rb', line 38 def git_branch Open3.popen3('git status') { |_, stdout, _, _| stdout.read }[/^On branch ([^\n]+)/,1] end |
#git_branch_exists?(branch) ⇒ Boolean
42 43 44 |
# File 'lib/gitbc.rb', line 42 def git_branch_exists?(branch) Open3.popen3('git branch') { |_, stdout, _, _| stdout.read } =~ /#{branch}/ end |
#git_repository ⇒ Object
46 47 48 |
# File 'lib/gitbc.rb', line 46 def git_repository Open3.popen3('git remote -v') { |_, stdout, _, _| stdout.read }[/[email protected]:(.+).git/,1] end |
#is_git_installed? ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'lib/gitbc.rb', line 25 def is_git_installed? begin Open3.popen3('git --version') return true rescue Errno::ENOENT return false end end |
#is_git_repo? ⇒ Boolean
34 35 36 |
# File 'lib/gitbc.rb', line 34 def is_git_repo? Open3.popen3('git status') { |_, _, stderr, _| stderr.read } !~ /Not a git repository/ end |
#is_github_alive? ⇒ Boolean
62 63 64 65 66 67 68 69 |
# File 'lib/gitbc.rb', line 62 def is_github_alive? begin raise if @github_client..attrs[:status] != 'good' rescue return false end return true end |
#remote_matches?(repo) ⇒ Boolean
54 55 56 |
# File 'lib/gitbc.rb', line 54 def remote_matches?(repo) Open3.popen3('git remote -v') { |_, stdout, _, _| stdout.read } =~ /#{repo}/ end |
#repo_exists?(repo) ⇒ Boolean
50 51 52 |
# File 'lib/gitbc.rb', line 50 def repo_exists?(repo) @github_client.repository?(repo) end |
#revision_exists?(rev) ⇒ Boolean
58 59 60 |
# File 'lib/gitbc.rb', line 58 def revision_exists?(rev) Open3.popen3("git cat-file -t #{rev}") { |_, stdout, _, _| stdout.read } =~ /commit/ end |
#update_options(options) ⇒ Object
71 72 73 |
# File 'lib/gitbc.rb', line 71 def () @params.merge() end |