Class: Waddup::Source::Git
- Inherits:
-
Waddup::Source
- Object
- Waddup::Source
- Waddup::Source::Git
- Extended by:
- Extension::System
- Includes:
- Extension::System
- Defined in:
- lib/waddup/sources/git.rb
Constant Summary collapse
- ALIAS =
'git'
- ICON =
"\xE2\x9C\x8F\xEF\xB8\x8F "
- GIT_FORMAT =
'%h %ai %s'
- EXTRACT_PATTERN =
Pattern to extract from the above format
/([0-9a-f]{7}) ([-0-9: ]+\+\d{4}) (.+)/i
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
Class Method Summary collapse
-
.label_for_repo(repo) ⇒ Object
Generates label for given repo path.
-
.usable? ⇒ Boolean
Requires Git to be installed successfully.
Instance Method Summary collapse
-
#author ⇒ Object
Obtains author from git-config.
-
#events(from, to) ⇒ Object
Aggregates events from all repositories.
-
#events_for_repo(from, to, repo) ⇒ Object
Aggregates events for given repository.
-
#initialize(base_path = Dir.pwd) ⇒ Git
constructor
Retrieves author and repositories on initialization.
-
#repos ⇒ Object
Collects repositories under base-path.
Methods included from Extension::System
Methods inherited from Waddup::Source
Methods included from Registry
Constructor Details
#initialize(base_path = Dir.pwd) ⇒ Git
Retrieves author and repositories on initialization
Arguments
:base_path (defaults to current working directory)
20 21 22 |
# File 'lib/waddup/sources/git.rb', line 20 def initialize(base_path = Dir.pwd) @base_path = base_path end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
12 13 14 |
# File 'lib/waddup/sources/git.rb', line 12 def base_path @base_path end |
Class Method Details
.label_for_repo(repo) ⇒ Object
Generates label for given repo path
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/waddup/sources/git.rb', line 76 def self.label_for_repo(repo) path = Pathname.new(repo) parent = path.parent case parent.basename.to_s when 'code', 'design' parent = parent.parent end return nil if parent.root? parent.basename.to_s end |
.usable? ⇒ Boolean
Requires Git to be installed successfully
91 92 93 94 |
# File 'lib/waddup/sources/git.rb', line 91 def self.usable? run 'git --version', quietly: true $?.success? end |
Instance Method Details
#author ⇒ Object
Obtains author from git-config
25 26 27 |
# File 'lib/waddup/sources/git.rb', line 25 def @author ||= run 'git config --get user.name' end |
#events(from, to) ⇒ Object
Aggregates events from all repositories
Arguments:
:from (datetime)
:to (datetime)
41 42 43 44 45 46 |
# File 'lib/waddup/sources/git.rb', line 41 def events(from, to) events = repos.map do |repo| events_for_repo from, to, repo end events.flatten! end |
#events_for_repo(from, to, repo) ⇒ Object
Aggregates events for given repository
Arguments:
:from (datetime)
:to (datetime)
:repo (path)
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/waddup/sources/git.rb', line 62 def events_for_repo(from, to, repo) repo_label = self.class.label_for_repo repo results = run "git --git-dir='#{repo}' log --all --no-merges --author='#{}' --since='#{from.iso8601}' --until='#{to.iso8601}' --format='format:#{GIT_FORMAT}'" results.scan(EXTRACT_PATTERN).map do |hash, datetime, subject| Waddup::Event.new do |e| e.label = "[#{repo_label}] #{subject}" e.at = Time.parse(datetime) e.source = self end end end |
#repos ⇒ Object
Collects repositories under base-path
30 31 32 |
# File 'lib/waddup/sources/git.rb', line 30 def repos @repos ||= Dir["#{base_path}/**/.git"] end |