Class: GithubSnapshot::Repository
- Inherits:
-
Object
- Object
- GithubSnapshot::Repository
- Defined in:
- lib/github_snapshot/repository.rb
Instance Attribute Summary collapse
-
#canonical_name ⇒ Object
readonly
Returns the value of attribute canonical_name.
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#gh_has_wiki ⇒ Object
readonly
Returns the value of attribute gh_has_wiki.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#pushed_at ⇒ Object
readonly
Returns the value of attribute pushed_at.
-
#ssh_url ⇒ Object
readonly
Returns the value of attribute ssh_url.
-
#wiki_folder ⇒ Object
readonly
Returns the value of attribute wiki_folder.
-
#wiki_ssh_url ⇒ Object
readonly
Returns the value of attribute wiki_ssh_url.
Instance Method Summary collapse
- #backup ⇒ Object
- #has_wiki? ⇒ Boolean
-
#initialize(repo, organization) ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize(repo, organization) ⇒ Repository
Returns a new instance of Repository.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/github_snapshot/repository.rb', line 14 def initialize(repo, organization) @name = repo['name'] @folder = "#{@name}-GST-#{GithubSnapshot.time_now}.git" @wiki_folder = @folder.gsub('.git', '.wiki.git') @ssh_url = repo['ssh_url'] @wiki_ssh_url = @ssh_url.gsub('.git', '.wiki.git') @canonical_name = "#{organization.name}/#{@name}" @pushed_at = repo['pushed_at'] @gh_has_wiki = repo['has_wiki'] @organization = organization end |
Instance Attribute Details
#canonical_name ⇒ Object (readonly)
Returns the value of attribute canonical_name.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def canonical_name @canonical_name end |
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def folder @folder end |
#gh_has_wiki ⇒ Object (readonly)
Returns the value of attribute gh_has_wiki.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def gh_has_wiki @gh_has_wiki end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def name @name end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def organization @organization end |
#pushed_at ⇒ Object (readonly)
Returns the value of attribute pushed_at.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def pushed_at @pushed_at end |
#ssh_url ⇒ Object (readonly)
Returns the value of attribute ssh_url.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def ssh_url @ssh_url end |
#wiki_folder ⇒ Object (readonly)
Returns the value of attribute wiki_folder.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def wiki_folder @wiki_folder end |
#wiki_ssh_url ⇒ Object (readonly)
Returns the value of attribute wiki_ssh_url.
11 12 13 |
# File 'lib/github_snapshot/repository.rb', line 11 def wiki_ssh_url @wiki_ssh_url end |
Instance Method Details
#backup ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/github_snapshot/repository.rb', line 30 def backup GithubSnapshot.logger.info "#{@canonical_name} - backing up" # Go to next repo if the repository is empty unless @pushed_at GithubSnapshot.logger.info "#{@canonical_name} is empty" return nil end Dir.chdir "#{@organization.name}" begin clone clone_wiki if has_wiki? prune_old_backups rescue GithubSnapshot::Error GithubSnapshot.logger.error "#{@canonical_name} - skipping due to error" return nil end Dir.chdir ".." GithubSnapshot.logger.info "#{@canonical_name} - success" end |
#has_wiki? ⇒ Boolean
26 27 28 |
# File 'lib/github_snapshot/repository.rb', line 26 def has_wiki? Open3.capture3("git ls-remote #{@wiki_ssh_url}")[1].empty? && @gh_has_wiki end |