Sha256: be1b87d680a202813eaa1270228bd52e6a31e029db094ee8b87d62c55f5fa958

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'bitbucket_rest_api'

require_relative 'performers/bitbucket_git_repository'
require_relative 'performers/bitbucket_git_wiki'

module BackupRepos
  class BackupBitbucket
    class << self
      def process
        new.process
      end
    end

    def process
      ask_credentials
      process_git_repositories
      process_git_wikis
    end

    private

    def client
      @client ||= ::BitBucket.new(login: @username, password: @password)
    end

    def ask_credentials
      cli = HighLine.new
      @username = cli.ask('BitBucket Username: ')
      @password = cli.ask('BitBucket Password:  ') { |q| q.echo = false }
    end

    def process_git_repositories
      git_repos.each do |repo_params|
        Performers::BitbucketGitRepository.new(repo_params).backup
      end
    end

    def process_git_wikis
      wiki_repos = git_repos.select(&:has_wiki)

      wiki_repos.each do |repo_params|
        Performers::BitbucketGitWiki.new(repo_params).backup
      end
    end

    def git_repos
      repos.select { |repo| repo.scm == 'git' }
    end

    def repos
      @repos ||= client.repos.list
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
backup_repos-0.1.0 lib/backup_repos/backup_bitbucket.rb