Commit f8ad4d2b authored by miks's avatar miks

Merge branch 'master' into deploy_keys

Conflicts:
	app/models/project.rb
parents 723104c4 78d88262
before_install: sudo apt-get install libicu-dev -y
branches: branches:
only: only:
- 'master' - 'master'
......
...@@ -22,7 +22,9 @@ gem "acts_as_list" ...@@ -22,7 +22,9 @@ gem "acts_as_list"
gem "rdiscount" gem "rdiscount"
gem "acts-as-taggable-on", "~> 2.1.0" gem "acts-as-taggable-on", "~> 2.1.0"
gem "drapper" gem "drapper"
gem "rchardet19", "~> 1.3.5" gem "resque"
gem "httparty"
gem "charlock_holmes"
group :assets do group :assets do
gem "sass-rails", "~> 3.1.0" gem "sass-rails", "~> 3.1.0"
...@@ -47,6 +49,7 @@ group :development, :test do ...@@ -47,6 +49,7 @@ group :development, :test do
gem "awesome_print" gem "awesome_print"
gem "database_cleaner" gem "database_cleaner"
gem "launchy" gem "launchy"
gem "webmock"
end end
group :test do group :test do
......
...@@ -77,6 +77,7 @@ GEM ...@@ -77,6 +77,7 @@ GEM
xpath (~> 0.1.4) xpath (~> 0.1.4)
carrierwave (0.5.8) carrierwave (0.5.8)
activesupport (~> 3.0) activesupport (~> 3.0)
charlock_holmes (0.6.8)
childprocess (0.2.2) childprocess (0.2.2)
ffi (~> 1.0.6) ffi (~> 1.0.6)
coffee-rails (3.1.1) coffee-rails (3.1.1)
...@@ -87,6 +88,7 @@ GEM ...@@ -87,6 +88,7 @@ GEM
execjs execjs
coffee-script-source (1.1.3) coffee-script-source (1.1.3)
columnize (0.3.4) columnize (0.3.4)
crack (0.3.1)
daemons (1.1.4) daemons (1.1.4)
database_cleaner (0.7.0) database_cleaner (0.7.0)
devise (1.5.0) devise (1.5.0)
...@@ -111,6 +113,9 @@ GEM ...@@ -111,6 +113,9 @@ GEM
railties (~> 3.0) railties (~> 3.0)
hashery (1.4.0) hashery (1.4.0)
hike (1.2.1) hike (1.2.1)
httparty (0.8.1)
multi_json
multi_xml
i18n (0.6.0) i18n (0.6.0)
jquery-rails (1.0.17) jquery-rails (1.0.17)
railties (~> 3.0) railties (~> 3.0)
...@@ -132,6 +137,7 @@ GEM ...@@ -132,6 +137,7 @@ GEM
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.17.2) mime-types (1.17.2)
multi_json (1.0.3) multi_json (1.0.3)
multi_xml (0.4.1)
nokogiri (1.5.0) nokogiri (1.5.0)
orm_adapter (0.0.5) orm_adapter (0.0.5)
polyglot (0.3.3) polyglot (0.3.3)
...@@ -143,6 +149,8 @@ GEM ...@@ -143,6 +149,8 @@ GEM
rack (>= 0.4) rack (>= 0.4)
rack-mount (0.8.3) rack-mount (0.8.3)
rack (>= 1.0.0) rack (>= 1.0.0)
rack-protection (1.1.4)
rack
rack-ssl (1.3.2) rack-ssl (1.3.2)
rack rack
rack-test (0.6.1) rack-test (0.6.1)
...@@ -165,10 +173,17 @@ GEM ...@@ -165,10 +173,17 @@ GEM
rdoc (~> 3.4) rdoc (~> 3.4)
thor (~> 0.14.6) thor (~> 0.14.6)
rake (0.9.2.2) rake (0.9.2.2)
rchardet19 (1.3.5)
rdiscount (1.6.8) rdiscount (1.6.8)
rdoc (3.11) rdoc (3.11)
json (~> 1.4) json (~> 1.4)
redis (2.2.2)
redis-namespace (1.0.3)
redis (< 3.0.0)
resque (1.19.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rspec (2.7.0) rspec (2.7.0)
rspec-core (~> 2.7.0) rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0) rspec-expectations (~> 2.7.0)
...@@ -220,6 +235,10 @@ GEM ...@@ -220,6 +235,10 @@ GEM
multi_json (~> 1.0.3) multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3) simplecov-html (~> 0.5.3)
simplecov-html (0.5.3) simplecov-html (0.5.3)
sinatra (1.3.1)
rack (~> 1.3, >= 1.3.4)
rack-protection (~> 1.1, >= 1.1.2)
tilt (~> 1.3, >= 1.3.3)
six (0.2.0) six (0.2.0)
sprockets (2.0.3) sprockets (2.0.3)
hike (~> 1.2) hike (~> 1.2)
...@@ -244,8 +263,13 @@ GEM ...@@ -244,8 +263,13 @@ GEM
uglifier (1.1.0) uglifier (1.1.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
vegas (0.1.8)
rack (>= 1.0.0)
warden (1.1.0) warden (1.1.0)
rack (>= 1.0) rack (>= 1.0)
webmock (1.7.8)
addressable (~> 2.2, > 2.2.5)
crack (>= 0.1.7)
xpath (0.1.4) xpath (0.1.4)
nokogiri (~> 1.3) nokogiri (~> 1.3)
...@@ -261,6 +285,7 @@ DEPENDENCIES ...@@ -261,6 +285,7 @@ DEPENDENCIES
awesome_print awesome_print
capybara capybara
carrierwave carrierwave
charlock_holmes
coffee-rails (~> 3.1.0) coffee-rails (~> 3.1.0)
database_cleaner database_cleaner
devise (= 1.5.0) devise (= 1.5.0)
...@@ -270,6 +295,7 @@ DEPENDENCIES ...@@ -270,6 +295,7 @@ DEPENDENCIES
gitolite! gitolite!
grit! grit!
haml-rails haml-rails
httparty
jquery-rails jquery-rails
kaminari kaminari
launchy launchy
...@@ -277,8 +303,8 @@ DEPENDENCIES ...@@ -277,8 +303,8 @@ DEPENDENCIES
pygments.rb (= 0.2.3) pygments.rb (= 0.2.3)
rails (= 3.1.1) rails (= 3.1.1)
rails-footnotes (~> 3.7.5) rails-footnotes (~> 3.7.5)
rchardet19 (~> 1.3.5)
rdiscount rdiscount
resque
rspec-rails rspec-rails
ruby-debug19 ruby-debug19
sass-rails (~> 3.1.0) sass-rails (~> 3.1.0)
...@@ -292,3 +318,4 @@ DEPENDENCIES ...@@ -292,3 +318,4 @@ DEPENDENCIES
thin thin
turn turn
uglifier uglifier
webmock
...@@ -5,9 +5,9 @@ GitLab is a free Project/Repository management application ...@@ -5,9 +5,9 @@ GitLab is a free Project/Repository management application
## Application details ## Application details
rails 3.1 * rails 3.1
works only with gitolite * works only with gitolite
sqlite as default a database * sqlite as default a database
## Requirements ## Requirements
......
...@@ -42,3 +42,11 @@ body.project-page #notes-list .note span.note-author strong{font-weight: bold; f ...@@ -42,3 +42,11 @@ body.project-page #notes-list .note span.note-author strong{font-weight: bold; f
.note .note-title { margin-left:55px; } .note .note-title { margin-left:55px; }
p.notify_controls input{
margin: 5px;
}
p.notify_controls span{
font-weight: 700;
}
...@@ -359,6 +359,9 @@ header nav{border-radius: 4px; box-shadow: 0 1px 2px black; width: 294px; margin ...@@ -359,6 +359,9 @@ header nav{border-radius: 4px; box-shadow: 0 1px 2px black; width: 294px; margin
margin-top: 2px; margin-top: 2px;
height:30px height:30px
} }
header nav.shorter_nav{
width: 207px;
}
header nav a{padding: 8px 12px 8px 34px; display: inline-block; color: #D6DADF; border-right: 1px solid #31363E; position: relative; box-shadow: 1px 0 0 rgba(255,255,255,.1); margin: 0} header nav a{padding: 8px 12px 8px 34px; display: inline-block; color: #D6DADF; border-right: 1px solid #31363E; position: relative; box-shadow: 1px 0 0 rgba(255,255,255,.1); margin: 0}
header nav a span{width: 20px; height: 20px; display: inline-block; background: red; position: absolute; left: 8px; top: 6px;} header nav a span{width: 20px; height: 20px; display: inline-block; background: red; position: absolute; left: 8px; top: 6px;}
header nav a:last-child {border: 0; box-shadow: none} header nav a:last-child {border: 0; box-shadow: none}
...@@ -382,7 +385,7 @@ header nav a.dashboard { ...@@ -382,7 +385,7 @@ header nav a.dashboard {
border-bottom-left-radius: 4px; border-bottom-left-radius: 4px;
} }
header nav a.admin{ header nav a.last_elem{
-webkit-border-top-right-radius: 4px; -webkit-border-top-right-radius: 4px;
-webkit-border-bottom-right-radius: 4px; -webkit-border-bottom-right-radius: 4px;
-moz-border-radius-topright: 4px; -moz-border-radius-topright: 4px;
......
...@@ -23,4 +23,23 @@ module CommitsHelper ...@@ -23,4 +23,23 @@ module CommitsHelper
link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit), link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit),
:remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link" :remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link"
end end
def commit_msg_with_link_to_issues(project, message)
return '' unless message
out = ''
message.split(/(#[0-9]+)/m).each do |m|
if m =~ /(#([0-9]+))/m
begin
issue = project.issues.find($2)
out += link_to($1, project_issue_path(project, $2))
rescue
out += $1
end
else
out += m
end
end
preserve out
end
end end
...@@ -15,6 +15,7 @@ class Project < ActiveRecord::Base ...@@ -15,6 +15,7 @@ class Project < ActiveRecord::Base
has_many :notes, :dependent => :destroy has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy has_many :deploy_keys, :dependent => :destroy
has_many :web_hooks, :dependent => :destroy
acts_as_taggable acts_as_taggable
...@@ -83,12 +84,58 @@ class Project < ActiveRecord::Base ...@@ -83,12 +84,58 @@ class Project < ActiveRecord::Base
:heads, :heads,
:commits_since, :commits_since,
:fresh_commits, :fresh_commits,
:commits_between,
:to => :repository, :prefix => nil :to => :repository, :prefix => nil
def to_param def to_param
code code
end end
def web_url
[GIT_HOST['host'], code].join("/")
end
def execute_web_hooks(oldrev, newrev, ref)
ref_parts = ref.split('/')
# Return if this is not a push to a branch (e.g. new commits)
return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000"
data = web_hook_data(oldrev, newrev, ref)
web_hooks.each { |web_hook| web_hook.execute(data) }
end
def web_hook_data(oldrev, newrev, ref)
data = {
before: oldrev,
after: newrev,
ref: ref,
repository: {
name: name,
url: web_url,
description: description,
homepage: web_url,
private: private?
},
commits: []
}
commits_between(oldrev, newrev).each do |commit|
data[:commits] << {
id: commit.id,
message: commit.safe_message,
timestamp: commit.date.xmlschema,
url: "http://#{GIT_HOST['host']}/#{code}/commits/#{commit.id}",
author: {
name: commit.author_name,
email: commit.author_email
}
}
end
data
end
def team_member_by_name_or_email(email = nil, name = nil) def team_member_by_name_or_email(email = nil, name = nil)
user = users.where("email like ? or name like ?", email, name).first user = users.where("email like ? or name like ?", email, name).first
users_projects.find_by_user_id(user.id) if user users_projects.find_by_user_id(user.id) if user
......
...@@ -31,6 +31,22 @@ class Repository ...@@ -31,6 +31,22 @@ class Repository
project.id project.id
end end
def write_hooks
%w(post-receive).each do |hook|
write_hook(hook, File.read(File.join(Rails.root, 'lib', "#{hook}-hook")))
end
end
def write_hook(name, content)
hook_file = File.join(project.path_to_repo, 'hooks', name)
File.open(hook_file, 'w') do |f|
f.write(content)
end
File.chmod(0775, hook_file)
end
def repo def repo
@repo ||= Grit::Repo.new(project.path_to_repo) @repo ||= Grit::Repo.new(project.path_to_repo)
end end
...@@ -47,6 +63,8 @@ class Repository ...@@ -47,6 +63,8 @@ class Repository
Gitlabhq::GitHost.system.new.configure do |c| Gitlabhq::GitHost.system.new.configure do |c|
c.update_project(path, project) c.update_project(path, project)
end end
write_hooks if File.exists?(project.path_to_repo)
end end
def destroy_repository def destroy_repository
...@@ -115,4 +133,8 @@ class Repository ...@@ -115,4 +133,8 @@ class Repository
repo.commits(ref) repo.commits(ref)
end.map{ |c| Commit.new(c) } end.map{ |c| Commit.new(c) }
end end
def commits_between(from, to)
repo.commits_between(from, to).map { |c| Commit.new(c) }
end
end end
class WebHook < ActiveRecord::Base
include HTTParty
# HTTParty timeout
default_timeout 10
belongs_to :project
validates :url,
presence: true,
format: {
with: URI::regexp(%w(http https)),
message: "should be a valid url" }
def execute(data)
WebHook.post(url, body: data.to_json)
rescue
# There was a problem calling this web hook, let's forget about it.
end
end
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
%hr %hr
%pre.commit_message %pre.commit_message
= preserve @commit.safe_message = commit_msg_with_link_to_issues(@project, @commit.safe_message)
.clear .clear
%br %br
......
...@@ -21,16 +21,18 @@ ...@@ -21,16 +21,18 @@
<%= text_field_tag "search", nil, :placeholder => "Search", :class => "search-input" %> <%= text_field_tag "search", nil, :placeholder => "Search", :class => "search-input" %>
</div> </div>
<!-- .login-top --> <!-- .login-top -->
<nav> <nav class="<%= 'shorter_nav' unless current_user.is_admin? %>">
<%= link_to dashboard_path, :class => current_page?(root_path) ? "current dashboard" : "dashboard" do %> <%= link_to dashboard_path, :class => "#{'current' if current_page?(root_path)} dashboard" do %>
<span></span>Dashboard <span></span>Dashboard
<% end %> <% end %>
<%= link_to projects_path, :class => current_page?(projects_path) ? "current project" : "project" do %> <%= link_to projects_path, :class =>"#{'current' if current_page?(projects_path)} project #{'last_elem' unless current_user.is_admin?}" do %>
<span></span>Projects <span></span>Projects
<% end %> <% end %>
<%= link_to((current_user.is_admin? ? admin_root_path : "#"), :class => (admin_namespace? ? "current admin" : "admin")) do %> <% if current_user.is_admin? %>
<%= link_to((current_user.is_admin? ? admin_root_path : "#"), :class => "#{'current' if admin_namespace?} admin last_elem") do %>
<span></span>Admin <span></span>Admin
<% end %> <% end %>
<% end %>
</nav> </nav>
</header> </header>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
%head %head
%title %title
GitLab #{" - #{@project.name}" if @project && !@project.new_record?} GitLab #{" - #{@project.name}" if @project && !@project.new_record?}
= favicon_link_tag 'favicon.ico'
= stylesheet_link_tag "application" = stylesheet_link_tag "application"
= javascript_include_tag "application" = javascript_include_tag "application"
= csrf_meta_tags = csrf_meta_tags
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
%head %head
%title %title
GitLab #{" - #{@project.name}" if @project && !@project.new_record?} GitLab #{" - #{@project.name}" if @project && !@project.new_record?}
= favicon_link_tag 'favicon.ico'
= stylesheet_link_tag "application" = stylesheet_link_tag "application"
= javascript_include_tag "application" = javascript_include_tag "application"
= csrf_meta_tags = csrf_meta_tags
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
%head %head
%title %title
GitLab #{" - #{@project.name}" if @project && !@project.new_record?} GitLab #{" - #{@project.name}" if @project && !@project.new_record?}
= favicon_link_tag 'favicon.ico'
= stylesheet_link_tag "application" = stylesheet_link_tag "application"
= javascript_include_tag "application" = javascript_include_tag "application"
= csrf_meta_tags = csrf_meta_tags
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
%head %head
%title %title
GitLab #{" - #{@project.name}" if @project && !@project.new_record?} GitLab #{" - #{@project.name}" if @project && !@project.new_record?}
= favicon_link_tag 'favicon.ico'
= stylesheet_link_tag "application" = stylesheet_link_tag "application"
= javascript_include_tag "application" = javascript_include_tag "application"
- if current_page?(tree_project_ref_path(@project, @project.root_ref)) || current_page?(project_commits_path(@project)) - if current_page?(tree_project_ref_path(@project, @project.root_ref)) || current_page?(project_commits_path(@project))
......
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
%br %br
= f.file_field :attachment = f.file_field :attachment
%p.notify_controls
%span Notify:
= check_box_tag :notify, 1, @note.noteable_type != "Commit" = check_box_tag :notify, 1, @note.noteable_type != "Commit"
= label_tag :notify, "Notify project team about your note" = label_tag :notify, "Project team"
-if @note.noteable_type == "Commit" -if @note.noteable_type == "Commit"
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
= label_tag :notify_author, "Notify commit author about your note" = label_tag :notify_author, "Commit author"
.clear .clear
%br %br
......
class PostReceive
def self.perform(reponame, oldrev, newrev, ref)
project = Project.find_by_path(reponame)
return false if project.nil?
project.execute_web_hooks(oldrev, newrev, ref)
end
end
Gitlab::Application.routes.draw do Gitlab::Application.routes.draw do
# Optionally, enable Resque here
# require 'resque/server'
# mount Resque::Server.new, at: '/info/resque'
get 'tags'=> 'tags#index' get 'tags'=> 'tags#index'
get 'tags/:tag' => 'projects#index' get 'tags/:tag' => 'projects#index'
......
class CreateWebHooks < ActiveRecord::Migration
def change
create_table :web_hooks do |t|
t.string :url
t.integer :project_id
t.timestamps
end
end
end
...@@ -13,18 +13,6 @@ ...@@ -13,18 +13,6 @@
ActiveRecord::Schema.define(:version => 20111220190817) do ActiveRecord::Schema.define(:version => 20111220190817) do
create_table "features", :force => true do |t|
t.string "name"
t.string "branch_name"
t.integer "assignee_id"
t.integer "author_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "version"
t.integer "status", :default => 0, :null => false
end
create_table "issues", :force => true do |t| create_table "issues", :force => true do |t|
t.string "title" t.string "title"
t.integer "assignee_id" t.integer "assignee_id"
...@@ -145,4 +133,11 @@ ActiveRecord::Schema.define(:version => 20111220190817) do ...@@ -145,4 +133,11 @@ ActiveRecord::Schema.define(:version => 20111220190817) do
t.integer "project_access", :default => 0, :null => false t.integer "project_access", :default => 0, :null => false
end end
create_table "web_hooks", :force => true do |t|
t.string "url"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end end
#!/bin/bash
# This file was placed here by Gitlab. It makes sure that your pushed commits
# will be processed properly.
while read oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
pwd=`pwd`
reponame=`basename "$pwd" | cut -d. -f1`
env -i redis-cli rpush "resque:queue:post-receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1
done
require 'resque/tasks'
...@@ -17,15 +17,13 @@ module Utils ...@@ -17,15 +17,13 @@ module Utils
end end
module CharEncode module CharEncode
def encode(string) def encode(content)
return '' unless string content ||= ''
cd = CharDet.detect(string) detection = CharlockHolmes::EncodingDetector.detect(content)
if cd.confidence > 0.6 if hash = detection
string.force_encoding(cd.encoding) content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
end end
string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace) content
rescue
"Invalid Encoding"
end end
end end
......
No preview for this file type
...@@ -55,3 +55,7 @@ Factory.add(:key, Key) do |obj| ...@@ -55,3 +55,7 @@ Factory.add(:key, Key) do |obj|
obj.title = "Example key" obj.title = "Example key"
obj.key = File.read(File.join(Rails.root, "db", "pkey.example")) obj.key = File.read(File.join(Rails.root, "db", "pkey.example"))
end end
Factory.add(:web_hook, WebHook) do |obj|
obj.url = Faker::Internet.url
end
require "spec_helper"
include Haml::Helpers
describe CommitsHelper do
before do
@project = Factory :project
@other_project = Factory :project, :path => "OtherPath", :code => "OtherCode"
@fake_user = Factory :user
@valid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project
@invalid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @other_project
end
it "should provides return message untouched if no issue number present" do
message = "Dummy message without issue number"
commit_msg_with_link_to_issues(@project, message).should eql message
end
it "should returns message handled by preserve" do
message = "My brand new
Commit on multiple
lines !"
#\n are converted to &#x000A as specified in preserve_rspec
expected = "My brand new&#x000A; Commit on multiple&#x000A; lines !"
commit_msg_with_link_to_issues(@project, message).should eql expected
end
it "should returns empty string if message undefined" do
commit_msg_with_link_to_issues(@project, nil).should eql ''
end
it "should returns link_to issue for one valid issue in message" do
issue_id = @valid_issue.id
message = "One commit message ##{issue_id}"
expected = "One commit message <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"
commit_msg_with_link_to_issues(@project, message).should eql expected
end
it "should returns message untouched for one invalid issue in message" do
issue_id = @invalid_issue.id
message = "One commit message ##{issue_id}"
commit_msg_with_link_to_issues(@project, message).should eql message
end
it "should handle multiple issue references in commit message" do
issue_id = @valid_issue.id
invalid_issue_id = @invalid_issue.id
message = "One big commit message with a valid issue ##{issue_id} and an invalid one ##{invalid_issue_id}.
We reference valid ##{issue_id} multiple times (##{issue_id}) as the invalid ##{invalid_issue_id} is also
referenced another time (##{invalid_issue_id})"
expected = "One big commit message with a valid issue <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"+
" and an invalid one ##{invalid_issue_id}.&#x000A; "+
"We reference valid <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a> multiple times "+
"(<a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>) "+
"as the invalid ##{invalid_issue_id} is also&#x000A; referenced another time (##{invalid_issue_id})"
commit_msg_with_link_to_issues(@project, message).should eql expected
end
end
\ No newline at end of file
...@@ -7,6 +7,7 @@ describe Project do ...@@ -7,6 +7,7 @@ describe Project do
it { should have_many(:issues) } it { should have_many(:issues) }
it { should have_many(:notes) } it { should have_many(:notes) }
it { should have_many(:snippets) } it { should have_many(:snippets) }
it { should have_many(:web_hooks).dependent(:destroy) }
end end
describe "Validation" do describe "Validation" do
...@@ -33,6 +34,7 @@ describe Project do ...@@ -33,6 +34,7 @@ describe Project do
it { should respond_to(:repo) } it { should respond_to(:repo) }
it { should respond_to(:tags) } it { should respond_to(:tags) }
it { should respond_to(:commit) } it { should respond_to(:commit) }
it { should respond_to(:commits_between) }
end end
it "should not allow 'gitolite-admin' as repo name" do it "should not allow 'gitolite-admin' as repo name" do
...@@ -50,6 +52,11 @@ describe Project do ...@@ -50,6 +52,11 @@ describe Project do
project.path_to_repo.should == File.join(Rails.root, "tmp", "tests", "somewhere") project.path_to_repo.should == File.join(Rails.root, "tmp", "tests", "somewhere")
end end
it "returns the full web URL for this repo" do
project = Project.new(:code => "somewhere")
project.web_url.should == "#{GIT_HOST['host']}/somewhere"
end
describe :valid_repo? do describe :valid_repo? do
it "should be valid repo" do it "should be valid repo" do
project = Factory :project project = Factory :project
...@@ -62,6 +69,106 @@ describe Project do ...@@ -62,6 +69,106 @@ describe Project do
end end
end end
describe "web hooks" do
let(:project) { Factory :project }
context "with no web hooks" do
it "raises no errors" do
lambda {
project.execute_web_hooks('oldrev', 'newrev', 'ref')
}.should_not raise_error
end
end
context "with web hooks" do
before do
@webhook = Factory(:web_hook)
@webhook_2 = Factory(:web_hook)
project.web_hooks << [@webhook, @webhook_2]
end
it "executes multiple web hook" do
@webhook.should_receive(:execute).once
@webhook_2.should_receive(:execute).once
project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master')
end
end
context "does not execute web hooks" do
before do
@webhook = Factory(:web_hook)
project.web_hooks << [@webhook]
end
it "when pushing a branch for the first time" do
@webhook.should_not_receive(:execute)
project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master')
end
it "when pushing tags" do
@webhook.should_not_receive(:execute)
project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0')
end
end
context "when pushing new branches" do
end
context "when gathering commit data" do
before do
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
@commit = project.fresh_commits(2).first
# Fill nil/empty attributes
project.description = "This is a description"
@data = project.web_hook_data(@oldrev, @newrev, @ref)
end
subject { @data }
it { should include(before: @oldrev) }
it { should include(after: @newrev) }
it { should include(ref: @ref) }
context "with repository data" do
subject { @data[:repository] }
it { should include(name: project.name) }
it { should include(url: project.web_url) }
it { should include(description: project.description) }
it { should include(homepage: project.web_url) }
it { should include(private: project.private?) }
end
context "with commits" do
subject { @data[:commits] }
it { should be_an(Array) }
it { should have(1).element }
context "the commit" do
subject { @data[:commits].first }
it { should include(id: @commit.id) }
it { should include(message: @commit.safe_message) }
it { should include(timestamp: @commit.date.xmlschema) }
it { should include(url: "http://localhost/#{project.code}/commits/#{@commit.id}") }
context "with a author" do
subject { @data[:commits].first[:author] }
it { should include(name: @commit.author_name) }
it { should include(email: @commit.author_email) }
end
end
end
end
end
describe "updates" do describe "updates" do
let(:project) { Factory :project } let(:project) { Factory :project }
...@@ -107,6 +214,21 @@ describe Project do ...@@ -107,6 +214,21 @@ describe Project do
it { project.fresh_commits.last.id.should == "0dac878dbfe0b9c6104a87d65fe999149a8d862c" } it { project.fresh_commits.last.id.should == "0dac878dbfe0b9c6104a87d65fe999149a8d862c" }
end end
describe "commits_between" do
let(:project) { Factory :project }
subject do
commits = project.commits_between("a6d1d4aca0c85816ddfd27d93773f43a31395033",
"2fb376f61875b58bceee0492e270e9c805294b1a")
commits.map { |c| c.id }
end
it { should have(2).elements }
it { should include("2fb376f61875b58bceee0492e270e9c805294b1a") }
it { should include("4571e226fbcd7be1af16e9fa1e13b7ac003bebdf") }
it { should_not include("a6d1d4aca0c85816ddfd27d93773f43a31395033") }
end
describe "Git methods" do describe "Git methods" do
let(:project) { Factory :project } let(:project) { Factory :project }
......
require 'spec_helper'
describe WebHook do
describe "Associations" do
it { should belong_to :project }
end
describe "Validations" do
it { should validate_presence_of(:url) }
context "url format" do
it { should allow_value("http://example.com").for(:url) }
it { should allow_value("https://excample.com").for(:url) }
it { should allow_value("http://test.com/api").for(:url) }
it { should allow_value("http://test.com/api?key=abc").for(:url) }
it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) }
it { should_not allow_value("example.com").for(:url) }
it { should_not allow_value("ftp://example.com").for(:url) }
it { should_not allow_value("herp-and-derp").for(:url) }
end
end
describe "execute" do
before(:each) do
@webhook = Factory :web_hook
@project = Factory :project
@project.web_hooks << [@webhook]
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
WebMock.stub_request(:post, @webhook.url)
end
it "POSTs to the web hook URL" do
@webhook.execute(@data)
WebMock.should have_requested(:post, @webhook.url).once
end
it "POSTs the data as JSON" do
json = @data.to_json
@webhook.execute(@data)
WebMock.should have_requested(:post, @webhook.url).with(body: json).once
end
it "catches exceptions" do
WebHook.should_receive(:post).and_raise("Some HTTP Post error")
lambda {
@webhook.execute(@data)
}.should_not raise_error
end
end
end
require 'spec_helper' require 'spec_helper'
describe "Dashboard" do describe "Dashboard" do
before { login_as :user }
describe "GET /dashboard" do
before do before do
@project = Factory :project @project = Factory :project
@user = User.create(:email => "test917@mail.com",
:name => "John Smith",
:password => "123456",
:password_confirmation => "123456")
@project.add_access(@user, :read, :write) @project.add_access(@user, :read, :write)
login_with(@user)
end
describe "GET /dashboard" do
before do
visit dashboard_path visit dashboard_path
end end
...@@ -20,12 +26,14 @@ describe "Dashboard" do ...@@ -20,12 +26,14 @@ describe "Dashboard" do
end end
end end
it "should have news feed" do # Temporary disabled cause of travis
within "#news-feed" do # TODO: fix or rewrite
page.should have_content("commit") #it "should have news feed" do
page.should have_content(@project.commit.author.name) #within "#news-feed" do
page.should have_content(@project.commit.safe_message) #page.should have_content("commit")
end #page.should have_content(@project.commit.author.name)
end #page.should have_content(@project.commit.safe_message)
#end
#end
end end
end end
require 'spec_helper' #require 'spec_helper'
require 'benchmark' #require 'benchmark'
#
describe "Projects" do #describe "Projects" do
before { login_as :user } # before { login_as :user }
#
describe "GET /projects/tree" do # describe "GET /projects/tree" do
describe "head" do # describe "head" do
before do # before do
@project = Factory :project # @project = Factory :project
@project.add_access(@user, :read) # @project.add_access(@user, :read)
# end
end #
# it "should be fast" do
it "should be fast" do # time = Benchmark.realtime do
time = Benchmark.realtime do # visit tree_project_ref_path(@project, @project.root_ref)
visit tree_project_ref_path(@project, @project.root_ref) # end
end # (time < 1.0).should be_true
(time < 1.0).should be_true # end
end # end
end #
# describe ValidCommit::ID do
describe ValidCommit::ID do # before do
before do # @project = Factory :project
@project = Factory :project # @project.add_access(@user, :read)
@project.add_access(@user, :read) # end
end #
# it "should be fast" do
it "should be fast" do # time = Benchmark.realtime do
time = Benchmark.realtime do # visit tree_project_ref_path(@project, ValidCommit::ID)
visit tree_project_ref_path(@project, ValidCommit::ID) # end
end # (time < 1.0).should be_true
(time < 1.0).should be_true # end
end # end
end # end
end #end
end
...@@ -8,6 +8,7 @@ require 'rspec/rails' ...@@ -8,6 +8,7 @@ require 'rspec/rails'
require 'capybara/rails' require 'capybara/rails'
require 'capybara/rspec' require 'capybara/rspec'
require 'capybara/dsl' require 'capybara/dsl'
require 'webmock/rspec'
require 'factories' require 'factories'
require 'monkeypatch' require 'monkeypatch'
...@@ -48,6 +49,8 @@ RSpec.configure do |config| ...@@ -48,6 +49,8 @@ RSpec.configure do |config|
end end
DatabaseCleaner.start DatabaseCleaner.start
WebMock.disable_net_connect!(allow_localhost: true)
end end
config.after do config.after do
......
require 'spec_helper'
describe PostReceive do
context "as a resque worker" do
it "reponds to #perform" do
PostReceive.should respond_to(:perform)
end
end
context "web hooks" do
let(:project) { Factory :project }
it "it retrieves the correct project" do
Project.should_receive(:find_by_path).with(project.path)
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master')
end
it "asks the project to execute web hooks" do
Project.stub(find_by_path: project)
project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master')
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment