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, current_sha) ⇒ 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, current_sha
  @env_name = env_name
  @wiki = wiki
  @org = wiki.split("/")[0..-2].join("/")
  @current_sha = current_sha
end

Instance Attribute Details

#beanstalkObject



14
15
16
17
18
19
# File 'lib/gantree/release_notes.rb', line 14

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



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

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

#commitsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gantree/release_notes.rb', line 42

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

#createObject



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

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

#environmentObject



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

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

#execute(cmd) ⇒ Object



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

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

#git_logObject



61
62
63
# File 'lib/gantree/release_notes.rb', line 61

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

#notesObject



69
70
71
72
73
74
75
76
# File 'lib/gantree/release_notes.rb', line 69

def notes
  compare = "#{previous_sha}...#{current_sha}"
  notes = "\"\#{@env_name} \#{now} [compare](\#{@org}/\#{app_name}/compare/\#{compare})\"\n\n\#{commits.collect{|x| \"* \#{x}\" }.join(\"\\n\")}\n"
end

#nowObject



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

def now
  @now ||= Time.now.strftime("%a, %e %b %Y %H:%M:%S %z")
end

#previous_shaObject



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

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

#previous_tagObject



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

def previous_tag
  environment.version_label
end