lib/github_snapshot/repository.rb in github_snapshot-0.1.3 vs lib/github_snapshot/repository.rb in github_snapshot-0.1.4

- old
+ new

@@ -22,34 +22,34 @@ @gh_has_wiki = repo['has_wiki'] @organization = organization end def has_wiki? - Open3.capture3("git ls-remote #{wiki_ssh_url}")[1].empty? && gh_has_wiki + Open3.capture3("git ls-remote #{@wiki_ssh_url}")[1].empty? && @gh_has_wiki end def backup - GithubSnapshot.logger.info "#{canonical_name} - backing up" + 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" + unless @pushed_at + GithubSnapshot.logger.info "#{@canonical_name} is empty" return nil end + Dir.chdir "#{@organization.name}" begin - Dir.chdir "#{organization.name}" clone - clone_wiki if self.has_wiki? + clone_wiki if has_wiki? prune_old_backups - Dir.chdir ".." rescue GithubSnapshot::Error - GithubSnapshot.logger.error "#{canonical_name} - skipping due to error" + GithubSnapshot.logger.error "#{@canonical_name} - skipping due to error" return nil end + Dir.chdir ".." - GithubSnapshot.logger.info "#{canonical_name} - success" + GithubSnapshot.logger.info "#{@canonical_name} - success" end private def clone @@ -57,37 +57,37 @@ # Cloning large repos is a very sensitive operation; here we rely on # Timeout to make sure the script doesn't hang begin Timeout::timeout (GithubSnapshot.git_clone_timeout) { - GithubSnapshot.exec "#{GithubSnapshot.git_clone_cmd} #{ssh_url} #{folder}" + GithubSnapshot.exec "#{GithubSnapshot.git_clone_cmd} #{@ssh_url} #{@folder}" } rescue Timeout::Error, Utilities::ExecError => e message = e.class == Timeout::Error ? 'timedout' : 'exec error' - GithubSnapshot.logger.error "Could not clone #{canonical_name}, #{message}" + GithubSnapshot.logger.error "Could not clone #{@canonical_name}, #{message}" raise GithubSnapshot::Error end - Utilities.tar "#{folder}", GithubSnapshot.logger - GithubSnapshot.exec "rm -rf #{folder}" + Utilities.tar "#{@folder}", GithubSnapshot.logger + GithubSnapshot.exec "rm -rf #{@folder}" end def clone_wiki - GithubSnapshot.logger.info "#{canonical_name} - cloning wiki" - GithubSnapshot.exec "#{GithubSnapshot.git_clone_cmd} #{wiki_ssh_url} #{wiki_folder}" - Utilities.tar "#{wiki_folder}", GithubSnapshot.logger - GithubSnapshot.exec "rm -rf #{wiki_folder}" + GithubSnapshot.logger.info "#{@canonical_name} - cloning wiki" + GithubSnapshot.exec "#{GithubSnapshot.git_clone_cmd} #{@wiki_ssh_url} #{@wiki_folder}" + Utilities.tar "#{@wiki_folder}", GithubSnapshot.logger + GithubSnapshot.exec "rm -rf #{@wiki_folder}" end def prune_old_backups - GithubSnapshot.logger.info "#{canonical_name} - pruning old backups" - file_regex = "#{name}-GST-*" + GithubSnapshot.logger.info "#{@canonical_name} - pruning old backups" + file_regex = "#{@name}-GST-*tar.gz" zipped_bkps = FileList[file_regex].exclude(/wiki/) zipped_bkps.sort[0..-(GithubSnapshot.releases_to_keep + 1)].each do |file| File.delete file end if zipped_bkps.length > GithubSnapshot.releases_to_keep - wiki_regex = "#{name}-GST-*wiki*" + wiki_regex = "#{@name}-GST-*wiki*" zipped_wikis = FileList[wiki_regex] zipped_wikis.sort[0..-(GithubSnapshot.releases_to_keep + 1)].each do |file| File.delete file end if zipped_wikis.length > GithubSnapshot.releases_to_keep end