Class: Gantree::ReleaseNotes

Inherits:
Object
  • Object
show all
Defined in:
lib/gantree/release_notes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wiki, env_name, packaged_version) ⇒ ReleaseNotes

Returns a new instance of ReleaseNotes.



7
8
9
10
11
12
# File 'lib/gantree/release_notes.rb', line 7

def initialize(wiki, env_name, packaged_version)
  @env_name = env_name
  @wiki = wiki
  @org = wiki.split("/")[0..-2].join("/")
  @packaged_version = packaged_version
end

Instance Attribute Details

#beanstalkObject



18
19
20
21
22
23
# File 'lib/gantree/release_notes.rb', line 18

def beanstalk
  return @beanstalk if @beanstalk
  @beanstalk = Aws::ElasticBeanstalk::Client.new(
    :region => ENV['AWS_REGION'] || "us-east-1"
  )
end

#current_shaObject (readonly)

Returns the value of attribute current_sha.



5
6
7
# File 'lib/gantree/release_notes.rb', line 5

def current_sha
  @current_sha
end

Instance Method Details

#app_nameObject



37
38
39
40
# File 'lib/gantree/release_notes.rb', line 37

def app_name
  name = environment.application_name
  name.include?("-") ? name.split("-")[1] : name # TODO: business logic
end

#commitsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gantree/release_notes.rb', line 46

def commits
  return @commits if @commits
  # Get commits for this release
  commits = git_log
  commits = commits.split("COMMIT_SEPARATOR")
  commits = commits.collect { |x| x.strip }
  # only grab the line with the lighthouse info
  # or the first line if no lighthouse info
  commits = commits.collect do |x|
    lines = x.split("\n")
    lines.select { |y| y =~ /\[#\d+/ }.first || lines.first
  end.compact
  # rid of clean up ticket format [#1234 state:xxx]
  commits = commits.map do |x|
    x.gsub(/\[#(\d+)(.*)\]/, '\1')
  end
  @commits = commits.uniq.sort
end

#commits_listObject



65
66
67
# File 'lib/gantree/release_notes.rb', line 65

def commits_list
  commits.collect{|x| "* #{x}" }.join("\n")
end

#createObject



85
86
87
88
# File 'lib/gantree/release_notes.rb', line 85

def create
  filename = "Release-notes-br-#{app_name}.md" # business logic
  Gantree::Wiki.new(notes, filename, @wiki).update
end

#environmentObject



25
26
27
# File 'lib/gantree/release_notes.rb', line 25

def environment
  beanstalk.describe_environments(:environment_names => [@env_name]).environments.first
end

#execute(cmd) ⇒ Object



73
74
75
# File 'lib/gantree/release_notes.rb', line 73

def execute(cmd)
  `#{cmd}`
end

#git_logObject



69
70
71
# File 'lib/gantree/release_notes.rb', line 69

def git_log
  execute("git log --no-merges --pretty=format:'%B COMMIT_SEPARATOR' #{previous_sha}..#{current_sha}").strip
end

#notesObject



77
78
79
80
81
82
83
# File 'lib/gantree/release_notes.rb', line 77

def notes
  compare = "#{previous_sha}...#{current_sha}"
  notes = <<-EOL
#{@env_name} #{pacific_time} [#{compare}](#{@org}/#{app_name}/compare/#{compare}) by #{ENV['USER']} (#{@packaged_version})
#{commits_list}
EOL
end

#pacific_timeObject



42
43
44
# File 'lib/gantree/release_notes.rb', line 42

def pacific_time
  Time.now.strftime '%Y-%m-%d %a %I:%M%p PDT'
end

#previous_shaObject



33
34
35
# File 'lib/gantree/release_notes.rb', line 33

def previous_sha
  previous_tag.split("-")[2]
end

#previous_tagObject



29
30
31
# File 'lib/gantree/release_notes.rb', line 29

def previous_tag
  environment.version_label
end