capistrano-github-releases 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c039113c72bc7bd53910a0972e31e6e8dd2d8b6d
4
+ data.tar.gz: 5b9987290f4d22c063862a75d20a26b0986f98b1
5
+ SHA512:
6
+ metadata.gz: a7167d91088eb9473ed46b13e48d90fc57f0c6ca021009698dd982486ced0c442312524dfed762cf25e88aa6305e2ac7c53ade38787ae9b247a32a4352ffb72b
7
+ data.tar.gz: 7907ed41515ab6faf811f82029eb4339d7e23362188276037ecf69e55194385ae3d554e688688567919cf0f2683e98e3e7171cc1d0a04f076241d0915df152d1
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-github-releases.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 linyows
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ Capistrano::Github::Releases
2
+ ============================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/capistrano-github-releases.png)][gem]
5
+ [gem]: https://rubygems.org/gems/capistrano-github-releases
6
+
7
+ GitHub Releases tasks for Capistrano v3:
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'capistrano-github-releases'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install capistrano-github-releases
23
+
24
+ Usage
25
+ -----
26
+
27
+ Capfile:
28
+
29
+ ```ruby
30
+ require 'capistrano/github/releases'
31
+ ```
32
+
33
+ deploy/production.rb:
34
+
35
+ ```ruby
36
+ after 'deploy:published', 'github:releases:create'
37
+ after 'deploy:published', 'github:releases:add_comment'
38
+ ```
39
+
40
+
41
+ Contributing
42
+ ------------
43
+
44
+ 1. Fork it ( http://github.com/<my-github-username>/capistrano-github-releases/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/github/releases/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-github-releases"
8
+ spec.version = Capistrano::Github::Releases::VERSION
9
+ spec.authors = ["linyows"]
10
+ spec.email = ["linyows@gmail.com"]
11
+ spec.summary = %q{GitHub Releases tasks for Capistrano v3}
12
+ spec.description = %q{GitHub Releases tasks for Capistrano v3}
13
+ spec.homepage = "https://github.com/linyows/capistrano-github-releases"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "capistrano", "~> 3.1"
22
+ spec.add_dependency "octokit", "~> 2.7.0"
23
+ spec.add_dependency "highline", "~> 1.6.20"
24
+ spec.add_dependency "dotenv", "~> 0.9.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,10 @@
1
+ load File.expand_path('../../tasks/github_releases.rake', __FILE__)
2
+
3
+ require 'capistrano/github/releases/version'
4
+
5
+ module Capistrano
6
+ module Github
7
+ module Releases
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Capistrano
2
+ module Github
3
+ module Releases
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,140 @@
1
+ require 'octokit'
2
+ require 'dotenv'
3
+ require 'highline'
4
+
5
+ Dotenv.load
6
+
7
+ module Dotenv
8
+ def self.add(key_value, filename = nil)
9
+ filename = File.expand_path(filename || '.env')
10
+ f = File.open(filename, File.exists?(filename) ? 'a' : 'w')
11
+ f.puts key_value
12
+ key, value = key_value.split('=')
13
+ ENV[key] = value
14
+ end
15
+ end
16
+
17
+ namespace :github do
18
+ namespace :releases do
19
+ set :username, -> {
20
+ username = `git config --get user.name`.strip
21
+ username = `whoami`.strip unless username
22
+ username
23
+ }
24
+
25
+ set :github_username, -> {
26
+ if ENV['GITHUB_USERNAME'].nil?
27
+ username = HighLine.new.ask("GitHub Username? [default: #{fetch(:username)}]")
28
+ Dotenv.add "GITHUB_USERNAME=#{username}"
29
+ else
30
+ ENV['GITHUB_USERNAME']
31
+ end
32
+ }
33
+
34
+ set :release_title, -> {
35
+ begin
36
+ pull_request = Octokit.pull(fetch(:github_repo), fetch(:pull_request_id))
37
+ default_title = pull_request.title
38
+ rescue => e
39
+ puts e
40
+ default_title = fetch(:release_tag)
41
+ end
42
+ title = HighLine.new.ask("Release Title? [default: #{default_title}]")
43
+ title = default_title if title.empty?
44
+ title
45
+ }
46
+
47
+ set :release_body, -> {
48
+ pull_req = "pull request: #{fetch(:github_repo)}##{fetch(:pull_request_id)}"
49
+ body = HighLine.new.ask("Release Comment? [default: #{pull_req}]")
50
+ "#{body + "\n" unless body.empty?}#{pull_req}"
51
+ }
52
+
53
+ set :release_tag, -> {
54
+ Time.now.strftime('release-%Y%m%d-%H%M')
55
+ }
56
+
57
+ set :pull_request_id, -> {
58
+ merge_comment = `git log | grep 'Merge pull request' | head -n 1`
59
+ merge_comment.match(/#(\d+)/)[1].to_i
60
+ }
61
+
62
+ set :release_comment, -> {
63
+ url = "#{fetch(:github_releases_path)}/#{fetch(:release_tag)}"
64
+ <<-MD.gsub(/^ {6}/, '').strip
65
+ I deployed this with production environment and created a release tag. :octocat:
66
+ #{fetch(:release_title)}: [#{fetch(:release_tag)}](#{url})
67
+ MD
68
+ }
69
+
70
+ set :github_token, -> {
71
+ if ENV['GITHUB_PERSONAL_ACCESS_TOKEN'].nil?
72
+ token = HighLine.new.ask('GitHub Personal Access Token?')
73
+ Dotenv.add "GITHUB_PERSONAL_ACCESS_TOKEN=#{token}"
74
+ else
75
+ ENV['GITHUB_PERSONAL_ACCESS_TOKEN']
76
+ end
77
+ }
78
+
79
+ set :github_repo, -> {
80
+ repo = "#{fetch(:repo_url)}"
81
+ repo.match(/([\w-]+\/[\w-]+)\.git$/)[1]
82
+ }
83
+
84
+ set :github_releases_path, -> {
85
+ "#{Octokit.web_endpoint}#{fetch(:github_repo)}/releases/tag"
86
+ }
87
+
88
+ set :github_authentication, -> {
89
+ Octokit.configure do |c|
90
+ c.login = fetch(:github_username)
91
+ c.access_token = fetch(:github_token)
92
+ end
93
+ }
94
+
95
+ desc 'Create new release note.'
96
+ task :create do
97
+ begin
98
+ fetch(:github_authentication)
99
+
100
+ Octokit.create_release(
101
+ fetch(:github_repo),
102
+ fetch(:release_tag),
103
+ name: fetch(:release_title),
104
+ body: fetch(:release_body),
105
+ target_commitish: 'master',
106
+ draft: false,
107
+ prerelease: false
108
+ )
109
+ rescue => e
110
+ puts e
111
+ invoke 'github:git:create_tag_and_push_origin'
112
+ end
113
+ end
114
+
115
+ desc 'Add comment for new release.'
116
+ task :add_comment do
117
+ begin
118
+ fetch(:github_authentication)
119
+
120
+ Octokit.add_comment(
121
+ fetch(:github_repo),
122
+ fetch(:pull_request_id),
123
+ fetch(:release_comment)
124
+ )
125
+ rescue => e
126
+ puts e
127
+ end
128
+ end
129
+ end
130
+
131
+ namespace :git do
132
+ desc 'Create tag for new release and push to origin.'
133
+ task :create_tag_and_push_origin do
134
+ message = "#{fetch(:release_title)} by #{fetch(:username)}\n"
135
+ message += "#{fetch(:github_repo)}##{fetch(:pull_request_id)}"
136
+ `git tag -am "#{message}" #{fetch(:release_tag)}`
137
+ `git push origin #{fetch(:release_tag)}`
138
+ end
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-github-releases
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-24 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: 2.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.20
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.20
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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
+ description: GitHub Releases tasks for Capistrano v3
98
+ email:
99
+ - linyows@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - capistrano-github-releases.gemspec
110
+ - lib/capistrano/github/releases.rb
111
+ - lib/capistrano/github/releases/version.rb
112
+ - lib/capistrano/tasks/github_releases.rake
113
+ homepage: https://github.com/linyows/capistrano-github-releases
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.0
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: GitHub Releases tasks for Capistrano v3
137
+ test_files: []