Module: Bimble::Helpers::Github
- Extended by:
- Memoist
- Included in:
- GitStrategy::Clone, GitStrategy::GithubApi
- Defined in:
- lib/bimble/helpers/github.rb
Constant Summary collapse
- GITHUB_REPO_REGEX =
/github.com[:\/]([^\/]*)\/([^\.]*)/
Instance Method Summary collapse
- #add_blob_to_tree(sha, filename) ⇒ Object
- #blob_content(sha) ⇒ Object
- #blob_shas(branch, path) ⇒ Object
- #commit(sha) ⇒ Object
- #create_blob(content) ⇒ Object
- #create_branch(name, sha) ⇒ Object
- #default_branch ⇒ Object
- #github ⇒ Object
- #latest_commit(branch_name) ⇒ Object
- #open_pr(head, base) ⇒ Object
- #repo ⇒ Object
- #tree(branch) ⇒ Object
- #user ⇒ Object
Instance Method Details
#add_blob_to_tree(sha, filename) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bimble/helpers/github.rb', line 67 def add_blob_to_tree(sha, filename) tree = tree default_branch new_tree = github.git_data.trees.create user, repo, "base_tree" => tree['sha'], "tree" => [ "path" => filename, "mode" => "100644", "type" => "blob", "sha" => sha ] new_tree['sha'] end |
#blob_content(sha) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/bimble/helpers/github.rb', line 51 def blob_content(sha) blob = github.git_data.blobs.get user, repo, sha if blob['encoding'] == 'base64' Base64.decode64(blob['content']) else blob['content'] end end |
#blob_shas(branch, path) ⇒ Object
45 46 47 48 |
# File 'lib/bimble/helpers/github.rb', line 45 def blob_shas(branch, path) tree = tree branch Hash[tree['tree'].select{|x| x['path'] =~ /^#{path}$/ && x['type'] == 'blob'}.map{|x| [x.path, x.sha]}] end |
#commit(sha) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/bimble/helpers/github.rb', line 78 def commit(sha) parent = latest_commit(default_branch) commit = github.git_data.commits.create user, repo, "message" => , "parents" => [parent], "tree" => sha commit['sha'] end |
#create_blob(content) ⇒ Object
62 63 64 65 |
# File 'lib/bimble/helpers/github.rb', line 62 def create_blob(content) blob = github.git_data.blobs.create user, repo, "content" => content, "encoding" => "utf-8" blob['sha'] end |
#create_branch(name, sha) ⇒ Object
86 87 88 89 |
# File 'lib/bimble/helpers/github.rb', line 86 def create_branch(name, sha) branch = github.git_data.references.create user, repo, "ref" => "refs/heads/#{name}", "sha" => sha branch['ref'] end |
#default_branch ⇒ Object
28 29 30 31 |
# File 'lib/bimble/helpers/github.rb', line 28 def default_branch repository = github.repos.get user, repo repository.default_branch end |
#github ⇒ Object
11 12 13 |
# File 'lib/bimble/helpers/github.rb', line 11 def github Github.new oauth_token: @oauth_token end |
#latest_commit(branch_name) ⇒ Object
34 35 36 37 |
# File 'lib/bimble/helpers/github.rb', line 34 def latest_commit(branch_name) branch_data = github.repos.branch user, repo, branch_name branch_data['commit']['sha'] end |
#open_pr(head, base) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/bimble/helpers/github.rb', line 91 def open_pr(head, base) github.pull_requests.create user, repo, "title" => pull_request_title, "body" => pull_request_body, "head" => head, "base" => base end |
#repo ⇒ Object
22 23 24 25 |
# File 'lib/bimble/helpers/github.rb', line 22 def repo match = @git_url.match GITHUB_REPO_REGEX match ? match[2] : nil end |
#tree(branch) ⇒ Object
40 41 42 |
# File 'lib/bimble/helpers/github.rb', line 40 def tree(branch) github.git_data.trees.get user, repo, branch end |
#user ⇒ Object
16 17 18 19 |
# File 'lib/bimble/helpers/github.rb', line 16 def user match = @git_url.match GITHUB_REPO_REGEX match ? match[1] : nil end |