Class: Bimble::GitStrategy::GithubApi

Inherits:
Object
  • Object
show all
Includes:
Helpers::Github, Helpers::Strings, Helpers::Updater
Defined in:
lib/bimble/git_strategy/github_api.rb

Constant Summary

Constants included from Helpers::Github

Helpers::Github::GITHUB_REPO_REGEX

Instance Method Summary collapse

Methods included from Helpers::Updater

#update

Methods included from Helpers::Github

#add_blob_to_tree, #blob_content, #blob_shas, #commit, #create_blob, #create_branch, #default_branch, #github, #latest_commit, #open_pr, #repo, #tree, #user

Methods included from Helpers::Strings

#branch_name, #commit_message, #pull_request_body, #pull_request_title

Constructor Details

#initialize(git_url, oauth_token) ⇒ GithubApi

Returns a new instance of GithubApi.



7
8
9
10
# File 'lib/bimble/git_strategy/github_api.rb', line 7

def initialize(git_url, oauth_token)
  @git_url = git_url
  @oauth_token = oauth_token
end

Instance Method Details

#commit_file(name, content) ⇒ Object



50
51
52
53
54
55
# File 'lib/bimble/git_strategy/github_api.rb', line 50

def commit_file(name, content)    
  blob_sha = create_blob(content)
  tree_sha = add_blob_to_tree(blob_sha, name)
  commit_sha = commit(tree_sha)
  create_branch(branch_name, commit_sha)
end

#commit_to_new_branchObject



46
47
48
# File 'lib/bimble/git_strategy/github_api.rb', line 46

def commit_to_new_branch
  commit_file("Gemfile.lock", File.read("Gemfile.lock"))
end

#get_file(name) ⇒ Object



42
43
44
# File 'lib/bimble/git_strategy/github_api.rb', line 42

def get_file(name)
  get_files(name)[name]
end

#get_files(name) ⇒ Object



29
30
31
32
# File 'lib/bimble/git_strategy/github_api.rb', line 29

def get_files(name)
  blobs = blob_shas(default_branch, name)
  Hash[blobs.map{|x| [x[0], blob_content(x[1])]}]
end

#in_working_copyObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bimble/git_strategy/github_api.rb', line 12

def in_working_copy
  Dir.mktmpdir do |tmpdir|
    # Get files
    files = get_files("Gemfile.*").merge(get_files(".*gemspec"))
    Dir.chdir(tmpdir) do
      # Write files
      files.each_pair do |name, content|
        File.open(name, 'w') {|f| f.write(content) }
      end
      # Store md5 of lockfile
      @original_md5 = Digest::MD5.hexdigest(File.read("Gemfile.lock"))
      # Do the business
      yield
    end
  end
end

#lock_md5Object



34
35
36
# File 'lib/bimble/git_strategy/github_api.rb', line 34

def lock_md5
  Digest::MD5.hexdigest(File.read("Gemfile.lock"))
end

#lockfile_changed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/bimble/git_strategy/github_api.rb', line 38

def lockfile_changed?
  lock_md5 != @original_md5
end