CapistranoTrac 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +68 -0
- data/Rakefile +15 -0
- data/lib/capistrano_trac.rb +3 -0
- data/lib/capistrano_trac/recipes.rb +101 -0
- data/test/test_capistrano_trac.rb +0 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
CapistranoTrac
|
2
|
+
by HandleIT
|
3
|
+
http://handle.it
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
The capistrano_trac library provides capistrano tasks to interact with a project's Trac site.
|
8
|
+
|
9
|
+
Currently, the library simply provides 2 tasks for recording deployments and rollbacks of code related to tickets. This is done by parsing the SVN log between deployed revisions, looking for Trac formatted references to tickets (e.g. #70), and appending a comment to the tickets, recording the deployment/rollback.
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* Failure is incredibly ungraceful, though generally unlikely, given that the requirements for accessing the Trac site are roughly the same as those for accessing the repository.
|
14
|
+
* Currently, the trac user/pass must be the same as the SCM user/pass. It remains to be seen how much of a problem this will be.
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
Include the recipes:
|
19
|
+
require 'capistrano_trac/recipes'
|
20
|
+
|
21
|
+
For the trac tasks to work, the :trac_url variable must be set to the root of your trac site.
|
22
|
+
For example:
|
23
|
+
set :trac_url, "http://www.yourtrachost/trac/yourproject"
|
24
|
+
|
25
|
+
The 2 trac ticketing tasks are designed to be run in conjunction with a deployment or rollback, although this isn't mandatory.
|
26
|
+
|
27
|
+
To automatically document deployments and rollbacks in your capistrano deployment, add the lines:
|
28
|
+
|
29
|
+
* after "deploy", "trac:record_deployment"
|
30
|
+
* before "deploy:rollback", "trac:record_rollback"
|
31
|
+
|
32
|
+
Order is important, otherwise the tasks will be looking at the wrong revisions.
|
33
|
+
|
34
|
+
To manually record changes, simply run the record_deployment task to document the most recent deployment changes, or the record_rollback task to document a rollback that is about to be run.
|
35
|
+
|
36
|
+
== REQUIREMENTS:
|
37
|
+
|
38
|
+
* capistrano >= 2.0.0
|
39
|
+
* mechanize >= 0.6.10
|
40
|
+
|
41
|
+
== INSTALL:
|
42
|
+
|
43
|
+
* sudo gem install capistrano_trac
|
44
|
+
|
45
|
+
== LICENSE:
|
46
|
+
|
47
|
+
(The MIT License)
|
48
|
+
|
49
|
+
Copyright (c) 2007 FIX
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
52
|
+
a copy of this software and associated documentation files (the
|
53
|
+
'Software'), to deal in the Software without restriction, including
|
54
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
55
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
56
|
+
permit persons to whom the Software is furnished to do so, subject to
|
57
|
+
the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be
|
60
|
+
included in all copies or substantial portions of the Software.
|
61
|
+
|
62
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
63
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
65
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
66
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
67
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
68
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/capistrano_trac.rb'
|
4
|
+
|
5
|
+
Hoe.new('CapistranoTrac', CapistranoTrac::VERSION) do |p|
|
6
|
+
p.rubyforge_name = 'capistrano_trac'
|
7
|
+
p.author = 'HandleIT'
|
8
|
+
p.email = 'support@handle.it'
|
9
|
+
p.summary = 'A collection of Trac related Capistrano tasks'
|
10
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
p.url = 'http://handle.rubyforge.org'
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
p.extra_deps << ['mechanize', '>= 0.6.10']
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'net/https'
|
3
|
+
require 'mechanize'
|
4
|
+
|
5
|
+
module CapistranoTrac
|
6
|
+
configuration = Capistrano::Configuration.respond_to?( :instance ) ?
|
7
|
+
Capistrano::Configuration.instance( :must_exist ) :
|
8
|
+
Capistrano.configuration( :must_exist )
|
9
|
+
|
10
|
+
configuration.load do
|
11
|
+
namespace :trac do
|
12
|
+
# Sets up the Mechanize agent
|
13
|
+
# and logs in to Trac
|
14
|
+
def trac_setup
|
15
|
+
# Prepare the mechanize agent
|
16
|
+
agent = WWW::Mechanize.new
|
17
|
+
agent.user_agent_alias = 'Mac Safari'
|
18
|
+
agent.basic_auth( scm_username, scm_password )
|
19
|
+
# Log in to the Trac site
|
20
|
+
agent.get( trac_url + '/login' )
|
21
|
+
return agent
|
22
|
+
end
|
23
|
+
|
24
|
+
# Appends a comment to a given ticket in the Trac system
|
25
|
+
def append_comment( ticket_num, comment )
|
26
|
+
agent = trac_setup
|
27
|
+
# Grab ticket page
|
28
|
+
ticket_page = agent.get( "#{ trac_url }/ticket/#{ ticket_num }" )
|
29
|
+
# Find comment form on page
|
30
|
+
comment_form = ticket_page.forms.with.action( "#{ URI.parse( trac_url ).path }/ticket/#{ ticket_num }#preview" ).first
|
31
|
+
# Enter comment on form
|
32
|
+
comment_field = comment_form.fields.with.name( 'comment' ).first
|
33
|
+
comment_field.value = comment
|
34
|
+
# Submit with button that commits the comment rather than the preview button
|
35
|
+
comment_form.submit( comment_form.buttons.with.value( 'Submit changes' ).first )
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a Trac formatted link to a range of log messages
|
39
|
+
def log_range_link( rev_path, start_rev, end_rev )
|
40
|
+
"log:#{ rev_path }@#{ start_rev }:#{ end_rev }"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Finds the root of the repository cap is deploying from
|
44
|
+
def repository_root( repo_url )
|
45
|
+
svn_info = `svn info #{ repo_url }`
|
46
|
+
YAML.load( svn_info )['Repository Root']
|
47
|
+
end
|
48
|
+
|
49
|
+
# Finds the path within the repository that leads to the base of the app being deployed
|
50
|
+
def repository_path( repo_url )
|
51
|
+
repo_url.sub( repository_root( repo_url ), '' )
|
52
|
+
end
|
53
|
+
|
54
|
+
# Determines the current deployment stage.
|
55
|
+
# Works in both multistage and vanilla cap.
|
56
|
+
def deployment_stage
|
57
|
+
if exists?( :stage )
|
58
|
+
stage
|
59
|
+
elsif exists?( :default_stage )
|
60
|
+
default_stage
|
61
|
+
else
|
62
|
+
"production"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Finds all the ticket numbers ( in Trac format ) mentioned in the log messages
|
67
|
+
# between two changesets.
|
68
|
+
def ticket_numbers( old_rev, new_rev )
|
69
|
+
# Get all log messages between the previous and current revisions
|
70
|
+
# skip over the previous revision to avoid comments for last deployed revision
|
71
|
+
svn_log = `svn log #{ repository } -r #{ old_rev.to_i + 1 }:#{ new_rev }`
|
72
|
+
# Process log, recording instances of tickets mentioned in trac format ( #n )
|
73
|
+
( svn_log.scan(/\B#(\d+)\b/).collect { |match| match.first } ).uniq
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Appends deployment comment to the end of all trac tickets resolved by the latest deployment"
|
77
|
+
task :record_deployment, :roles => :app do
|
78
|
+
# Set previous revision to 0 if no previous revision ( i.e. first deployment )
|
79
|
+
set( :previous_revision, '0' ) unless releases.length > 1
|
80
|
+
# Check if there are actually any changesets deployed, return if not
|
81
|
+
return unless ( previous_revision.to_i + 1 ) < latest_revision.to_i
|
82
|
+
# Append a comment to each affected ticket
|
83
|
+
ticket_numbers( previous_revision, latest_revision ).each do |ticket|
|
84
|
+
comment_text = "Deployed #{ log_range_link( repository_path( repository ), previous_revision, latest_revision ) } to #{ deployment_stage } at #{ Time.now.to_s }"
|
85
|
+
append_comment( ticket, comment_text )
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "Appends rollback comments to all trac tickets resolved by the last rolled back deployment"
|
90
|
+
task :record_rollback, :roles => :app do
|
91
|
+
# Bail if nothing to roll back to
|
92
|
+
return unless releases.length > 1
|
93
|
+
# Append a comment to each affected ticket
|
94
|
+
ticket_numbers( previous_revision, latest_revision ).each do |ticket|
|
95
|
+
comment_text = "Rolled back #{ log_range_link( repository_path( repository ), previous_revision, latest_revision ) } in #{ deployment_stage } at #{ Time.now.to_s }"
|
96
|
+
append_comment( ticket, comment_text )
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: CapistranoTrac
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-10-04 00:00:00 +10:00
|
8
|
+
summary: A collection of Trac related Capistrano tasks
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: support@handle.it
|
12
|
+
homepage: http://handle.rubyforge.org
|
13
|
+
rubyforge_project: capistrano_trac
|
14
|
+
description: "== FEATURES/PROBLEMS: * Failure is incredibly ungraceful, though generally unlikely, given that the requirements for accessing the Trac site are roughly the same as those for accessing the repository. * Currently, the trac user/pass must be the same as the SCM user/pass. It remains to be seen how much of a problem this will be. == SYNOPSIS: Include the recipes: require 'capistrano_trac/recipes' For the trac tasks to work, the :trac_url variable must be set to the root of your trac site. For example: set :trac_url, \"http://www.yourtrachost/trac/yourproject\" The 2 trac ticketing tasks are designed to be run in conjunction with a deployment or rollback, although this isn't mandatory. To automatically document deployments and rollbacks in your capistrano deployment, add the lines: * after \"deploy\", \"trac:record_deployment\" * before \"deploy:rollback\", \"trac:record_rollback\" Order is important, otherwise the tasks will be looking at the wrong revisions. To manually record changes, simply run the record_deployment task to document the most recent deployment changes, or the record_rollback task to document a rollback that is about to be run. == REQUIREMENTS: * capistrano >= 2.0.0 * mechanize >= 0.6.10 == INSTALL: * sudo gem install capistrano_trac == LICENSE: (The MIT License) Copyright (c) 2007 FIX Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- HandleIT
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- lib/capistrano_trac.rb
|
37
|
+
- lib/capistrano_trac/recipes.rb
|
38
|
+
- test/test_capistrano_trac.rb
|
39
|
+
test_files:
|
40
|
+
- test/test_capistrano_trac.rb
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.txt
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mechanize
|
57
|
+
version_requirement:
|
58
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.6.10
|
63
|
+
version:
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: hoe
|
66
|
+
version_requirement:
|
67
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.3.0
|
72
|
+
version:
|