capistrano-github-pullrequests 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/capistrano-github-pullrequests.gemspec +19 -0
- data/lib/capistrano-github-pullrequests.rb +2 -0
- data/lib/capistrano-github-pullrequests/version.rb +7 -0
- data/lib/capistrano/recipes/deploy/scm/github.rb +192 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Muse
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "capistrano-github-pullrequests/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Muse"]
|
6
|
+
gem.email = ["brian.muse@gmail.com"]
|
7
|
+
gem.description = %q{Capistrano extension to deploy a github pull request}
|
8
|
+
gem.summary = %q{Capistrano extension to deploy a github pull request}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "capistrano-github-pullrequests"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Capistrano::Scm::Github::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "capistrano"
|
19
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/scm/base'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module SCM
|
6
|
+
|
7
|
+
class Github < Base
|
8
|
+
# Sets the default command name for this SCM on your *local* machine.
|
9
|
+
# Users may override this by setting the :scm_command variable.
|
10
|
+
default_command "git"
|
11
|
+
|
12
|
+
# When referencing "head", use the branch we want to deploy or, by
|
13
|
+
# default, Git's reference of HEAD (the latest changeset in the default
|
14
|
+
# branch, usually called "master").
|
15
|
+
def head
|
16
|
+
variable(:branch) || 'HEAD'
|
17
|
+
end
|
18
|
+
|
19
|
+
def origin
|
20
|
+
variable(:remote) || 'origin'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Performs a clone on the remote machine, then checkout on the branch
|
24
|
+
# you want to deploy.
|
25
|
+
def checkout(revision, destination)
|
26
|
+
git = command
|
27
|
+
remote = origin
|
28
|
+
|
29
|
+
args = []
|
30
|
+
|
31
|
+
# Add an option for the branch name so :git_shallow_clone works with branches
|
32
|
+
args << "-b #{variable(:branch)}" unless variable(:branch).nil? || variable(:branch) == revision
|
33
|
+
args << "-o #{remote}" unless remote == 'origin'
|
34
|
+
if depth = variable(:git_shallow_clone)
|
35
|
+
args << "--depth #{depth}"
|
36
|
+
end
|
37
|
+
|
38
|
+
execute = []
|
39
|
+
execute << "#{git} clone #{verbose} #{args.join(' ')} #{variable(:repository)} #{destination}"
|
40
|
+
|
41
|
+
if(variable(:pull_request_number))
|
42
|
+
execute << "cd #{destination} && #{git} fetch #{verbose} #{remote} +refs/pull/#{variable(:pull_request_number)}/merge: && #{git} checkout -qf FETCH_HEAD"
|
43
|
+
else
|
44
|
+
execute << "cd #{destination} && #{git} checkout #{verbose} -b deploy #{revision}"
|
45
|
+
end
|
46
|
+
|
47
|
+
if variable(:git_enable_submodules)
|
48
|
+
execute << "#{git} submodule #{verbose} init"
|
49
|
+
execute << "#{git} submodule #{verbose} sync"
|
50
|
+
if false == variable(:git_submodules_recursive)
|
51
|
+
execute << "#{git} submodule #{verbose} update --init"
|
52
|
+
else
|
53
|
+
execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive))
|
54
|
+
execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
execute.compact.join(" && ").gsub(/\s+/, ' ')
|
59
|
+
end
|
60
|
+
|
61
|
+
# An expensive export. Performs a checkout as above, then
|
62
|
+
# removes the repo.
|
63
|
+
def export(revision, destination)
|
64
|
+
checkout(revision, destination) << " && rm -Rf #{destination}/.git"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Merges the changes to 'head' since the last fetch, for remote_cache
|
68
|
+
# deployment strategy
|
69
|
+
def sync(revision, destination)
|
70
|
+
git = command
|
71
|
+
remote = origin
|
72
|
+
|
73
|
+
execute = []
|
74
|
+
execute << "cd #{destination}"
|
75
|
+
|
76
|
+
# Use git-config to setup a remote tracking branches. Could use
|
77
|
+
# git-remote but it complains when a remote of the same name already
|
78
|
+
# exists, git-config will just silenty overwrite the setting every
|
79
|
+
# time. This could cause wierd-ness in the remote cache if the url
|
80
|
+
# changes between calls, but as long as the repositories are all
|
81
|
+
# based from each other it should still work fine.
|
82
|
+
if remote != 'origin'
|
83
|
+
execute << "#{git} config remote.#{remote}.url #{variable(:repository)}"
|
84
|
+
execute << "#{git} config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/*"
|
85
|
+
end
|
86
|
+
|
87
|
+
# since we're in a local branch already, just reset to specified revision rather than merge
|
88
|
+
if(variable(:pull_request_number))
|
89
|
+
execute << "#{git} fetch #{verbose} #{remote} +refs/pull/#{variable(:pull_request_number)}/merge: && #{git} checkout -qf FETCH_HEAD"
|
90
|
+
else
|
91
|
+
execute << "#{git} fetch #{verbose} #{remote} && #{git} fetch --tags #{verbose} #{remote} && #{git} reset #{verbose} --hard #{revision}"
|
92
|
+
end
|
93
|
+
|
94
|
+
if variable(:git_enable_submodules)
|
95
|
+
execute << "#{git} submodule #{verbose} init"
|
96
|
+
execute << "#{git} submodule #{verbose} sync"
|
97
|
+
if false == variable(:git_submodules_recursive)
|
98
|
+
execute << "#{git} submodule #{verbose} update --init"
|
99
|
+
else
|
100
|
+
execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive))
|
101
|
+
execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Make sure there's nothing else lying around in the repository (for
|
106
|
+
# example, a submodule that has subsequently been removed).
|
107
|
+
execute << "#{git} clean #{verbose} -d -x -f"
|
108
|
+
|
109
|
+
execute.join(" && ")
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns a string of diffs between two revisions
|
113
|
+
def diff(from, to=nil)
|
114
|
+
return scm :diff, from unless to
|
115
|
+
scm :diff, "#{from}..#{to}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns a log of changes between the two revisions (inclusive).
|
119
|
+
def log(from, to=nil)
|
120
|
+
scm :log, "#{from}..#{to}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# Getting the actual commit id, in case we were passed a tag
|
124
|
+
# or partial sha or something - it will return the sha if you pass a sha, too
|
125
|
+
def query_revision(revision)
|
126
|
+
raise ArgumentError, "Deploying remote branches is no longer supported. Specify the remote branch as a local branch for the git repository you're deploying from (ie: '#{revision.gsub('origin/', '')}' rather than '#{revision}')." if revision =~ /^origin\//
|
127
|
+
return revision if revision =~ /^[0-9a-f]{40}$/
|
128
|
+
command = scm('ls-remote', repository, revision)
|
129
|
+
result = yield(command)
|
130
|
+
revdata = result.split(/[\t\n]/)
|
131
|
+
newrev = nil
|
132
|
+
revdata.each_slice(2) do |refs|
|
133
|
+
rev, ref = *refs
|
134
|
+
if ref.sub(/refs\/.*?\//, '').strip == revision.to_s
|
135
|
+
newrev = rev
|
136
|
+
break
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return newrev if newrev =~ /^[0-9a-f]{40}$/
|
140
|
+
|
141
|
+
# If sha is not found on remote, try expanding from local repository
|
142
|
+
command = scm('rev-parse --revs-only', origin + '/' + revision)
|
143
|
+
newrev = yield(command).to_s.strip
|
144
|
+
|
145
|
+
raise "Unable to resolve revision for '#{revision}' on repository '#{repository}'." unless newrev =~ /^[0-9a-f]{40}$/
|
146
|
+
return newrev
|
147
|
+
end
|
148
|
+
|
149
|
+
def command
|
150
|
+
# For backwards compatibility with 1.x version of this module
|
151
|
+
variable(:git) || super
|
152
|
+
end
|
153
|
+
|
154
|
+
# Determines what the response should be for a particular bit of text
|
155
|
+
# from the SCM. Password prompts, connection requests, passphrases,
|
156
|
+
# etc. are handled here.
|
157
|
+
def handle_data(state, stream, text)
|
158
|
+
host = state[:channel][:host]
|
159
|
+
logger.info "[#{host} :: #{stream}] #{text}"
|
160
|
+
case text
|
161
|
+
when /\bpassword.*:/i
|
162
|
+
# git is prompting for a password
|
163
|
+
unless pass = variable(:scm_password)
|
164
|
+
pass = Capistrano::CLI.password_prompt
|
165
|
+
end
|
166
|
+
%("#{pass}"\n)
|
167
|
+
when %r{\(yes/no\)}
|
168
|
+
# git is asking whether or not to connect
|
169
|
+
"yes\n"
|
170
|
+
when /passphrase/i
|
171
|
+
# git is asking for the passphrase for the user's key
|
172
|
+
unless pass = variable(:scm_passphrase)
|
173
|
+
pass = Capistrano::CLI.password_prompt
|
174
|
+
end
|
175
|
+
%("#{pass}"\n)
|
176
|
+
when /accept \(t\)emporarily/
|
177
|
+
# git is asking whether to accept the certificate
|
178
|
+
"t\n"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
# If verbose output is requested, return nil, otherwise return the
|
185
|
+
# command-line switch for "quiet" ("-q").
|
186
|
+
def verbose
|
187
|
+
variable(:scm_verbose) ? nil : "-q"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-github-pullrequests
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Muse
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Capistrano extension to deploy a github pull request
|
31
|
+
email:
|
32
|
+
- brian.muse@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- capistrano-github-pullrequests.gemspec
|
43
|
+
- lib/capistrano-github-pullrequests.rb
|
44
|
+
- lib/capistrano-github-pullrequests/version.rb
|
45
|
+
- lib/capistrano/recipes/deploy/scm/github.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.25
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Capistrano extension to deploy a github pull request
|
70
|
+
test_files: []
|