capistrano-fiesta 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2fc4b1af2b47f2a45c0e8b60aadc60a658dbb4ea
4
+ data.tar.gz: 1cb5f0e91853e6aedc27fd362e25682ef06affff
5
+ SHA512:
6
+ metadata.gz: 9542290e2c26fc476a0d480cfdd0f9f93921db86cc8195470736d40b3a64516f9713b26e9768cc71eab84e6bae38425532599682ad1fb0e8e31129c998a5882b
7
+ data.tar.gz: b57b86256495b92c2f5583d53fc9f895f12e225e4653ecf5d245b14832ac0bc11d81ba8e8c01794872957bf1c5c5806f5352125a49fe8fb61e9f601206ba7829
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-fiesta.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jens Balvig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # capistrano-fiesta
2
+
3
+ capistrano-fiesta integrates capistrano with GitHub pull requests and Slack, making
4
+ sharing release reports with the rest of the team a breeze.
5
+
6
+ When deploying, capistrano-fiesta will compile an editable list of merged pull
7
+ request titles since the last release, pulling out any images from the descriptions so they can be attached as screenshots:
8
+
9
+ ![editor](https://cloud.githubusercontent.com/assets/104138/10676263/57b6bb44-7905-11e5-8df3-38e96a2a0685.png)
10
+
11
+ The edited content will be posted to Slack:
12
+
13
+ ![slack](https://cloud.githubusercontent.com/assets/104138/10676270/63f627b4-7905-11e5-88e7-b60c08aada99.png)
14
+
15
+
16
+ ## Installing
17
+
18
+ 1. To get automated posting to Slack, first install [Slackistrano](https://github.com/phallstrom/slackistrano).
19
+ 2. Add capistrano-fiesta to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'capistrano-fiesta'
23
+ ```
24
+ 3. Require in the capfile or appropriate stage and configure the Slack channel:
25
+
26
+ ```ruby
27
+ require 'capybara-fiesta'
28
+ set :fiesta_slack_channel, '#release'
29
+ ```
30
+ 4. If you're using [hub](https://github.com/github/hub) your GitHub credentials should already be configured. Otherwise you can use the [ENV vars in Octokit](https://github.com/octokit/octokit.rb/blob/a98979107a4bf9741a05a1f751405f8a29f29b38/lib/octokit/default.rb#L42-L156) to configure GitHub access.
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/balvig/capistrano-fiesta.
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capistrano/fiesta"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/fiesta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-fiesta"
8
+ spec.version = Capistrano::Fiesta::VERSION
9
+ spec.authors = ["Jens Balvig"]
10
+ spec.email = ["jens@balvig.com"]
11
+
12
+ spec.summary = %q{Celebrate your releases!}
13
+ spec.description = %q{Automatically creates a report of merged PRs since last deploy for pasting into slack}
14
+ spec.homepage = "https://github.com/balvig/capistrano-fiesta"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "capistrano", "~> 3.1"
23
+ spec.add_dependency "octokit", "~> 4.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "multi_json"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "webmock"
31
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ require "capistrano/fiesta/report"
2
+
3
+ load File.expand_path("../tasks/fiesta.rake", __FILE__)
@@ -0,0 +1,87 @@
1
+ require "capistrano/fiesta/story"
2
+ require "erb"
3
+ require "tempfile"
4
+ require "octokit"
5
+ require "yaml"
6
+
7
+ module Capistrano
8
+ module Fiesta
9
+ class Report
10
+ attr_accessor :logs
11
+
12
+ def initialize(github_url, last_release: Time.now)
13
+ @github_url, @last_release = github_url, last_release
14
+ @logs = []
15
+ end
16
+
17
+ def write
18
+ open_in_editor if stories.any?
19
+ end
20
+
21
+ def stories
22
+ @stories ||= merged_pull_requests.map { |pr| Story.new(pr) }
23
+ end
24
+
25
+ private
26
+
27
+ def open_in_editor
28
+ file << draft
29
+ file.close
30
+ Kernel.system(ENV["EDITOR"] || "vi", file.path)
31
+ file.open
32
+ file.unlink
33
+ file.read.force_encoding("utf-8")
34
+ end
35
+
36
+ def file
37
+ @file ||= Tempfile.new(['fiesta', '.md'])
38
+ end
39
+
40
+ def draft
41
+ ERB.new(File.read(template), nil, '-').result(binding)
42
+ end
43
+
44
+ def template
45
+ File.join(File.expand_path('../../templates', __FILE__), 'fiesta.erb')
46
+ end
47
+
48
+ def merged_pull_requests
49
+ github.search_issues("base:master repo:#{repo} merged:>#{last_released_at}").items
50
+ rescue Octokit::UnprocessableEntity => e
51
+ log "Unable to access GitHub. Message given was: #{e.message}"
52
+ []
53
+ end
54
+
55
+ def repo
56
+ @github_url.match(/github.com[:\/](\S+\/\S+)\.git/)[1]
57
+ end
58
+
59
+ def last_released_at
60
+ Time.parse(@last_release + 'Z00:00').iso8601
61
+ end
62
+
63
+ def github
64
+ @github ||= Octokit::Client.new(config)
65
+ end
66
+
67
+ def config
68
+ { access_token: hub_config["oauth_token"] }
69
+ end
70
+
71
+ def hub_config_path
72
+ Dir.home + "/.config/hub"
73
+ end
74
+
75
+ def hub_config
76
+ YAML.load_file(hub_config_path)["github.com"].first
77
+ rescue Errno::ENOENT
78
+ log "No github config found at #{hub_config_path}, using ENV defaults (https://github.com/octokit/octokit.rb/blob/master/lib/octokit/default.rb)"
79
+ {}
80
+ end
81
+
82
+ def log(message)
83
+ @logs << "[FIESTA] #{message}"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,17 @@
1
+ module Capistrano
2
+ module Fiesta
3
+ class Story
4
+ def initialize(pr)
5
+ @pr = pr
6
+ end
7
+
8
+ def title
9
+ @pr.title.sub(/\[Delivers #\d+\]\z/, '').strip
10
+ end
11
+
12
+ def images
13
+ @pr.body.scan(/https?:\/\/\S*\.(?:png|jpg|gif)/i)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Fiesta
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+
2
+ namespace :fiesta do
3
+ desc 'Generate a release report for pasting in Slack'
4
+ task :report do
5
+ invoke 'fiesta:set_last_release'
6
+ invoke 'fiesta:generate'
7
+ end
8
+
9
+ task :set_last_release do
10
+ on roles(:web).first do
11
+ releases = capture("ls #{releases_path}")
12
+ last_release = releases.split("\n").sort.last
13
+ set(:last_release, last_release)
14
+ end
15
+ end
16
+
17
+ task :generate do
18
+ 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))
21
+ result = report.write
22
+
23
+ if !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
39
+ end
40
+ end
41
+ end
42
+
43
+ before 'deploy:starting', 'fiesta:set_last_release'
44
+ after 'deploy:finished', 'fiesta:generate'
@@ -0,0 +1,6 @@
1
+ <% stories.sort_by(&:title).each do |story| -%>
2
+ • <%= story.title %>
3
+ <% story.images.each do |image| -%>
4
+ <<%= image %>|Screenshot>
5
+ <% end -%>
6
+ <% end -%>
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-fiesta
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jens Balvig
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Automatically creates a report of merged PRs since last deploy for pasting
126
+ into slack
127
+ email:
128
+ - jens@balvig.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - capistrano-fiesta.gemspec
142
+ - lib/capistrano-fiesta.rb
143
+ - lib/capistrano/fiesta.rb
144
+ - lib/capistrano/fiesta/report.rb
145
+ - lib/capistrano/fiesta/story.rb
146
+ - lib/capistrano/fiesta/version.rb
147
+ - lib/capistrano/tasks/fiesta.rake
148
+ - lib/capistrano/templates/fiesta.erb
149
+ homepage: https://github.com/balvig/capistrano-fiesta
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Celebrate your releases!
173
+ test_files: []