Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernized code for ruby 1.9.3 and delayed jobs support #180

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.*.swp
.AppleDouble
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source :rubygems
gem "inifile", "~>0.4.1"
gem "lockfile", "~>1.4.3"
gem "net-ssh", "~>2.1.4"
source 'https://rubygems.org'
gem 'inifile', '~>0.4.1'
gem 'lockfile', '~>1.4.3'
gem 'net-ssh', '~>2.1.4'
gem 'delayed_job', '=2.0.4'

5 changes: 5 additions & 0 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Redmine Git Hosting Plugin with Delayed Jobs (v0.5.0)

Added support for delayed_jobs ACL update and improved visualization of access rights.
-- Tomas Srna

# Redmine Git Hosting Plugin (v0.4.2)

A ChiliProject / Redmine plugin which makes configuring your own git hosting easy. This plugin allows straightforward management
Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ begin
require 'lockfile'
require 'net/ssh'
rescue
puts "need to install tmpdir lockfile and net/ssh gems"
puts 'need to install tmpdir lockfile and net/ssh gems'
end

begin
gem 'delayed_job', '~>2.0.4'
require 'delayed/tasks'
rescue LoadError
STDERR.puts 'Run `rake gems:install` to install delayed_job'
end
3 changes: 1 addition & 2 deletions app/controllers/git_http_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class GitHttpController < ApplicationController

before_filter :authenticate


def index
p1 = params[:p1]
p2 = params[:p2]
Expand Down Expand Up @@ -241,7 +240,7 @@ def update_server_info
end

def git_command(command)
return "#{run_git_prefix()} env GL_BYPASS_UPDATE_HOOK=true git #{command} '"
return "#{run_git_prefix()} GL_BYPASS_UPDATE_HOOK=true GL_LIBDIR=\"/etc/perl\" git #{command} '"
end


Expand Down
42 changes: 0 additions & 42 deletions app/controllers/gitolite_hooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,6 @@ def post_receive
output.write(result)
output.flush
} if @project.repository_mirrors.any?

