gantree 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 233bce4a14384b2aeb458764e5bfc12603408a0a
4
- data.tar.gz: 7756f02e36be10f640e20ff4d55ee0ed71f3c361
3
+ metadata.gz: c2d4478af044e2d416b405280f08feef34c35ec6
4
+ data.tar.gz: 6c221680c7a3dcd83eb81e7d5bdfb1e1da9bb6f1
5
5
  SHA512:
6
- metadata.gz: 0db36ca1285a02a01503638683ac1bbbba23e0a4bcb30cc2c2c52a2ee7b9b4383286d8c7faa73696cfb82ef5399cf3aac09187c87d2df3c26392758acfc66fbd
7
- data.tar.gz: f73955012750e53346395b7a7a051a4f46a0a44998074d4a99f1910fa82f2ade99384a98e475b03ed4aa0833d4b02c59544f98a5523d486f3c671ac3ab6bd1a0
6
+ metadata.gz: 178085f479f97562426be69b98a9362dd063b6a9889ac7f733d25a030bb10b13132e9f5f578158cd3c7a39b87469c5f58ad31c05b3e252ddb3a612fa6d4947c0
7
+ data.tar.gz: a2dd894648cbe1670c55c74015880790da9040b24a9b5e194045ae03e0907b88ad34cac7cfe5ac1f674ea0486767ad08167c2413944511f0a9200d084eef9772
@@ -3,6 +3,7 @@ require 'archive/zip'
3
3
  require 'colorize'
4
4
  require 'librato/metrics'
5
5
  require_relative 'release_notes'
6
+ require_relative 'wiki'
6
7
  require_relative 'notification'
7
8
 
8
9
  module Gantree
@@ -1,57 +1,83 @@
1
1
  require 'aws-sdk'
2
+
2
3
  module Gantree
3
4
  class ReleaseNotes
4
- def initialize wiki, app, hash
5
- @application = app
6
- @new_hash = hash
7
- @wiki_url = wiki
8
- end
5
+ attr_reader :current_sha
6
+ attr_writer :beanstalk
7
+ def initialize wiki, env_name, current_sha
8
+ @env_name = env_name
9
+ @wiki = wiki
10
+ @org = wiki.split("/")[0..-2].join("/")
11
+ @current_sha = current_sha
12
+ end
9
13
 
10
- def create
11
- get_release_notes
12
- write_release_notes
13
- commit_release_notes
14
+ def beanstalk
15
+ return @beanstalk if @beanstalk
16
+ @beanstalk = Aws::ElasticBeanstalk::Client.new(
17
+ :region => ENV['AWS_REGION'] || "us-east-1"
18
+ )
14
19
  end
15
-
16
- def get_release_notes
17
- rl_dir = "/tmp/wiki_release_notes"
18
- FileUtils.rm_rf(rl_dir) if File.directory? rl_dir
19
- `git clone #{@wiki_url} /tmp/wiki_release_notes/`
20
+
21
+ def environment
22
+ beanstalk.describe_environments(:environment_names => [@env_name]).environments.first
20
23
  end
21
-
22
- def write_release_notes
23
- wiki_dir = "/tmp/wiki_release_notes/"
24
- release_notes_file = "Release-notes-br-#{@application}.md"
25
- path_to_wiki_file = "#{wiki_dir}#{release_notes_file}"
26
- `touch #{path_to_wiki_file}` unless File.exist? "#{path_to_wiki_file}"
27
- `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}`
24
+
25
+ def previous_tag
26
+ environment.version_label
28
27
  end
29
28
 
30
- def release_notes
31
- time = Time.now.strftime("%a, %e %b %Y %H:%M:%S %z")
32
- "#{time} [#{last_deployed_hash}...#{@new_hash}](https://github.com/br/#{@application}/compare/#{last_deployed_hash}...#{@new_hash})"
29
+ def previous_sha
30
+ previous_tag.split("-")[2]
33
31
  end
34
32
 
