Class: Github::RepoX
Instance Method Summary collapse
-
#branch_sha(branch) ⇒ Object
get branch sha.
-
#branches ⇒ Object
get all branches.
-
#create_branch(branch, sha, &block) ⇒ Object
create a new branch.
-
#default_branch ⇒ Object
get default branch.
-
#delete_branch(branch) ⇒ Object
delete a branch.
-
#description ⇒ Object
description.
-
#initialize(token, repo_path) ⇒ RepoX
constructor
A new instance of RepoX.
-
#name ⇒ Object
get name.
-
#set_default_branch(branch) ⇒ Object
set default branch.
Methods included from Logging
Constructor Details
#initialize(token, repo_path) ⇒ RepoX
Returns a new instance of RepoX.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/github/repox.rb', line 10 def initialize(token, repo_path) @client = Octokit::Client.new(access_token: token) begin @repo = @client.repo(repo_path) rescue Octokit::Error => e logger.error "Repo #{repo_path} does not exist." exit 1 end end |
Instance Method Details
#branch_sha(branch) ⇒ Object
get branch sha
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/github/repox.rb', line 55 def branch_sha(branch) begin ref = @client.ref(@repo.full_name, "heads/#{branch}") rescue Octokit::Error => e logger.error "Branch #{branch} does not exist." exit 1 end if ref.key?(:object) return ref.object.sha end logger.error "Branch #{branch} does not exist." exit 1 end |
#branches ⇒ Object
get all branches
50 51 52 |
# File 'lib/github/repox.rb', line 50 def branches @client.branches(@repo.full_name) end |
#create_branch(branch, sha, &block) ⇒ Object
create a new branch
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/github/repox.rb', line 70 def create_branch(branch, sha, &block) begin @client.create_ref(@repo.full_name, "heads/#{branch}", sha) rescue Octokit::Error => e if e..include?("422 - Reference already exists") logger.debug "Branch #{branch} already exists." block.call if block_given? else logger.error "Branch #{branch} already exists." exit 1 end end end |
#default_branch ⇒ Object
get default branch
45 46 47 |
# File 'lib/github/repox.rb', line 45 def default_branch @repo.default_branch end |
#delete_branch(branch) ⇒ Object
delete a branch
85 86 87 |
# File 'lib/github/repox.rb', line 85 def delete_branch(branch) @repo.delete_ref("heads/#{branch}") end |
#description ⇒ Object
description
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/github/repox.rb', line 22 def description puts <<-EOS -------------------------------------- Repo description name: #{@repo.full_name} default_branch: #{default_branch} branches: #{branches.map { |value| value.name }} -------------------------------------- EOS end |
#name ⇒ Object
get name
40 41 42 |
# File 'lib/github/repox.rb', line 40 def name @repo.full_name end |
#set_default_branch(branch) ⇒ Object
set default branch
90 91 92 |
# File 'lib/github/repox.rb', line 90 def set_default_branch(branch) @client.edit_repository(@repo.full_name, default_branch: branch) end |