# Notify CIA
#Thread.abort_on_exception = true
Thread.new(@project, params[:refs]) {|project, refs|
GitHosting.logger.debug "Notifying CIA"
output.write("Notifying CIA\n")
output.flush
#GitHosting.logger.debug "REFS #{refs}"

refs.each {|ref|
oldhead, newhead, refname = ref.split(',')

# Only pay attention to branch updates
next if not refname.match(/refs\/heads\//)

branch = refname.gsub('refs/heads/', '')

if newhead.match(/^0{40}$/)
# Deleting a branch
GitHosting.logger.debug "Deleting branch \"#{branch}\""
next
elsif oldhead.match(/^0{40}$/)
# Creating a branch
GitHosting.logger.debug "Creating branch \"#{branch}\""
range = newhead
else
range = "#{oldhead}..#{newhead}"
end

revisions = %x[#{GitHosting.git_exec} --git-dir='#{GitHosting.repository_path(@project)}' rev-list --reverse #{range}]
#GitHosting.logger.debug "Revisions in Range: #{revisions.split().join(' ')}"

revisions.split().each{|rev|
revision = project.repository.find_changeset_by_name(rev.strip)
#GitHosting.logger.debug "Revision Found: #{revision.revision}"
next if project.repository.cia_notifications.notified?(revision) # Already notified about this commit
GitHosting.logger.info "Notifying CIA: Branch => #{branch} REVISION => #{revision.revision}"
CiaNotificationMailer.deliver_notification(revision, branch)
project.repository.cia_notifications.notified(revision)
}
}
} if !params[:refs].nil? && @project.repository.extra.notify_cia==1
}, :layout => false
end

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/gitolite_public_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def create
if @gitolite_public_key.save
flash[:notice] = l(:notice_public_key_added)
else
@gitolite_public_key = GitolitePublicKey.new(:user => @user)
#@gitolite_public_key = GitolitePublicKey.new(:user => @user)
@gitolite_public_key.errors.each do |attr, message|
flash[:error] = "<strong>#{attr}:</strong> #{message}" if flash[:error].blank?
end
end
redirect_to url_for(:controller => 'my', :action => 'account')
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/cia_notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def deliver!(mail = @mail)

begin
ok, result = rpc_server.call2("hub.deliver", @body)
if ok:
if ok
GitHosting.logger.info "RPC Called. OK => #{ok} Result => #{result}"
return false
end
Expand Down
34 changes: 27 additions & 7 deletions app/models/git_hosting_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def before_save(object)


def after_save(object)
GitHosting.logger.debug "On GitHostingObserver.after_save for #{object.class} #{object.id}"
update_repositories(object)
end

Expand All @@ -63,22 +64,41 @@ def after_destroy(object)
protected


def update_repositories(object)

def update_repositories(object)
projects = []
case object
when Repository::Git then projects.push(object.project)
when User then projects = object.projects unless is_login_save?(object)
when GitolitePublicKey then projects = object.user.projects
when Member then projects.push(object.project)
when Role then projects = object.members.map(&:project).flatten.uniq.compact
when Role then projects = object.members.map(&:project).flatten.uniq.compact
when Project then projects.push(object)
end

projects.select! do |p|
p if (!p.repository.nil? && p.repository.is_a?(Repository::Git) &&
!p.repository.update_requested.nil? && !p.repository.update_finished.nil? &&
p.repository.update_requested < p.repository.update_finished)
end

if(projects.length > 0)
if (@@updating_active)
GitHosting::update_repositories(projects, false)
else
@@cached_project_updates.concat(projects)
end
#GitHosting::update_repositories(projects, false)
project_pids = projects.collect {|p| p.id}
projects.each do |p|
unless p.repository.nil?
p.repository.update_requested = Time.new
ua = @@updating_active
@@updating_active = false
p.repository.save
@@updating_active = ua
end
end
GitHosting.logger.debug 'Calling delayed update_repositories_pid'
GitHosting.delay.update_repositories_pid(project_pids, false)
else
@@cached_project_updates.concat(projects)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/git_hosting_settings_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def after_save(object)
all_projects.each do |p|
if p.repository.is_a?(Repository::Git)
r = p.repository
repo_name= p.parent ? File.join(GitHosting::get_full_parent_path(p, true),p.identifier) : p.identifier
repo_name = p.identifier
r.url = File.join(object.value['gitRepositoryBasePath'], "#{repo_name}.git")
r.root_url = r.url
r.save
Expand Down
15 changes: 15 additions & 0 deletions app/models/gitolite_public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GitolitePublicKey < ActiveRecord::Base
named_scope :inactive, {:conditions => {:active => GitolitePublicKey::STATUS_LOCKED}}

validate :has_not_been_changed
validate :fingerprintable_key

before_validation :set_identifier

Expand All @@ -31,5 +32,19 @@ def set_identifier
self.identifier ||= "redmine_#{self.user.login.underscore}_#{Time.now.to_i.to_s}_#{Time.now.usec.to_s}".gsub(/[^0-9a-zA-Z\-]/,'_')
end

def fingerprintable_key
return true unless key # Don't test if there is no key.
file = Tempfile.new('key_file')
begin
file.puts key
file.rewind
fingerprint_output = `ssh-keygen -lf #{file.path} 2>&1` # Catch stderr.
ensure
file.close
file.unlink # deletes the temp file
end
errors.add(:key, "can't be fingerprinted - not a public key") if fingerprint_output.match("is not a public key file")
end

def to_s ; title ; end
end
5 changes: 2 additions & 3 deletions app/views/my/account.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@
<table class="list">
<tr>
<% if @gitolite_public_keys.any? %>
<th style="text-align:left;" ><h4><%=l(:label_public_keys)%></h4></th>
<th style="text-align:left;" colspan="2" ><strong><%=l(:label_public_keys)%></strong></th>
<% else %>
<th style="text-align:left;" ><h4><%=l(:label_no_public_keys)%></h4></th>
<th style="text-align:left;" colspan="2" ><strong><%=l(:label_no_public_keys)%></strong></th>
<% end %>
<th style="width:10%;"></th>
</tr>
<% @gitolite_public_keys.each do |key| %>
<tr class="<%= cycle('odd', 'even') %>">
Expand Down
97 changes: 54 additions & 43 deletions app/views/projects/_git_urls.erb
Original file line number Diff line number Diff line change
@@ -1,53 +1,64 @@
<% if @project.repository && @project.repository.is_a?(Repository::Git) %>
<% content_for :header_tags do %>

<%= stylesheet_link_tag('git_url_display', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('git_url_display', :plugin => 'redmine_git_hosting') %>
<%= stylesheet_link_tag('zero_clipboard', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('ZeroClipboard', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('zero_clipboard_setup', :plugin => 'redmine_git_hosting') %>


<script type="text/javascript">

guProjectName= "<%= (@project.parent ? GitHosting::get_full_parent_path(@project, false) + "/" : "" ) %>" + "<%= @project.repository.url %>".replace(/^.*\//, "")
guProjectIsPublic= <%= project.is_public.to_s %> ;
guUser= "<%= User.current.login %>"
guUserIsCommitter= <%= User.current.allowed_to?(:commit_access, project) ? "true" : "false" %> ;
guGitUser="<%= Setting.plugin_redmine_git_hosting['gitUser'] %>"
guGitServer="<%= Setting.plugin_redmine_git_hosting['gitServer'] %>"
guHttpBase="<%= Setting.plugin_redmine_git_hosting['httpServer'] %>".replace(/\/$/, "")
guHttpProto="<%= project.repository.extra[:git_http].to_s == "2" ? "http" : "https" %>"

window.onload = setGitUrlOnload

ZeroClipboard.setMoviePath('<%= image_path('ZeroClipboard.swf', :plugin => 'redmine_git_hosting') %>');
setZeroClipboardInputSource("git_url_text");
</script>
<%= stylesheet_link_tag('git_url_display', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('git_url_display', :plugin => 'redmine_git_hosting') %>

<%= stylesheet_link_tag('zero_clipboard', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('ZeroClipboard', :plugin => 'redmine_git_hosting') %>
<%= javascript_include_tag('zero_clipboard_setup', :plugin => 'redmine_git_hosting') %>


<script type="text/javascript">

guProjectName = "<%= @project.repository.url %>".replace(/^.*\//, "")
guProjectIsPublic= <%= project.is_public.to_s %> ;
guUser= "<%= User.current.login %>"
guUserIsCommitter= <%= User.current.allowed_to?(:commit_access, project) ? "true" : "false" %> ;
guGitUser="<%= Setting.plugin_redmine_git_hosting['gitUser'] %>"
guGitServer="<%= Setting.plugin_redmine_git_hosting['gitServer'] %>"
guHttpBase="<%= Setting.plugin_redmine_git_hosting['httpServer'] %>".replace(/\/$/, "")
guHttpProto="<%= project.repository.extra[:git_http].to_s == "2" ? "http" : "https" %>"

window.onload = setGitUrlOnload

ZeroClipboard.setMoviePath('<%= image_path('ZeroClipboard.swf', :plugin => 'redmine_git_hosting') %>');
setZeroClipboardInputSource("git_url_text");
</script>
<% end %>

<% if (project.module_enabled?(:repository) && Setting.plugin_redmine_git_hosting['gitRepositoriesShowUrl'].to_s != "false" ) && ((!User.current.anonymous?) || project.repository.extra[:git_http].to_s != "0" || (project.is_public && project.repository.extra[:git_daemon].to_s != "0" )) %>
<div class="box">
<div class="box" style="min-height: 100px;">
<h3>Git Repository</h3>
<div id="git_url_box">
<ul id="git_url_list" >
<% if !User.current.anonymous? %>
<li><a id="git_url_ssh" href="javascript:void(0)">SSH</a></li>
<% end %>
<% if project.repository.extra[:git_http].to_s != "0" %>
<li><a id="git_url_http" href="javascript:void(0)">HTTP</a></li>
<% end %>
<% if project.is_public && project.repository.extra[:git_daemon].to_s != "0" %>
<li><a id="git_url_git" href="javascript:void(0)">Git</a></li>
<% end %>
</ul>
<input id="git_url_text" name="git_url_text" readonly="readonly" value="" />
<div id="clipboard_container" title="<%= l(:label_copy_to_clipboard) %>" style="display: none;">
<div id="clipboard_button"><%= image_tag 'paste.png', :plugin => 'redmine_git_hosting' %></div>
</div>
<span id="git_url_desc">This URL has <span id="git_url_access">Read-Only</span> access.</span>
</div>
<%
pc = 0
User.current.gitolite_public_keys.each { |p| pc = pc+1 if p.active == true }
flash.now[:warning] = l(:no_public_key) if pc < 1


if !@project.repository.blank? && !@project.repository.update_requested.blank? &&
(@project.repository.update_finished.blank? ||
@project.repository.update_requested > @project.repository.update_finished)
flash.now[:warning] = l(:update_pending) + @project.repository.update_requested.to_s
end
%>
<div id="git_url_box">
<ul id="git_url_list" >
<% if !User.current.anonymous? && project.members.find_by_user_id(User.current.id) != nil %>
<li><a id="git_url_ssh" href="javascript:void(0)">SSH</a></li>
<% end %>
<% if project.is_public %>
<li><a id="git_url_http" href="javascript:void(0)"><%=l(:http_anon)%></a></li>
<% else %>
<li><a id="git_url_http" href="javascript:void(0)"><%=l(:http_auth)%></a></li>
<% end %>
</ul>
<input id="git_url_text" name="git_url_text" readonly="readonly" value="" />
<div id="clipboard_container" title="<%= l(:label_copy_to_clipboard) %>" style="display: none;">
<div id="clipboard_button"><%= image_tag 'paste.png', :plugin => 'redmine_git_hosting' %></div>
</div>
<span id="git_url_desc"><%= l(:this_url_has) %> <span id="git_url_access">Read-Only</span> <%= l(:access) %>.</span>
</div>
</div>
<% end %>
<% end %>
17 changes: 3 additions & 14 deletions app/views/projects/settings/_repository.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,12 @@
end
end
%>
<p>
<%= label_tag "extra[git_daemon]", l(:field_git_daemon) %>
<%= select_tag "extra[git_daemon]", options_for_select([ [l(:label_disabled), "0"], [l(:label_enabled), "1"]], :selected=>extra_vals[:git_daemon]) %>
</p>
<p>
<%= label_tag "extra[git_http]", l(:field_git_http) %>
<%= select_tag "extra[git_http]", options_for_select([ [l(:label_disabled), "0"], [l(:label_https_only), "1"], [l(:label_https_and_http), "2"] ], :selected=>extra_vals[:git_http]) %>
</p>
<p>
<%= label_tag "extra[notify_cia]", l(:field_notify_cia) %>
<%= select_tag "extra[notify_cia]", options_for_select([ [l(:label_disabled), "0"], [l(:label_enabled), "1"]], :selected=>extra_vals[:notify_cia]) %>
<% if extra_vals[:notify_cia] == "1" %>
<a id="notify_cia_test" href="<%= url_for(:controller => "gitolite_hooks", :action => "test", :projectid => @repository.project.identifier) %>"><%= l(:field_notify_cia_test) %></a>
<em><b><span id="notify_cia_result"></span></b></em>
<% end %>
<%= select_tag "extra[git_http]", options_for_select([ [l(:label_disabled), "0"], [l(:label_https_only), "1"]
#, [l(:label_https_and_http), "2"]
], :selected=>extra_vals[:git_http]) %>
</p>
<%= javascript_include_tag('notify_cia_test', :plugin => 'redmine_git_hosting') %>
<br/>
<% else %>
<%= repository_field_tags(f, @repository) if @repository %>
Expand Down
Loading