Class: Gantree::ReleaseNotes

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

Instance Method Summary collapse

Constructor Details

#initialize(wiki, app, hash) ⇒ ReleaseNotes

Returns a new instance of ReleaseNotes.



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

def initialize wiki, app, hash
  @application = app
  @new_hash = hash
  @wiki_url = wiki
end

Instance Method Details

#commit_release_notesObject



53
54
55
# File 'lib/gantree/release_notes.rb', line 53

def commit_release_notes
  `cd /tmp/wiki_release_notes && git add . && git commit -am "Updated release notes" && git push origin master`
end

#createObject



10
11
12
13
14
# File 'lib/gantree/release_notes.rb', line 10

def create
  get_release_notes
  write_release_notes
  commit_release_notes
end

#get_latest_tagObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gantree/release_notes.rb', line 39

def get_latest_tag
  Aws.config[:credentials]
  beanstalk = Aws::ElasticBeanstalk::Client.new
  resp = beanstalk.describe_application_versions(
    application_name: @application,
  )
  label = resp["application_versions"].select {|version| version["version_label"].include?("br-master") }.first
  if label
    label["version_label"].split("-")[0..2].join('-')
  else
    raise "No Master Tags Deployed:\n #{resp["application_versions"].inspect}"
    500
  end
end

#get_release_notesObject



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

def get_release_notes
  rl_dir = "/tmp/wiki_release_notes"
  FileUtils.rm_rf(rl_dir) if File.directory? rl_dir
  `git clone #{@wiki_url} /tmp/wiki_release_notes/` 
end

#last_deployed_hashObject



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

def last_deployed_hash
  get_latest_tag.split("-").last
end

#release_notesObject



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

def release_notes
  time = Time.now.strftime("%a, %e %b %Y %H:%M:%S %z")
  "#{time} [#{last_deployed_hash}...#{@new_hash}](https://github.com/br/#{@application}/compare/#{last_deployed_hash}...#{@new_hash})"
end

#write_release_notesObject



22
23
24
25
26
27
28
# File 'lib/gantree/release_notes.rb', line 22

def write_release_notes
  wiki_dir = "/tmp/wiki_release_notes/"
  release_notes_file = "Release-notes-br-#{@application}.md"
  path_to_wiki_file = "#{wiki_dir}#{release_notes_file}"
  `touch #{path_to_wiki_file}` unless File.exist? "#{path_to_wiki_file}"
  `printf "#{release_notes}\n\n" | cat - #{path_to_wiki_file} > #{path_to_wiki_file}.tmp  && mv #{path_to_wiki_file}.tmp #{path_to_wiki_file}`
end