capistrano-fiesta 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83eb008c0ff57b874de422572d34b5fc038d520f
4
- data.tar.gz: c0246dab3ff8c418901878ddcfd288b53bfae27f
3
+ metadata.gz: 8569d071a7d622c8c77e09c37a2004c1b2dda7f3
4
+ data.tar.gz: fc09af141ae0face70f402820bfde64239922b86
5
5
  SHA512:
6
- metadata.gz: 0fed3a91cd8b169f48e81f618bfbd93c51b784c7010514b36c6d516630a8325d387266bf3b752e77edf3c7c77a6eb99a46f0b3ce901f5d9dfd4b2878605a76d0
7
- data.tar.gz: 4f63d07a21119757ad1d599ae641c75ae4998afe5a4c7c403737b20d7f1dacc220f4b02142041c195b97ec0323bc29ee5611f560335bcdd46b3f44f3c189763a
6
+ metadata.gz: ea945561cd5903e6873f09f674c791655ede9a14ec5605d93aee0076639c95806962b5c10e9bffef6d3cf15198364af5b7b652d2b306f0de36961b0bde7082cf
7
+ data.tar.gz: 1b1a5981d4a29bb94adf3825e6d1a68c26f03fbcc3ad3264496f1b656b8298d5439f9c1646da7671b45c99f9dc1a79ec4d13c194468787181c197c2f175f4381
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
- language: ruby
1
+ notifications:
2
+ email: false
2
3
  rvm:
3
- - 2.1.5
4
- before_install: gem install bundler -v 1.10.6
4
+ - 2.2.2
5
+ sudo: false
@@ -0,0 +1,23 @@
1
+ require "erb"
2
+
3
+ module Capistrano
4
+ module Fiesta
5
+ class Draft
6
+ attr_reader :comment, :stories
7
+
8
+ def initialize(comment:, stories: [])
9
+ @comment, @stories = comment, stories
10
+ end
11
+
12
+ def render
13
+ ERB.new(File.read(template), nil, '-').result(binding)
14
+ end
15
+
16
+ private
17
+
18
+ def template
19
+ File.join(File.expand_path('../../templates', __FILE__), 'draft.erb')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -7,9 +7,9 @@ module Capistrano
7
7
  @content = content
8
8
  end
9
9
 
10
- def open
10
+ def edit
11
11
  create_temp_file
12
- edit
12
+ open
13
13
  read
14
14
  end
15
15
 
@@ -20,8 +20,8 @@ module Capistrano
20
20
  file.close
21
21
  end
22
22
 
23
- def edit
24
- Kernel.system(ENV["EDITOR"] || "vi", file.path)
23
+ def open
24
+ system(ENV["EDITOR"] || "vi", file.path)
25
25
  end
26
26
 
27
27
  def read
@@ -0,0 +1,29 @@
1
+ require "octokit"
2
+ require "yaml"
3
+
4
+ module Capistrano
5
+ module Fiesta
6
+ class Github
7
+ def client
8
+ Octokit::Client.new(config)
9
+ end
10
+
11
+ private
12
+
13
+ def config
14
+ { access_token: hub_config["oauth_token"] }
15
+ end
16
+
17
+ def hub_config_path
18
+ Dir.home + "/.config/hub"
19
+ end
20
+
21
+ def hub_config
22
+ YAML.load_file(hub_config_path)["github.com"].first
23
+ rescue Errno::ENOENT
24
+ Logger.warn "No github config found at #{hub_config_path}, using ENV defaults (https://github.com/octokit/octokit.rb/blob/master/lib/octokit/default.rb)"
25
+ {}
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Capistrano
2
+ module Fiesta
3
+ class Logger
4
+ @logs = []
5
+
6
+ def self.warn(message)
7
+ @logs << "[FIESTA] #{message}"
8
+ end
9
+
10
+ def self.logs
11
+ @logs
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,47 +1,70 @@
1
1
  Encoding.default_internal = Encoding.default_external = 'utf-8'
2
2
 
3
- require "capistrano/fiesta/story"
3
+ require "capistrano/fiesta/github"
4
+ require "capistrano/fiesta/draft"
4
5
  require "capistrano/fiesta/editor"
5
- require "erb"
6
- require "octokit"
7
- require "yaml"
6
+ require "capistrano/fiesta/logger"
7
+ require "capistrano/fiesta/story"
8
8
 
9
9
  module Capistrano
10
10
  module Fiesta
11
11
  class Report
12
- attr_accessor :logs, :comment
12
+ class << self
13
+ attr_accessor :chat_client
14
+ end
15
+
16
+ attr_reader :announcement
17
+
18
+ def self.create(*args)
19
+ report = new(*args)
20
+ report.save
21
+ report
22
+ end
13
23
 
14
24
  def initialize(github_url, last_release: nil, comment: nil)
15
25
  @github_url, @last_release, @comment = github_url, last_release, comment
16
- @logs = []
17
26
  end
18
27
 
19
- def write
20
- editor.open if stories.any?
28
+ def save
29
+ @announcement = editor.edit if stories.any?
21
30
  end
22
31
 
23
32
  def stories
24
33
  @stories ||= merged_pull_requests.map { |pr| Story.new(pr) }
25
34
  end
26
35
 
36
+ def announce(channel: 'releases', **options)
37
+ return Logger.warn 'Announcement blank, nothing posted to Slack' unless announcement?
38
+ options[:payload] = { channel: channel, username: 'New Releases', icon_emoji: ':tada:', text: announcement }
39
+ chat.post(options)
40
+ rescue NameError
41
+ Logger.warn "Install Slackistrano to announce releases on Slack"
42
+ end
43
+
44
+ def create_release(name = nil)
45
+ return Logger.warn 'No new stories, skipping GitHub release' if stories.none?
46
+ name ||= Time.now.to_i.to_s
47
+ github.create_release(repo, "release-#{name}", name: name, body: stories.map(&:to_markdown).join("\n"))
48
+ end
49
+
27
50
  private
