gantree 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gantree/deploy.rb +1 -0
- data/lib/gantree/release_notes.rb +67 -41
- data/lib/gantree/version.rb +1 -1
- data/lib/gantree/wiki.rb +57 -0
- data/spec/lib/gantree/1_release_notes_spec.rb +42 -15
- data/spec/lib/gantree/wiki_spec.rb +49 -0
- data/spec/spec_helper.rb +22 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2d4478af044e2d416b405280f08feef34c35ec6
|
4
|
+
data.tar.gz: 6c221680c7a3dcd83eb81e7d5bdfb1e1da9bb6f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178085f479f97562426be69b98a9362dd063b6a9889ac7f733d25a030bb10b13132e9f5f578158cd3c7a39b87469c5f58ad31c05b3e252ddb3a612fa6d4947c0
|
7
|
+
data.tar.gz: a2dd894648cbe1670c55c74015880790da9040b24a9b5e194045ae03e0907b88ad34cac7cfe5ac1f674ea0486767ad08167c2413944511f0a9200d084eef9772
|
data/lib/gantree/deploy.rb
CHANGED
@@ -1,57 +1,83 @@
|
|
1
1
|
require 'aws-sdk'
|
2
|
+
|
2
3
|
module Gantree
|
3
4
|
class ReleaseNotes
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
17
|
-
|
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
|
23
|
-
|
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
|
31
|
-
|
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
|
36
|
-
|
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
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
54
|
-
|
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
|
data/lib/gantree/version.rb
CHANGED
data/lib/gantree/wiki.rb
ADDED
@@ -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
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
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
|
-
|
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
|
19
|
-
|
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
|
23
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|