Module: CIRunner::GitHelper

Extended by:
GitHelper
Included in:
GitHelper
Defined in:
lib/ci_runner/git_helper.rb

Overview

A helper for the ‘ci_runner rerun` command to infer options automatically. The goal being to have the user only type `ci_runner rerun` and have things work magically.

The command line options passed by a user have precedence.

Instance Method Summary collapse

Instance Method Details

#head_commitString

Get the HEAD commit of the repository. This assumes the user runs the ‘ci-runner` command from a repository.

Returns:

  • (String)

    The HEAD commit of the user’s local repository.

Raises:

  • (Error)

    In case the ‘git` subprocess returns an error.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ci_runner/git_helper.rb', line 19

def head_commit
  stdout, _, status = Open3.capture3("git rev-parse HEAD")

  if status.success?
    stdout.rstrip
  else
    raise(Error, <<~EOM)
      Couldn't determine the commit. The commit is required to download the right CI logs.

      Please pass the `--commit` flag (ci_runner --commit <commit>)
    EOM
  end
end

#repository_from_remoteString

Get the full repository name (including the owner, i.e. rails/rails) thanks to the Git remote. This allows the user to not have to type ‘ci-runner rerun –repostitory catanacorp/catana` each time.

Returns:

  • (String)

    The full repository name

Raises:

  • (Error)

    In case the ‘git` subprocess returns an error.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ci_runner/git_helper.rb', line 39

def repository_from_remote
  stdout, _, status = Open3.capture3("git remote -v")

  if status.success?
    process_remotes(stdout)
  else
    raise(Error, <<~EOM)
      Couldn't determine the name of the repository.

      Please pass the `--repository` flag (ci_runner --repository <owner/repository_name>)
    EOM
  end
end