Sha256: 9e4884574700b1ee9db0b6b9f50dab4f5a7cbe82f729e83a2c3390cc1d9e2eeb

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Jive
  class Git
    attr_reader :shell

    def initialize(shell = ::Jive.shell)
      @shell = shell
    end

    def clone(slug, host: "github.com")
      dir = target_dir_for(slug, host: host)
      unless dir.exist?
        shell.run_each([
          [:mkdir, "-p", dir.parent.to_s],
          [:git, "clone", "git@#{host}:#{slug}", dir]
        ])
      end
      cd(slug, host: host)
    end

    def cd(slug, host: "github.com")
      dir = target_dir_for(slug, host: host)
      if dir.exist?
        shell.after_run([
          ["cd", dir],
          ["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
        ])
      else
        clone(slug)
      end
    end

    def semantic_help
      <<~MESSAGE
        Format: <type>(<scope>): <subject>

        <scope> is optional

        feat: add hat wobble
        ^--^  ^------------^
        |     |
        |     +-> Summary in present tense.
        |
        +-------> Type: chore, docs, feat, fix, refactor, style, or test.

        chore: updating grunt tasks etc; no production code change
        docs: changes to the documentation
        feat: new feature for the user, not a new feature for build script
        fix: bug fix for the user, not a fix to a build script
        refactor: refactoring production code, eg. renaming a variable
        style: formatting, missing semi colons, etc; no production code change
        test: adding missing tests, refactoring tests; no production code change
      MESSAGE
    end

    private

    def target_dir_for(slug, host:)
      Pathname.new(Dir.home).join("src/#{host}/#{slug}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jive-0.3.2 lib/jive/git.rb