28
51
 
29
52
  def editor
30
- Editor.new(draft)
53
+ Editor.new(draft.render)
31
54
  end
32
55
 
33
56
  def draft
34
- ERB.new(File.read(template), nil, '-').result(binding)
57
+ Draft.new(comment: @comment, stories: stories)
35
58
  end
36
59
 
37
- def template
38
- File.join(File.expand_path('../../templates', __FILE__), 'fiesta.erb')
60
+ def announcement?
61
+ announcement && !announcement.empty?
39
62
  end
40
63
 
41
64
  def merged_pull_requests
42
65
  github.search_issues("base:master repo:#{repo} merged:>#{last_released_at}").items
43
66
  rescue Octokit::UnprocessableEntity => e
44
- log "Unable to access GitHub. Message given was: #{e.message}"
67
+ Logger.warn "Unable to access GitHub. Message given was: #{e.message}"
45
68
  []
46
69
  end
47
70
 
@@ -54,26 +77,11 @@ module Capistrano
54
77
  end
55
78
 
56
79
  def github
57
- @github ||= Octokit::Client.new(config)
58
- end
59
-
60
- def config
61
- { access_token: hub_config["oauth_token"] }
62
- end
63
-
64
- def hub_config_path
65
- Dir.home + "/.config/hub"
66
- end
67
-
68
- def hub_config
69
- YAML.load_file(hub_config_path)["github.com"].first
70
- rescue Errno::ENOENT
71
- log "No github config found at #{hub_config_path}, using ENV defaults (https://github.com/octokit/octokit.rb/blob/master/lib/octokit/default.rb)"
72
- {}
80
+ @github ||= Github.new.client
73
81
  end
74
82
 
75
- def log(message)
76
- @logs << "[FIESTA] #{message}"
83
+ def chat
84
+ self.class.chat_client || Slackistrano
77
85
  end
78
86
  end
79
87
  end
@@ -12,6 +12,14 @@ module Capistrano
12
12
  def images
13
13
  @pr.body.scan(/https?:\/\/\S*\.(?:png|jpg|gif)/i)
14
14
  end
15
+
16
+ def url
17
+ @pr.html_url
18
+ end
19
+
20
+ def to_markdown
21
+ "- [#{title}](#{url})"
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Fiesta
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -1,6 +1,5 @@
1
-
2
1
  namespace :fiesta do
3
- desc 'Generate a release report for pasting in Slack'
2
+ desc 'Generate a release report and post it on Slack'
4
3
  task :report do
5
4
  invoke 'fiesta:set_last_release'
6
5
  invoke 'fiesta:generate'
@@ -16,28 +15,22 @@ namespace :fiesta do
16
15
 
17
16
  task :generate do
18
17
  run_locally do
19
- next warn 'Install Slackistrano to post Fiesta reports to Slack' unless defined?(Slackistrano)
20
- report = Capistrano::Fiesta::Report.new(repo_url, last_release: fetch(:last_release), comment: fetch(:fiesta_comment))
21
- result = report.write
22
-
23
- if result && !result.empty?
24
- Slackistrano.post(
25
- team: fetch(:slack_team),
26
- token: fetch(:slack_token),
27
- webhook: fetch(:slack_webhook),
28
- via_slackbot: fetch(:slack_via_slackbot),
29
- payload: {
30
- channel: fetch(:fiesta_slack_channel),
31
- username: 'New Releases',
32
- icon_emoji: ':tada:',
33
- text: result
34
- }
35
- )
36
- else
37
- report.logs.each { |log| warn log }
38
- end
18
+ report = Capistrano::Fiesta::Report.create(repo_url, last_release: fetch(:last_release), comment: fetch(:fiesta_comment))
19
+ report.announce(slack)
20
+ report.create_release(fetch(:release_name)) if fetch(:branch) == 'master'
21
+ Capistrano::Fiesta::Logger.logs.each { |log| warn log }
39
22
  end
40
23
  end
24
+
25
+ def slack
26
+ {
27
+ team: fetch(:slack_team),
28
+ token: fetch(:slack_token),
29
+ webhook: fetch(:slack_webhook),
30
+ via_slackbot: fetch(:slack_via_slackbot),
31
+ channel: fetch(:fiesta_slack_channel)
32
+ }
33
+ end
41
34
  end
42
35
 
43
36
  before 'deploy:starting', 'fiesta:set_last_release'
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-fiesta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -169,12 +169,15 @@ files:
169
169
  - capistrano-fiesta.gemspec
170
170
  - lib/capistrano-fiesta.rb
171
171
  - lib/capistrano/fiesta.rb
172
+ - lib/capistrano/fiesta/draft.rb
172
173
  - lib/capistrano/fiesta/editor.rb
174
+ - lib/capistrano/fiesta/github.rb
175
+ - lib/capistrano/fiesta/logger.rb
173
176
  - lib/capistrano/fiesta/report.rb
174
177
  - lib/capistrano/fiesta/story.rb
175
178
  - lib/capistrano/fiesta/version.rb
176
179
  - lib/capistrano/tasks/fiesta.rake
177
- - lib/capistrano/templates/fiesta.erb
180
+ - lib/capistrano/templates/draft.erb
178
181
  homepage: https://github.com/balvig/capistrano-fiesta
179
182
  licenses:
180
183
  - MIT