Class: Packman::Github::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/packman/github/repository.rb,
lib/packman/github/repository/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(org, name, github_options: {}) ⇒ Repository

Returns a new instance of Repository.



14
15
16
17
18
# File 'lib/packman/github/repository.rb', line 14

def initialize(org, name, github_options: {})
  @org = org
  @name = name
  @config = Github.config(github_options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/packman/github/repository.rb', line 12

def name
  @name
end

#orgObject (readonly)

Returns the value of attribute org.



12
13
14
# File 'lib/packman/github/repository.rb', line 12

def org
  @org
end

Instance Method Details

#cloned?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/packman/github/repository.rb', line 28

def cloned?
  Dir.exist?(sync_directory) && Git.open(sync_directory)
rescue ArgumentError
  FileUtils.rm_rf(sync_directory)
  false
end

#full_nameObject



20
21
22
# File 'lib/packman/github/repository.rb', line 20

def full_name
  "#{org}/#{name}"
end

#pull_request!Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/packman/github/repository.rb', line 52

def pull_request!
  pr = octokit.create_pull_request(
    full_name,
    'master',
    branch_name,
    "bundle update #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}",
    "Pull requested from [PackmanBot](https://github.com/packmanbot)."
  )
  pr[:html_url]

rescue Octokit::UnprocessableEntity => e
  puts e
end

#push!Object



45
46
47
48
49
50
# File 'lib/packman/github/repository.rb', line 45

def push!
  git = Git.open(sync_directory)
  git.branch(branch_name).checkout
  git.commit_all('update')
  git.push('origin', branch_name)
end

#sync!Object



35
36
37
38
39
40
41
42
43
# File 'lib/packman/github/repository.rb', line 35

def sync!
  if cloned?
    git = Git.open(sync_directory)
    git.checkout('master')
    git.pull
  else
    Git.clone(clone_url, sync_directory)
  end
end

#sync_directoryObject



24
25
26
# File 'lib/packman/github/repository.rb', line 24

def sync_directory
  "#{repos_directory}/#{full_name}"
end