gitlab-fogbugz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md ADDED
@@ -0,0 +1,12 @@
1
+ # 0.0.3 / 2012-07-15
2
+ * Make gitlab-fogbugz-server actually work when installed as gem
3
+ * Fix tests in Ruby 1.9.2 (did work in 1.8 and 1.9.3)
4
+
5
+ # 0.0.2 / 2012-07-12
6
+ * Switched from curl to programmatically use the FogBugz API via ruby-fogbugz
7
+ The initial reason to use curl were Ruby 1.8 SSL issues; just hope they've
8
+ been fixed in the last four years.
9
+
10
+ # 0.0.1 / 2012-07-12
11
+ * Forked from github-fogbugz
12
+ * First adaption to work with GitLiab
data/README.markdown CHANGED
@@ -1,5 +1,6 @@
1
1
  GitLab + Fogbugz
2
2
  ===
3
+ (forked and adapted from [github-fogbugz](https://github.com/johnreilly/github-fogbugz/))
3
4
 
4
5
  This is a simple sinatra application that has three responsibilities:
5
6
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  require "rake/gempackagetask"
5
5
 
6
6
  GEM = "gitlab-fogbugz"
7
- VERSION = "0.0.2"
7
+ VERSION = "0.0.3"
8
8
  AUTHOR = ["John Reilly", "François Beausoleil", "Markus Fischer"]
9
9
  EMAIL = ["jr@trms.com", "francois@teksol.info", "markus@fischer.name"]
10
10
  HOMEPAGE = "http://github.com/mfn/gitlab-fogbugz"
@@ -32,7 +32,7 @@ spec = Gem::Specification.new do |s|
32
32
  s.require_path = "lib"
33
33
 
34
34
  # Must reference lib/message_parser.rb explicitely, or it won't be automatically generated
35
- s.files = %w(LICENSE README.markdown Rakefile TODO lib/message_parser.rb) + Dir.glob("{lib,test,config,samples,bin}/**/*")
35
+ s.files = %w(HISTORY.md LICENSE README.markdown Rakefile TODO lib/message_parser.rb) + Dir.glob("{lib,test,config,samples,bin}/**/*")
36
36
  end
37
37
 
38
38
  Rake::GemPackageTask.new(spec) do |pkg|
data/TODO CHANGED
@@ -1,3 +1,6 @@
1
- TODO:
2
- - Implement FogBugz checkins once GitLab provides this feature
1
+ # TODO:
2
+ * Implement FogBugz checkins once GitLab provides this feature
3
3
  (see https://github.com/gitlabhq/gitlabhq/issues/747 )
4
+ * After switching to Sinatra::Base, automagically --help and e.g. setting port
5
+ from sinatra isn't available anymore. Provide some alternative or do in a
6
+ smarter way.
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # vim: filetype=ruby:
2
3
  require 'rubygems'
3
4
  require 'json'
4
- require 'sinatra'
5
+ require 'sinatra/base'
5
6
  require 'yaml'
6
7
  require 'cgi'
7
8
  require 'fileutils'
@@ -60,128 +61,130 @@ end
60
61
  # about all of your developers. Each dev must
61
62
  # authenticate once with this app, then the token
62
63
  # is kept on the filesystem.
64
+ class GitlabFogbugzServer < Sinatra::Base
63
65
 
64
- ##
65
- # GitLab should send its post-receive hook here.
66
- post '/' do
67
- request.body.rewind
68
- GitlabFogbugz.new(request.body.read)
69
- end
66
+ ##
67
+ # GitLab should send its post-receive hook here.
68
+ post '/' do
69
+ request.body.rewind
70
+ GitlabFogbugz.new(request.body.read)
71
+ end
70
72
 
71
- AUTH_FORM = lambda {|fb_url, params|
72
- <<-EOHTML
73
- <h1>FogBugz Authentication</h1>
74
- <p>This form will authenticate you to <strong>#{fb_url}</strong></p>
75
- <form method="post" action="/authenticate">
76
- <p><label for="email">Email:</label><br/>
77
- <input name="email" size="40" value="#{params['email']}"/></p>
78
- <p><label for="password">Password:</label><br/>
79
- <input type="password" name="password" size="20"/></p>
80
- <p><input type="submit" value="Authenticate to FogBugz"/></p>
81
- </form>
82
- EOHTML
83
- }
73
+ AUTH_FORM = lambda {|fb_url, params|
74
+ <<-EOHTML
75
+ <h1>FogBugz Authentication</h1>
76
+ <p>This form will authenticate you to <strong>#{fb_url}</strong></p>
77
+ <form method="post" action="/authenticate">
78
+ <p><label for="email">Email:</label><br/>
79
+ <input name="email" size="40" value="#{params['email']}"/></p>
80
+ <p><label for="password">Password:</label><br/>
81
+ <input type="password" name="password" size="20"/></p>
82
+ <p><input type="submit" value="Authenticate to FogBugz"/></p>
83
+ </form>
84
+ EOHTML
85
+ }
84
86
 
85
- get "/login" do
86
- if fb_main_url = config['fb_main_url'] then
87
- AUTH_FORM.call(fb_main_url, Hash.new)
88
- else
89
- "<h1>A configuration error exists</h1><p>Ooops, the configuration file does not exist at path: <strong><tt>#{config_path}</tt></strong>.</p>"
87
+ get "/login" do
88
+ if fb_main_url = config['fb_main_url'] then
89
+ AUTH_FORM.call(fb_main_url, Hash.new)
90
+ else
91
+ "<h1>A configuration error exists</h1><p>Ooops, the configuration file does not exist at path: <strong><tt>#{config_path}</tt></strong>.</p>"
92
+ end
90
93
  end
91
- end
92
94
 
93
- post "/authenticate" do
94
- begin
95
- api = Fogbugz::Interface.new(:email => params["email"], :password => params["password"], :uri => config["fb_main_url"])
96
- tokens[ params["email"] ] = api.authenticate
97
- write_tokens
98
- redirect "/authenticated"
99
- rescue Fogbugz::AuthenticationException
100
- "<p>Failed authentication: <strong>#{$!.message}</strong></p>" + AUTH_FORM.call(config['fb_main_url'], params)
95
+ post "/authenticate" do
96
+ begin
97
+ api = Fogbugz::Interface.new(:email => params["email"], :password => params["password"], :uri => config["fb_main_url"])
98
+ tokens[ params["email"] ] = api.authenticate
99
+ write_tokens
100
+ redirect "/authenticated"
101
+ rescue Fogbugz::AuthenticationException
102
+ "<p>Failed authentication: <strong>#{$!.message}</strong></p>" + AUTH_FORM.call(config['fb_main_url'], params)
103
+ end
101
104
  end
102
- end
103
-
104
- get "/authenticated" do
105
- <<-HTML
106
- <h1>Authenticated</h1>
107
- <p>You are now authenticated to FogBugz. Go forth and commit!</p>
108
-
109
- <h2>Writing commit messages</h2>
110
- <p>Your commit messages can now contain text like the following to automatically manage your cases:</p>
111
- <blockquote>
112
- <p>Implemented foo, corrected baz.</p>
113
- <p>Implements #1234, references #2345. Closes #1234.</p>
114
- </blockquote>
115
- <p>This would automatically add the commit message to cases #1234 <em>and</em> #2345. The commit message will be appended as an event to the case. In addition, case #1234 will be closed.</p>
116
- <p>You can also mention multiple cases with one keyword, e.g. <tt>Implements #1234 and #5123</tt>.</p>
117
- <p>GitlabFogbugz recognizes the following keywords (also singular versions of the same keywords):</p>
118
- <ul>
119
- <li><tt>bugzid:</tt><br>For "compatibility" with the subversion wrapper provided by Fogcreek; however you still need to prefix the case number with <tt>#</tt>. Works like <tt>references</tt>.</li>
120
- <li><tt>closes</tt></li>
121
- <li><tt>completes</tt></li>
122
- <li><tt>fixes</tt></li>
123
- <li><tt>implements</tt></li>
124
- <li><tt>reopens</tt></li>
125
- <li><tt>references</tt> or <tt>refs</tt><br>Does not change the state of the case, just adds the commit message to this case.</li>
126
- <li><tt>resolves</tt><br>Resolves is different then <tt>closes</tt>, <tt>completes</tt>, <tt>fixes</tt> and <tt>implements</tt>: it does not explicitly sets the FogBugz case status, thus changes the case to it's categories default status for resolved cases: Bug -&gt; "fixed", Feature -&gt; "Implemented", Inquiry -&gt; "Responded" and Schedule Item -&gt; "Completed"</li>
127
- </ul>
128
- <p>NOTE: FogBugz does not allow closing a case that isn't resolved, so you really must use "Implements X, closes X", or else it won't work.</p>
129
- <p>Back to <a href="/tokens">Authenticated users</a></p>
130
- HTML
131
- end
132
105
 
133
- get "/tokens" do
134
- response = []
135
- response << "<h1>List of authenticated users</h1>"
136
- response << "<ul>"
137
- tokens.map do |email, token|
138
- response << "<li>#{email}"
139
- response << %Q(<form method="post" action="/remove"><input type="hidden" name="email" value="#{email}"/><input type="submit" value="Remove"/></form>)
140
- response << "</li>"
106
+ get "/authenticated" do
107
+ <<-HTML
108
+ <h1>Authenticated</h1>
109
+ <p>You are now authenticated to FogBugz. Go forth and commit!</p>
110
+
111
+ <h2>Writing commit messages</h2>
112
+ <p>Your commit messages can now contain text like the following to automatically manage your cases:</p>
113
+ <blockquote>
114
+ <p>Implemented foo, corrected baz.</p>
115
+ <p>Implements #1234, references #2345. Closes #1234.</p>
116
+ </blockquote>
117
+ <p>This would automatically add the commit message to cases #1234 <em>and</em> #2345. The commit message will be appended as an event to the case. In addition, case #1234 will be closed.</p>
118
+ <p>You can also mention multiple cases with one keyword, e.g. <tt>Implements #1234 and #5123</tt>.</p>
119
+ <p>GitlabFogbugz recognizes the following keywords (also singular versions of the same keywords):</p>
120
+ <ul>
121
+ <li><tt>bugzid:</tt><br>For "compatibility" with the subversion wrapper provided by Fogcreek; however you still need to prefix the case number with <tt>#</tt>. Works like <tt>references</tt>.</li>
122
+ <li><tt>closes</tt></li>
123
+ <li><tt>completes</tt></li>
124
+ <li><tt>fixes</tt></li>
125
+ <li><tt>implements</tt></li>
126
+ <li><tt>reopens</tt></li>
127
+ <li><tt>references</tt> or <tt>refs</tt><br>Does not change the state of the case, just adds the commit message to this case.</li>
128
+ <li><tt>resolves</tt><br>Resolves is different then <tt>closes</tt>, <tt>completes</tt>, <tt>fixes</tt> and <tt>implements</tt>: it does not explicitly sets the FogBugz case status, thus changes the case to it's categories default status for resolved cases: Bug -&gt; "fixed", Feature -&gt; "Implemented", Inquiry -&gt; "Responded" and Schedule Item -&gt; "Completed"</li>
129
+ </ul>
130
+ <p>NOTE: FogBugz does not allow closing a case that isn't resolved, so you really must use "Implements X, closes X", or else it won't work.</p>
131
+ <p>Back to <a href="/tokens">Authenticated users</a></p>
132
+ HTML
141
133
  end
142
134
 
143
- response << "</ul>"
144
- response << %Q(<p><a href="/login">Add a user</a></p>)
145
- response.join("\n")
146
- end
147
-
148
- post "/remove" do
149
- redirect "/tokens" unless params["email"]
150
- tokens.delete(params["email"])
151
- write_tokens
152
- redirect "/tokens"
153
- end
135
+ get "/tokens" do
136
+ response = []
137
+ response << "<h1>List of authenticated users</h1>"
138
+ response << "<ul>"
139
+ tokens.map do |email, token|
140
+ response << "<li>#{email}"
141
+ response << %Q(<form method="post" action="/remove"><input type="hidden" name="email" value="#{email}"/><input type="submit" value="Remove"/></form>)
142
+ response << "</li>"
143
+ end
154
144
 
155
- ##
156
- # Set the log and diff urls (in fogbugz's site settings) to point here.
157
- # Log url: http://localhost:4567/repo_url?type=log&repo=^REPO&file=^FILE&r1=^R1&r2=^R2
158
- # Diff url: http://localhost:4567/repo_url?type=diff&repo=^REPO&file=^FILE&r1=^R1&r2=^R2
159
- get '/repo_url' do
160
- #pull out the repo's scm viewer url from the config file
161
- if params[:type] == 'log'
162
- url = config['repos'][params[:repo]]['log_url']
163
- elsif params[:type] == 'diff'
164
- url = config['repos'][params[:repo]]['diff_url']
165
- else
166
- "Unknown repo viewer type."
145
+ response << "</ul>"
146
+ response << %Q(<p><a href="/login">Add a user</a></p>)
147
+ response.join("\n")
167
148
  end
168
-
169
- if url
170
- url.gsub!(/\^REPO/, params[:repo])
171
- url.gsub!(/\^FILE/, params[:file])
172
- url.gsub!(/\^R1/, params[:r1])
173
- url.gsub!(/\^R2/, params[:r2])
174
- redirect url
149
+
150
+ post "/remove" do
151
+ redirect "/tokens" unless params["email"]
152
+ tokens.delete(params["email"])
153
+ write_tokens
154
+ redirect "/tokens"
175
155
  end
156
+
157
+ ##
158
+ # Set the log and diff urls (in fogbugz's site settings) to point here.
159
+ # Log url: http://localhost:4567/repo_url?type=log&repo=^REPO&file=^FILE&r1=^R1&r2=^R2
160
+ # Diff url: http://localhost:4567/repo_url?type=diff&repo=^REPO&file=^FILE&r1=^R1&r2=^R2
161
+ get '/repo_url' do
162
+ #pull out the repo's scm viewer url from the config file
163
+ if params[:type] == 'log'
164
+ url = config['repos'][params[:repo]]['log_url']
165
+ elsif params[:type] == 'diff'
166
+ url = config['repos'][params[:repo]]['diff_url']
167
+ else
168
+ "Unknown repo viewer type."
169
+ end
176
170
 
177
- end
171
+ if url
172
+ url.gsub!(/\^REPO/, params[:repo])
173
+ url.gsub!(/\^FILE/, params[:file])
174
+ url.gsub!(/\^R1/, params[:r1])
175
+ url.gsub!(/\^R2/, params[:r2])
176
+ redirect url
177
+ end
178
+
179
+ end
178
180
 
179
- error do
180
- err = request.env['sinatra.error']
181
- puts "Error handling request: #{err.name}"
182
- puts err.backtrace.join("\n")
183
- end
181
+ error do
182
+ err = request.env['sinatra.error']
183
+ puts "Error handling request: #{err.name}"
184
+ puts err.backtrace.join("\n")
185
+ end
184
186
 
187
+ end
185
188
 
186
189
  ##
187
190
  # This class does all of the json parsing and submits a push's commits to fogbugz
@@ -255,3 +258,5 @@ class GitlabFogbugz
255
258
  end
256
259
  end
257
260
  end
261
+
262
+ GitlabFogbugzServer.run!
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/test_helper"
1
+ require_relative "test_helper"
2
2
  require "fogbugz_listener"
3
3
 
4
4
  class FogbugzListenerTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/test_helper"
1
+ require_relative "test_helper"
2
2
  require "message_parser"
3
3
 
4
4
  class MessageParserTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-fogbugz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-14 00:00:00.000000000 Z
14
+ date: 2012-07-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sinatra
@@ -92,6 +92,7 @@ extra_rdoc_files:
92
92
  - LICENSE
93
93
  - TODO
94
94
  files:
95
+ - HISTORY.md
95
96
  - LICENSE
96
97
  - README.markdown
97
98
  - Rakefile