Class: GithubSnapshot::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/github_snapshot/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#folderObject (readonly)

Returns the value of attribute folder.



11
12
13
# File 'lib/github_snapshot/repository.rb', line 11

def folder
  @folder
end

#gh_has_wikiObject (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

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/github_snapshot/repository.rb', line 11

def name
  @name
end

#organizationObject (readonly)

Returns the value of attribute organization.



11
12
13
# File 'lib/github_snapshot/repository.rb', line 11

def organization
  @organization
end

#pushed_atObject (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_urlObject (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_folderObject (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_urlObject (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

#backupObject



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

Returns:

  • (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