Class: CodeFumesHarvester::SourceControl

Inherits:
Object
  • Object
show all
Defined in:
lib/codefumes_harvester/source_control.rb

Overview

Defines the contract between CodeFumes and any local source control management system (SCM).

NOTE: Git is currently the only supported SCM. We look forward to changing this soon.

Constant Summary collapse

SUPPORTED_SCMS_AND_DETECTORS =

:nodoc:

{:git => '.git'}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SourceControl

Sets up a SourceControl object to read content from the repository located at path.



12
13
14
# File 'lib/codefumes_harvester/source_control.rb', line 12

def initialize(path)
  @repository = Grit::Repo.new(path)
end

Class Method Details

.supported_system?(tool_cli_name) ⇒ Boolean

Accepts command-line executable name of SCM and returns whether it is a supported SCM or not. tool_cli_name should be the name of the executable, not the ‘full name’ of the application (ex: ‘svn’ not ‘subversion’).

Returns true if the SCM is supported

Returns false if the SCM is not supported.

Returns:

  • (Boolean)


48
49
50
# File 'lib/codefumes_harvester/source_control.rb', line 48

def self.supported_system?(tool_cli_name)
  SUPPORTED_SCMS_AND_DETECTORS.keys.include?(tool_cli_name.to_sym)
end

.supported_systemsObject

Returns an array of ‘symbolized’ executable names for all supported SCMs.

The names are returned as symbols.



36
37
38
# File 'lib/codefumes_harvester/source_control.rb', line 36

def self.supported_systems
  SUPPORTED_SCMS_AND_DETECTORS.keys
end

Instance Method Details

#initial_commit_identifierObject

Returns the first commit identifier of a repository’s history.



28
29
30
# File 'lib/codefumes_harvester/source_control.rb', line 28

def initial_commit_identifier
  initial_commit.sha
end

#local_commit_identifier(branch_name = "master") ⇒ Object

Returns the current commit identifier of the underlying repository (‘HEAD’ of the supplied branch in git parlance).

Raises:

  • (ArgumentError)


88
89
90
91
# File 'lib/codefumes_harvester/source_control.rb', line 88

def local_commit_identifier(branch_name = "master")
  raise ArgumentError, "nil branch name supplied" if branch_name.nil?
  @repository.get_head(branch_name).commit.sha
end

#pathObject

Returns the full path of the underlying repository.



94
95
96
# File 'lib/codefumes_harvester/source_control.rb', line 94

def path
  @repository.path
end

#payload_between(from = initial_commit_identifier, to = "HEAD") ⇒ Object Also known as: payload

Returns a serialized Hash containing a single :commits key associated with an Array of serialized commit information, ready to be sent to the CodeFumes service.



19
20
21
22
23
24
# File 'lib/codefumes_harvester/source_control.rb', line 19

def payload_between(from = initial_commit_identifier, to = "HEAD")
  start_commit = from || initial_commit_identifier
  end_commit = to || "HEAD"
  new_commits = commits_between(start_commit, end_commit)
  new_commits.empty? ? {} : {:commits => new_commits}
end

#private_keyObject

Returns the private key of the project assciated with this repository.



82
83
84
# File 'lib/codefumes_harvester/source_control.rb', line 82

def private_key
  CodeFumes::ConfigFile.options_for_project(public_key)[:private_key]
end

#public_keyObject

Returns the public key of the project associated with this repository.



76
77
78
# File 'lib/codefumes_harvester/source_control.rb', line 76

def public_key
  @repository.config["codefumes.public-key"]
end

#store_public_key(public_key) ⇒ Object

Stores the public_key of the project associated with the underlying local repository. This will not be necessary with all SCMs.

For example, in a git repository, this method will store a codefumes key in the .git/config file. This value can be used as a lookup key for other tools to use in conjunction with the CodeFumes config file (see CodeFumes::Config) to interact with a CodeFumes project.



61
62
63
# File 'lib/codefumes_harvester/source_control.rb', line 61

def store_public_key(public_key)
  @repository.config["codefumes.public-key"] = public_key
end

Removes any association to the CodeFumes service which would have been added using the store_public_key method.

This method does not remove anything from the user’s global CodeFumes config file.



70
71
72
# File 'lib/codefumes_harvester/source_control.rb', line 70

def unlink_from_codefumes!
  @repository.git.config({}, "--remove-section", "codefumes")
end