Class: JenkinsTracker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins_tracker/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.

Raises:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jenkins_tracker/base.rb', line 7

def initialize(options = {})
  raise FileNotFoundError, "Changelog file not found at: #{options[:changelog_file]}" unless File.file?(options[:changelog_file])

  @changelog = File.read(options[:changelog_file])

  @tracker_client = TrackerClient.new(:token => options[:tracker_token])
  @tracker_client.use_ssl = true

  @job_name = options[:job_name]
  @build_url = options[:build_url]
end

Instance Attribute Details

#build_urlObject (readonly)

include Util



5
6
7
# File 'lib/jenkins_tracker/base.rb', line 5

def build_url
  @build_url
end

#changelogObject (readonly)

include Util



5
6
7
# File 'lib/jenkins_tracker/base.rb', line 5

def changelog
  @changelog
end

#job_nameObject (readonly)

include Util



5
6
7
# File 'lib/jenkins_tracker/base.rb', line 5

def job_name
  @job_name
end

#tracker_clientObject (readonly)

include Util



5
6
7
# File 'lib/jenkins_tracker/base.rb', line 5

def tracker_client
  @tracker_client
end

Instance Method Details

#integrate_job_with_tracker(project_id) ⇒ Object



19
20
21
22
23
24
# File 'lib/jenkins_tracker/base.rb', line 19

def integrate_job_with_tracker(project_id)
  parse_changelog.each do |change|
    note = "*#{change.commit_message}* integrated in *#{job_name}* (#{build_url})"
    tracker_client.add_note_to_story(project_id, change.story_id, note)
  end
end

#parse_changelogObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jenkins_tracker/base.rb', line 26

def parse_changelog
  results = []

  changelog.scan(/(\[[#a-zA-Z0-9\s]+\])(.*)/) do |ids, msg|
    parse_tracker_story_ids(ids).each do |id|
      results << ChangelogItem.new(:story_id => id, :commit_message => "#{ids}#{msg}".strip)
    end
  end

  results.uniq
end