Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
elvanja committed Sep 2, 2013
2 parents fd206c1 + 99954ac commit 809bb7b
Show file tree
Hide file tree
Showing 74 changed files with 2,084 additions and 427 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# exclude Jenkins work files
pkg
work

# exclude Idea files
.idea
*.iml
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source "http://rubygems.org"

# Use this line instead if you want to bundle from a local copy.
#gem "jenkins-plugin-runtime", :path => "#{File.dirname(__FILE__)}/../jenkins-plugin-runtime"
Expand All @@ -10,3 +10,7 @@ gem "sinatra"
group :development do
gem 'jpi', '>= 0.3.8'
end

group :test do
gem 'rspec'
end
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
remote: http://rubygems.org/
specs:
diff-lcs (1.2.4)
jenkins-plugin-runtime (0.2.3)
json
slop (~> 3.0.2)
Expand All @@ -11,10 +12,19 @@ GEM
jenkins-war (> 1.427)
rubyzip
thor
json (1.7.5)
json (1.7.5-java)
rack (1.4.1)
rack-protection (1.2.0)
rack
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.4)
rspec-expectations (2.14.1)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.3)
rubyzip (0.9.9)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
Expand All @@ -30,4 +40,5 @@ PLATFORMS
DEPENDENCIES
jenkins-plugin-runtime (>= 0.2.3)
jpi (>= 0.3.8)
rspec
sinatra
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ The plugin expects the request to have the appropriate structure, like this exam
In case you might wan't to inspect hook triggering (e.g. to check payload data), you can setup logging in Jenkins as [usual](https://wiki.jenkins-ci.org/display/JENKINS/Logging).<br/>
Just add a new logger for **Class** (this is because of JRuby internals).

## Contributing

### Testing

To help with testing, the spec/lib directory contains all the Java dependencies the plugin uses directly.
The spec_helper loads them before each test run.

In case you need to add new classes, please namespace them. See existing ones for details.

Then running JRuby to execute tests, you'll need the following switches:

* --1.9
* -Xcext.enabled=true
* -X+0

## Plan for the future release

#### Automatic branch project creation
Expand Down
2 changes: 1 addition & 1 deletion jenkins-gitlab-hook.pluginspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Jenkins::Plugin::Specification.new do |plugin|
plugin.name = "gitlab-hook"
plugin.display_name = "Gitlab Hook Plugin"
plugin.version = '0.2.12'
plugin.version = '1.0.0'
plugin.description = 'Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects'

plugin.url = 'https://wiki.jenkins-ci.org/display/JENKINS/Gitlab+Hook+Plugin'
Expand Down
63 changes: 63 additions & 0 deletions models/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'sinatra/base'

require_relative 'exceptions/bad_request_exception'
require_relative 'exceptions/configuration_exception'
require_relative 'exceptions/not_found_exception'
require_relative 'use_cases/process_commit'
require_relative 'use_cases/process_delete_commit'
require_relative 'services/parse_request'

include Java

java_import Java.java.util.logging.Logger
java_import Java.java.util.logging.Level

module GitlabWebHook
class Api < Sinatra::Base
LOGGER = Logger.getLogger(Api.class.name)

get '/ping' do
'Gitlab Web Hook is up and running :-)'
end

notify_commit = lambda do
process_projects Proc.new { |project| NotifyCommit.new(project).call }
end
get '/notify_commit', &notify_commit
post '/notify_commit', &notify_commit

build_now = lambda do
process_projects Proc.new { |project, details| BuildNow.new(project).with(details) }
end
get '/build_now', &build_now
post '/build_now', &build_now

private

def process_projects(action)
details = parse_request
messages = details.is_delete_branch_commit? ? ProcessDeleteCommit.new.with(details) : ProcessCommit.new.with(details, action)
LOGGER.info(messages.join("\n"))
messages.join("<br/>")
rescue BadRequestException => e
LOGGER.warning(e.message)
status 400
e.message
rescue NotFoundException => e
LOGGER.warning(e.message)
status 404
e.message
rescue => e
LOGGER.log(Level::SEVERE, e.message, e)
status 500
e.message
end

def parse_request
details = ParseRequest.new.from(params, request)
LOGGER.info("gitlab web hook triggered for repo url #{details.repository_url} and #{details.branch} branch")
LOGGER.info("with payload: #{details.payload}")
details
end
end
end
4 changes: 4 additions & 0 deletions models/exceptions/bad_request_exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module GitlabWebHook
class BadRequestException < StandardError
end
end
4 changes: 4 additions & 0 deletions models/exceptions/configuration_exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module GitlabWebHook
class ConfigurationException < StandardError
end
end
4 changes: 4 additions & 0 deletions models/exceptions/not_found_exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module GitlabWebHook
class NotFoundException < StandardError
end
end
146 changes: 0 additions & 146 deletions models/gitlab_project.rb

This file was deleted.

Loading

0 comments on commit 809bb7b

Please sign in to comment.