Class: MinaRevisioneer::MessageExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/mina_revisioneer/message_extractor.rb

Direct Known Subclasses

ChangeLog, GroupedChangeLog

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, token, binding) ⇒ MessageExtractor

Returns a new instance of MessageExtractor.



7
8
9
10
11
# File 'lib/mina_revisioneer/message_extractor.rb', line 7

def initialize host, token, binding
  @host = host
  @api_token = token
  @binding = binding
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



6
7
8
# File 'lib/mina_revisioneer/message_extractor.rb', line 6

def api_token
  @api_token
end

#bindingObject (readonly)

Returns the value of attribute binding.



6
7
8
# File 'lib/mina_revisioneer/message_extractor.rb', line 6

def binding
  @binding
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/mina_revisioneer/message_extractor.rb', line 6

def host
  @host
end

Instance Method Details

#last_deployObject



13
14
15
16
17
18
19
20
21
# File 'lib/mina_revisioneer/message_extractor.rb', line 13

def last_deploy
  @last_deploy ||= begin
    curl = %Q{curl "#{host}/deployments?limit=1" -H "API-TOKEN: #{api_token}" -s}
    response = %x[#{curl}].strip
    JSON.parse(response).first || {}
  end
rescue => err
  {} # no JSON received - propably first deploy?
end

#last_deploy_dateObject



30
31
32
# File 'lib/mina_revisioneer/message_extractor.rb', line 30

def last_deploy_date
  Time.parse(last_deploy.fetch("deployed_at"))
end

#last_deploy_shaObject



34
35
36
# File 'lib/mina_revisioneer/message_extractor.rb', line 34

def last_deploy_sha
  last_deploy.fetch("sha", nil)
end

#messagesObject



42
43
44
# File 'lib/mina_revisioneer/message_extractor.rb', line 42

def messages
  [] # implemented in subclass
end

#number_of_new_commitsObject



23
24
25
26
27
28
# File 'lib/mina_revisioneer/message_extractor.rb', line 23

def number_of_new_commits
  walker = Rugged::Walker.new(repo)
  walker.push sha
  walker.hide last_deploy_sha if last_deploy_sha
  walker.each.to_a.count
end

#repoObject



38
39
40
# File 'lib/mina_revisioneer/message_extractor.rb', line 38

def repo
  @repo ||= Rugged::Repository.new(".")
end

#shaObject



46
47
48
49
# File 'lib/mina_revisioneer/message_extractor.rb', line 46

def sha
  ref = repo.head
  ref.target
end