class Gantree::ReleaseNotes

Attributes

beanstalk[W]
current_sha[R]

Public Class Methods

new(wiki, env_name, packaged_version) click to toggle source
# 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

Public Instance Methods

app_name() click to toggle source
# File lib/gantree/release_notes.rb, line 42
def app_name
  name = environment.application_name
  name.include?("-") ? name.split("-")[0] : name # TODO: business logic
end
beanstalk() click to toggle source
# 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
commits() click to toggle source
# File lib/gantree/release_notes.rb, line 51
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 }.
              reject  {|x| x.empty? }.
              collect {|x| x.gsub(/\n+/, ", ")}
  tickets = []
  commits.each do |msg|
    md = msg.match(/(\w+-\d+)/)
    if md
      ticket_id = md[1]
      tickets << msg unless tickets.detect {|t| t =~ Regexp.new("^#{ticket_id}") }
    else
      tickets << msg
    end
  end
  tickets
end
commits_list() click to toggle source
# File lib/gantree/release_notes.rb, line 73
def commits_list
  commits.collect{|x| "* #{x}" }.join("\n")
end
create() click to toggle source
# File lib/gantree/release_notes.rb, line 93
def create
  filename = "Release-notes-br-#{app_name}.md" # business logic
  Gantree::Wiki.new(notes, filename, @wiki).update
end
environment() click to toggle source
# File lib/gantree/release_notes.rb, line 25
def environment
  beanstalk.describe_environments(:environment_names => [@env_name]).environments.first
end
execute(cmd) click to toggle source
# File lib/gantree/release_notes.rb, line 81
def execute(cmd)
  `#{cmd}`
end
git_log() click to toggle source
# File lib/gantree/release_notes.rb, line 77
def git_log
  execute("git log --no-merges --pretty=format:'%B COMMIT_SEPARATOR' #{previous_sha}..#{current_sha}").strip
end
notes() click to toggle source
# File lib/gantree/release_notes.rb, line 85
    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_time() click to toggle source
# File lib/gantree/release_notes.rb, line 47
def pacific_time
  Time.now.strftime '%Y-%m-%d %a %I:%M%p PDT'
end
previous_sha() click to toggle source
# File lib/gantree/release_notes.rb, line 33
def previous_sha
  if previous_tag
    previous_tag.split("-")[2] 
  else
    # for edge case where release notes have never been generated before, just use 1 commit before the current one
    "#{current_sha}~1"
  end
end
previous_tag() click to toggle source
# File lib/gantree/release_notes.rb, line 29
def previous_tag
  environment.version_label
end