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("-")[0] : name # TODO: business logic
end

#commitsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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 }.
              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_listObject



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

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

#createObject



88
89
90
91
# File 'lib/gantree/release_notes.rb', line 88

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



76
77
78
# File 'lib/gantree/release_notes.rb', line 76

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

#git_logObject



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

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

#notesObject



80
81
82
83
84
85
86
# File 'lib/gantree/release_notes.rb', line 80

def notes
  compare = "#{previous_sha}...#{current_sha}"
  notes = "\#{@env_name} \#{pacific_time} [\#{compare}](\#{@org}/\#{app_name}/compare/\#{compare}) by \#{ENV['USER']} (\#{@packaged_version})\n\#{commits_list}\n"
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