Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

1. work with gitolite

2. support subproject repository (e.g. git@site.name:parent_project/subproject.git)

3. bugfix
  • Loading branch information...
commit d319b868b2779bc9df10688368a14f138a12a3e5 1 parent 409a98a
Yunsang Choe authored January 29, 2011
5  README.rdoc 100644 → 100755
Source Rendered
... ...
@@ -1,3 +1,8 @@
  1
+= Patches
  2
+* work with gitolite
  3
+* support subproject git repo. (e.g. git@site.name:parent_project/subproject.git)
  4
+* fix bugs.
  5
+
1 6
 = Redmine Gitolite
2 7
 
3 8
 A Redmine plugin which manages your gitolite configuration based on your projects and memberships in Redmine. Includes Public Key management views (extracted from http://plan.io).
4  app/models/gitolite_public_key.rb 100644 → 100755
... ...
@@ -1,6 +1,6 @@
1 1
 class GitolitePublicKey < ActiveRecord::Base
2  
-  STATUS_ACTIVE = true
3  
-  STATUS_LOCKED = false
  2
+  STATUS_ACTIVE = 1
  3
+  STATUS_LOCKED = 0
4 4
 
5 5
   belongs_to :user
6 6
   validates_uniqueness_of :title, :scope => :user_id
4  app/views/projects/_redmine_gitolite.rhtml
@@ -5,13 +5,13 @@
5 5
 	<p>
6 6
 		<strong>Developer URL</strong>
7 7
 		<ul>
8  
-			<% repo_urls[:developer].each do |url| do %>
  8
+			<% repo_urls[:developer].each do |url|  %>
9 9
 			<li> <%=url%>
10 10
 			<% end%>
11 11
 		</ul>
12 12
 		<strong>Read-Only URL</strong>
13 13
 		<ul>
14  
-			<% repo_urls[:read_only].each do |url| do %>
  14
+			<% repo_urls[:read_only].each do |url|  %>
15 15
 			<li> <%=url%>
16 16
 			<% end%>
17 17
 		</ul>
4  app/views/repositories/git_instructions.html.erb 100644 → 100755
@@ -18,13 +18,13 @@
18 18
   git init
19 19
   git add .
20 20
   git commit -m 'Initializing <%= @project %> repository'
21  
-  git remote add origin <%= Setting.plugin_redmine_gitolite['developerBaseUrls'] + @project.identifier + '.git' %>
  21
+  git remote add origin <%= Setting.plugin_redmine_gitolite['developerBaseUrls'] + Gitolite.repository_name(@project) + '.git' %>
22 22
   git push origin master
23 23
 </pre>
24 24
 
25 25
 <h2>Existing Git Repo?</h2>
26 26
 <pre>  cd existing_git_repo
27  
-  git remote add origin <%= Setting.plugin_redmine_gitolite['developerBaseUrls'] + @project.identifier + '.git' %>
  27
+  git remote add origin <%= Setting.plugin_redmine_gitolite['developerBaseUrls'] + Gitolite.repository_name(@project) + '.git' %>
28 28
   git push origin master
29 29
 </pre>    
30 30
   
4  init.rb 100644 → 100755
@@ -9,9 +9,9 @@
9 9
 
10 10
 Redmine::Plugin.register :redmine_gitolite do
11 11
   name 'Redmine Gitolite plugin'
12  
-  author 'Joshua Hogendorn, originally Jan Schulz-Hofen'
  12
+  author 'Yunsang Choi originally Joshua Hogendorn, Jan Schulz-Hofen'
13 13
   description 'Enables Redmine to update a gitolite server.'
14  
-  version '0.0.1alpha'
  14
+  version '0.1.0'
15 15
   settings :default => {
16 16
     'gitoliteUrl' => 'git@localhost:gitolite-admin.git',
17 17
     'gitoliteIdentityFile' => '/srv/projects/redmine/miner/.ssh/id_rsa',
47  lib/gitolite.rb
@@ -3,15 +3,20 @@
3 3
 require 'net/ssh'
4 4
 require 'tmpdir'
5 5
 
  6
+require 'gitolite_conf.rb'
  7
+
6 8
 module Gitolite
  9
+	def self.repository_name project
  10
+		parent_name = project.parent ? repository_name(project.parent) : ""
  11
+		return "#{parent_name}/#{project.identifier}".sub(/^\//, "")
  12
+	end
  13
+
7 14
 	def self.get_urls(project)
8 15
 		urls = {:read_only => [], :developer => []}
9 16
 		read_only_baseurls = Setting.plugin_redmine_gitolite['readOnlyBaseUrls'].split(/[\r\n\t ,;]+/)
10 17
 		developer_baseurls = Setting.plugin_redmine_gitolite['developerBaseUrls'].split(/[\r\n\t ,;]+/)
11 18
 
12  
-		project_path = ''
13  
-		project_path += project.parent.identifier + "/" if project.parent
14  
-		project_path += project.identifier + ".git"
  19
+		project_path = repository_name(project) + ".git"
15 20
 
16 21
 		read_only_baseurls.each {|baseurl| urls[:read_only] << baseurl + project_path}
17 22
 		developer_baseurls.each {|baseurl| urls[:developer] << baseurl + project_path}
@@ -68,41 +73,25 @@ def self.update_repositories(projects)
68 73
 				end
69 74
 
70 75
 				# write config file
71  
-				conf = IniFile.new(File.join(local_dir,'gitolite','gitolite.conf'))
72  
-				original = conf.clone
73  
-				name = "#{project.identifier}"
74  
-
75  
-				conf["group #{name}_readonly"]['readonly'] = name
76  
-				conf["group #{name}_readonly"]['members'] = read_users.map{|u| u.gitolite_public_keys.active}.flatten.map{ |key| "#{key.identifier}" }.join(' ')
  76
+				conf = Config.new(File.join(local_dir,'gitolite/conf', 'gitolite.conf'))
  77
+				repo_name = repository_name(project)
  78
+				read_users = read_users.map{|u| u.gitolite_public_keys.active}.flatten.map{|key| "#{key.identifier}"}
  79
+				write_users = write_users.map{|u| u.gitolite_public_keys.active}.flatten.map{|key| "#{key.identifier}"}
77 80
 
78  
-				conf["group #{name}"]['writable'] = name
79  
-				conf["group #{name}"]['members'] = write_users.map{|u| u.gitolite_public_keys.active}.flatten.map{ |key| "#{key.identifier}" }.join(' ')
  81
+				conf.set_read_user repo_name, read_users
  82
+				conf.set_write_user repo_name, write_users
80 83
 
81  
-				# git-daemon support for read-only anonymous access
82  
-				if User.anonymous.allowed_to?( :view_changesets, project )
83  
-					conf["repo #{name}"]['daemon'] = 'yes'
84  
-				else
85  
-					conf["repo #{name}"]['daemon'] = 'no'
86  
-				end
87  
-				# Enable/disable gitweb
88  
-				if User.anonymous.allowed_to?( :view_gitweb, project )
89  
-					conf["repo #{name}"]['gitweb'] = 'yes'
90  
-				else
91  
-					conf["repo #{name}"]['gitweb'] = 'no'
92  
-				end
93  
-
94  
-				unless conf.eql?(original)
95  
-					conf.write 
  84
+				if conf.changed?
  85
+					conf.save
96 86
 					changed = true
97 87
 				end
98  
-
99 88
 			end
100 89
 			if changed
101  
-				git_push_file = File.join(local_dir, 'git_push.bat')
  90
+				git_push_file = File.join(local_dir, 'git_push.sh')
102 91
 
103 92
 	      new_dir= File.join(local_dir,'gitolite')
104  
-#				new_dir.gsub!(/\//, '\\')
105 93
 				File.open(git_push_file, "w") do |f|
  94
+				  f.puts "#!/bin/sh"
106 95
 					f.puts "cd #{new_dir}"
107 96
 					f.puts "git add keydir/* gitolite.conf"
108 97
 					f.puts "git config user.email '#{Setting.mail_from}'"
96  lib/gitolite_conf.rb
... ...
@@ -0,0 +1,96 @@
  1
+module Gitolite
  2
+  class Config
  3
+		def initialize file_path
  4
+			@path = file_path
  5
+			load
  6
+		end
  7
+
  8
+		def save
  9
+			File.open(@path, "w") do |f|
  10
+				f.puts content
  11
+			end
  12
+			@original_content = content
  13
+		end
  14
+
  15
+		def add_write_user repo_name, users
  16
+			repository(repo_name).add "RW+", users
  17
+		end
  18
+
  19
+		def set_write_user repo_name, users
  20
+			repository(repo_name).set "RW+", users
  21
+		end
  22
+
  23
+		def add_read_user repo_name, users
  24
+			repository(repo_name).add "R", users
  25
+		end
  26
+
  27
+		def set_read_user repo_name, users
  28
+			repository(repo_name).set "R", users
  29
+		end
  30
+
  31
+		def changed?
  32
+			@original_content != content
  33
+		end
  34
+
  35
+		private
  36
+		def load
  37
+			@original_content = []	
  38
+			@repositories = {}
  39
+			cur_repo_name = nil
  40
+			File.open(@path).each_line do |line|
  41
+				@original_content << line
  42
+				tokens = line.strip.split
  43
+				if tokens.first == 'repo'
  44
+					cur_repo_name = tokens.last
  45
+					@repositories[cur_repo_name] = AccessRights.new
  46
+					next
  47
+				end
  48
+				cur_repo_right = @repositories[cur_repo_name]
  49
+				if cur_repo_right and tokens[1] == '='
  50
+					cur_repo_right.add tokens.first, tokens[2,]
  51
+				end
  52
+			end
  53
+			@original_content = @original_content.join
  54
+		end
  55
+
  56
+		def repository repo_name
  57
+			@repositories[repo_name] ||= AccessRights.new
  58
+		end
  59
+
  60
+
  61
+		def content
  62
+			content = []
  63
+			@repositories.each do |repo, rights|
  64
+				content << "repo\t#{repo}"
  65
+				rights.each do |perm, users|
  66
+					content << "\t#{perm}\t=\t#{users.join(' ')}"
  67
+				end
  68
+				content << ""
  69
+			end
  70
+			return content.join("\n")
  71
+		end
  72
+
  73
+	end
  74
+
  75
+	class AccessRights
  76
+		def initialize
  77
+			@rights = {}
  78
+		end
  79
+
  80
+		def add perm, users
  81
+			@rights[perm.to_sym] ||= []
  82
+			@rights[perm.to_sym] << users
  83
+			@rights[perm.to_sym].flatten.uniq
  84
+		end
  85
+
  86
+		def set perm, users
  87
+			@rights[perm.to_sym] = []
  88
+			add perm, users
  89
+		end
  90
+
  91
+		def each 
  92
+			@rights.each {|k,v| yield k, v}
  93
+		end
  94
+	end
  95
+end
  96
+

0 notes on commit d319b86

Please sign in to comment.
Something went wrong with that request. Please try again.