35
- def last_deployed_hash
36
- get_latest_tag.split("-").last
33
+ def app_name
34
+ name = environment.application_name
35
+ name.include?("-") ? name.split("-")[1] : name # TODO: business logic
37
36
  end
38
37
 
39
- def get_latest_tag
40
- Aws.config[:credentials]
41
- beanstalk = Aws::ElasticBeanstalk::Client.new
42
- resp = beanstalk.describe_application_versions(
43
- application_name: @application,
44
- )
45
- label = resp["application_versions"].select {|version| version["version_label"].include?("br-master") }.first
46
- if label
47
- label["version_label"].split("-")[0..2].join('-')
48
- else
49
- raise "No Master Tags Deployed:\n #{resp["application_versions"].inspect}"
50
- 500
38
+ def now
39
+ @now ||= Time.now.strftime("%a, %e %b %Y %H:%M:%S %z")
40
+ end
41
+
42
+ def commits
43
+ return @commits if @commits
44
+ # Get commits for this release
45
+ commits = git_log
46
+ commits = commits.split("COMMIT_SEPARATOR")
47
+ commits = commits.collect { |x| x.strip }
48
+ # only grab the line with the lighthouse info
49
+ # or the first line if no lighthouse info
50
+ commits = commits.collect do |x|
51
+ lines = x.split("\n")
52
+ lines.select { |y| y =~ /\[#\d+/ }.first || lines.first
53
+ end.compact
54
+ # rid of clean up ticket format [#1234 state:xxx]
55
+ commits = commits.map do |x|
56
+ x.gsub(/\[#(\d+)(.*)\]/, '\1')
51
57
  end
58
+ @commits = commits.uniq.sort
52
59
  end
53
- def commit_release_notes
54
- `cd /tmp/wiki_release_notes && git add . && git commit -am "Updated release notes" && git push origin master`
60
+
61
+ def git_log
62
+ execute("git log --no-merges --pretty=format:'%B COMMIT_SEPARATOR' #{@left}..#{@right}").strip
63
+ end
64
+
65
+ def execute(cmd)
66
+ `#{cmd}`
67
+ end
68
+
69
+ def notes
70
+ compare = "#{previous_sha}...#{current_sha}"
71
+ notes = <<-EOL
72
+ "#{@env_name} #{now} [compare](#{@org}/#{app_name}/compare/#{compare})"
73
+
74
+ #{commits.collect{|x| "* #{x}" }.join("\n")}
75
+ EOL
76
+ end
77
+
78
+ def create
79
+ filename = "Release-notes-br-#{app_name}.md" # business logic
80
+ Gantree::Wiki.new(notes, filename, @wiki).update
55
81
  end
56
82
  end
57
- end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module Gantree
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -0,0 +1,57 @@
1
+ module Gantree
2
+ class Wiki
3
+ attr_reader :wiki_path
4
+ attr_accessor :file_path
5
+ def initialize(notes, filename, wiki_url, path='/tmp/')
6
+ @notes = notes
7
+ @wiki_url = wiki_url
8
+ wiki_path = wiki_url.split("/").last.sub(".git","")
9
+ @wiki_path = "#{path}#{wiki_path}"
10
+ @file_path = "#{@wiki_path}/#{filename}"
11
+ end
12
+
13
+ def update
14
+ pull
15
+ added = add_to_top
16
+ push if added
17
+ end
18
+
19
+ def pull
20
+ puts "Updating wiki cached repo".colorize(:yellow)
21
+ if File.exist?(@wiki_path)
22
+ Dir.chdir(@wiki_path) do
23
+ execute("git checkout master") unless execute("git branch").include?("* master")
24
+ execute("git pull origin master")
25
+ end
26
+ else
27
+ dirname = File.dirname(@wiki_path)
28
+ FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
29
+ cmd = "cd #{dirname} && git clone #{@wiki_url}"
30
+ execute(cmd)
31
+ end
32
+ end
33
+
34
+ def add_to_top
35
+ data = IO.read(@file_path) if File.exist?(@file_path)
36
+ File.open(@file_path, "w") do |file|
37
+ file.write(@notes)
38
+ file.write("\n\n")
39
+ file.write(data) if data
40
+ end
41
+ true
42
+ end
43
+
44
+ def push
45
+ Dir.chdir(@wiki_path) do
46
+ basename = File.basename(@file_path)
47
+ execute("git add #{basename}")
48
+ execute(%Q|git commit -m "Update release notes"|)
49
+ execute("git push origin master")
50
+ end
51
+ end
52
+
53
+ def execute(cmd)
54
+ `#{cmd}`
55
+ end
56
+ end
57
+ end
@@ -1,25 +1,52 @@
1
-
2
1
  require "spec_helper"
3
- require "pry"
4
2
 
5
3
  describe Gantree::ReleaseNotes do
6
4
  before(:all) do
7
- @app = "cms"
8
- @hash = "9ef330b"
9
- @wiki = "git@github.com:br/dev.wiki.git"
10
- @release_notes = Gantree::ReleaseNotes.new(@wiki,@app,@hash)
11
- @release_notes.instance_variable_set("@beanstalk", Aws::ElasticBeanstalk::Client.new(stub_responses: true))
5
+ @wiki = "https://github.com/br/dev.wiki.git"
6
+ @env_name = "stag-rails-app-s1"
7
+ @current_sha = "d961c96"
8
+ @rn = Gantree::ReleaseNotes.new(@wiki, @env_name, @current_sha)
9
+ @rn.beanstalk = Aws::ElasticBeanstalk::Client.new(stub_responses: true)
10
+ end
11
+
12
+ def mock_environment
13
+ double(
14
+ version_label: "br-master-fb3e1cd-23.zip",
15
+ application_name: "rails"
16
+ )
12
17
  end
13
18
 
14
19
  it "can retrieve the latest deployed master tag" do
15
- expect(@release_notes.send(:get_latest_tag)).to include "br-master"
20
+ allow(@rn).to receive(:environment).and_return(mock_environment)
21
+ expect(@rn.previous_tag).to include "br-master"
16
22
  end
17
-
18
- it "can get the last deployed hash" do
19
- expect(@release_notes.send(:last_deployed_hash).length).to eq 7
23
+
24
+ it "can retrieve the latest deployed sha from the master tag" do
25
+ allow(@rn).to receive(:environment).and_return(mock_environment)
26
+ expect(@rn.previous_sha).to eq "fb3e1cd"
20
27
  end
21
-
22
- it "can show release notes" do
23
- expect(@release_notes.send(:release_notes)).to include "github.com/br/#{@app}/compare/#{@release_notes.send(:last_deployed_hash)}..."
28
+
29
+ it "can retrieve the current sha" do
30
+ expect(@rn.current_sha).to eq @current_sha
31
+ end
32
+
33
+ it "should generate notes" do
34
+ allow(@rn).to receive(:environment).and_return(mock_environment)
35
+ allow(@rn).to receive(:git_log).and_return(git_log_mock)
36
+ notes = @rn.notes
37
+ puts notes if ENV['DEBUG']
38
+ expect(notes).to include(@env_name)
39
+ expect(notes).to include(@rn.now)
40
+ expect(notes).to include("compare")
41
+ expect(notes).to include("test up controller")
42
+ end
43
+
44
+ it "should grab commit messages" do
45
+ allow(@rn).to receive(:git_log).and_return(git_log_mock)
46
+ commits = @rn.commits
47
+ p commits if ENV['DEBUG']
48
+ expect(commits).to be_a(Array)
49
+ expect(commits).to include("commit 1")
50
+ expect(commits).to include("commit 2")
24
51
  end
25
- end
52
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe Gantree::Wiki do
4
+ before(:all) do
5
+ @notes = "fake_release_notes"
6
+ filename = "Release-notes-br-rails.md"
7
+ wiki = "git@github.com:br/dev.wiki.git"
8
+ @wiki = Gantree::Wiki.new(@notes, filename, wiki, "tmp/")
9
+ end
10
+
11
+ def fake_clone_dir
12
+ FileUtils.mkdir_p(@wiki.wiki_path)
13
+ end
14
+
15
+ it "should clone and pull" do
16
+ FileUtils.rm_rf(@wiki.wiki_path) if ENV['CLEAN']
17
+ allow(@wiki).to receive(:execute).and_return(fake_clone_dir)
18
+ @wiki.pull
19
+ folder_created = File.exist?(@wiki.wiki_path)
20
+ # puts "@wiki.wiki_path #{@wiki.wiki_path.inspect}"
21
+ expect(folder_created).to be true
22
+ @wiki.pull
23
+ end
24
+
25
+ it "should add notes to the top" do
26
+ FileUtils.mkdir("tmp") unless File.exist?("tmp")
27
+ @wiki.file_path = "tmp/Release-notes-br-rails.md"
28
+ FileUtils.rm_f(@wiki.file_path)
29
+ @wiki.add_to_top
30
+ notes = IO.read(@wiki.file_path)
31
+ expect(notes).to eq "#{@notes}\n\n"
32
+
33
+ @wiki.add_to_top
34
+ notes = IO.read(@wiki.file_path)
35
+ expect(notes).to eq "#{@notes}\n\n#{@notes}\n\n"
36
+ end
37
+
38
+ it "should push" do
39
+ allow(@wiki).to receive(:execute).and_return(fake_clone_dir)
40
+ @wiki.push
41
+ end
42
+
43
+ it "should update" do
44
+ allow(@wiki).to receive(:pull)
45
+ allow(@wiki).to receive(:add_to_top).and_return(true)
46
+ allow(@wiki).to receive(:push)
47
+ @wiki.update
48
+ end
49
+ end
@@ -20,10 +20,31 @@ module Helpers
20
20
  def execute(cmd)
21
21
  puts "Running: #{cmd}" if ENV['DEBUG']
22
22
  out = `#{cmd}`
23
- raise "Stack Trance Found: \n #{out}" if out.include? "Error"
23
+ raise "Stack Trace Found: \n #{out}" if out.include? "Error"
24
24
  puts out if ENV['DEBUG']
25
25
  out
26
26
  end
27
+
28
+ def git_log_mock
29
+ <<-EOL
30
+ commit 1
31
+ COMMIT_SEPARATOR
32
+ commit 2
33
+ COMMIT_SEPARATOR
34
+ test up controller
35
+ COMMIT_SEPARATOR
36
+ commit 4
37
+ COMMIT_SEPARATOR
38
+ add to test
39
+ note with newlie
40
+ COMMIT_SEPARATOR
41
+ fix bug
42
+ COMMIT_SEPARATOR
43
+ whatever
44
+ COMMIT_SEPARATOR
45
+ EOL
46
+ end
47
+
27
48
  end
28
49
 
29
50
  RSpec.configure do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gantree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -315,6 +315,7 @@ files:
315
315
  - lib/gantree/release_notes.rb
316
316
  - lib/gantree/update.rb
317
317
  - lib/gantree/version.rb
318
+ - lib/gantree/wiki.rb
318
319
  - spec/fixtures/project/Dockerrun.aws.json
319
320
  - spec/lib/gantree/1_release_notes_spec.rb
320
321
  - spec/lib/gantree/cli_spec.rb
@@ -322,6 +323,7 @@ files:
322
323
  - spec/lib/gantree/deploy_version_spec.rb
323
324
  - spec/lib/gantree/docker_spec.rb
324
325
  - spec/lib/gantree/init_spec.rb
326
+ - spec/lib/gantree/wiki_spec.rb
325
327
  - spec/spec_helper.rb
326
328
  homepage: https://github.com/feelobot/gantree
327
329
  licenses:
@@ -358,4 +360,5 @@ test_files:
358
360
  - spec/lib/gantree/deploy_version_spec.rb
359
361
  - spec/lib/gantree/docker_spec.rb
360
362
  - spec/lib/gantree/init_spec.rb
363
+ - spec/lib/gantree/wiki_spec.rb
361
364
  - spec/spec_helper.rb