Sha256: af43b990f98038f9d2b50ebf0c574e6ace56f28412bd4c2fda6b2df92c7b11a7

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

class JekyllAuth
  class Commands

    FILES = %w{Rakefile config.ru .gitignore .env}
    VARS  = %w{client_id client_secret team_id org_id}

    def self.source
      @source ||= File.expand_path( "../../templates", File.dirname(__FILE__) )
    end

    def self.destination
      @destination ||= Dir.pwd
    end

    def self.changed?
      execute_command("git", "status", destination, "--porcelain").length != 0
    rescue
      false
    end

    def self.execute_command(*args)
      output, status = Open3.capture2e(*args)
      raise "Command `#{args.join(" ")}` failed: #{output}" if status != 0
      output
    end

    def self.copy_templates
      FILES.each do |file|
        if File.exist? "#{destination}/#{file}"
          puts "* #{destination}/#{file} already exists... skipping."
        else
          puts "* creating #{destination}/#{file}"
          FileUtils.cp "#{source}/#{file}", "#{destination}/#{file}"
        end
      end
    end

    def self.team_id(org, team)
      client = Octokit::Client.new :access_token => ENV["GITHUB_TOKEN"]
      client.auto_paginate = true
      teams = client.organization_teams org
      found = teams.find { |t| t[:slug] == team }
      found[:id] if found
    end

    def self.env_var_set?(var)
      !(ENV[var].to_s.blank?)
    end

    def self.init_repo
      execute_command "git", "init", destination
      FILES.each do |file|
        next if file == ".env"
        execute_command("git", "add", "--", "#{destination}/#{file}")
      end
    end

    def self.initial_commit
      execute_command "git", "commit", "-m", "'[Jekyll Auth] Initial setup'"
    end

    def self.heroku_remote_set?
      remotes = execute_command "git", "remote", "-v"
      !!(remotes =~ /^heroku\s/)
    end

    def self.configure_heroku(options)
      VARS.each do |var|
        execute_command "heroku", "config:set", "GITHUB_#{var.upcase}=#{options[var]}" if options[var]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-auth-1.0.3 lib/jekyll_auth/commands.rb
jekyll-auth-1.0.2 lib/jekyll_auth/commands.rb
jekyll-auth-1.0.1 lib/jekyll_auth/commands.rb
jekyll-auth-1.0.0 lib/jekyll_auth/commands.rb