Module: GHFS::Util

Defined in:
lib/github-fs/util.rb

Class Method Summary collapse

Class Method Details

.create_branch(name, repo = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/github-fs/util.rb', line 22

def self.create_branch(name, repo=nil)
  if repo ||= GHFS.config.repository
    master_branch = GHFS.api.branch(repo, "master")
    master_sha = master_branch.commit.sha
    refs = GHFS.api.create_ref(repo, "heads/#{ name }", master_sha)

    ref = Array(refs).flatten.last
    ref && ref.commit && ref.commit.sha
  end
end

.remove_branch(name, repo = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/github-fs/util.rb', line 33

def self.remove_branch(name, repo=nil)
  if repo ||= GHFS.config.repository
    names = GHFS.api.branches(repo).map(&:name)

    if names.any? {|n| n == name }
      GHFS.api.delete_branch(repo, name)
    end
  end
end

.remove_temporary_branchObject



8
9
10
11
12
# File 'lib/github-fs/util.rb', line 8

def self.remove_temporary_branch
  if temporary_branch_exists?
    remove_branch(temporary_branch)
  end
end

.temporary_branchObject



18
19
20
# File 'lib/github-fs/util.rb', line 18

def self.temporary_branch
  @temporary_branch ||= "temp-branch-#{ rand(36**36).to_s(36).slice(0,8) }"
end

.temporary_branch_exists?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/github-fs/util.rb', line 14

def self.temporary_branch_exists?
  !@temporary_branch.nil?
end

.use_temporary_branchObject



3
4
5
6
# File 'lib/github-fs/util.rb', line 3

def self.use_temporary_branch
  GHFS.config.branch = temporary_branch
  create_branch(temporary_branch)
end