ginst 0.1.3 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Manifest +34 -8
  3. data/Rakefile +6 -3
  4. data/bin/ginst +11 -4
  5. data/features/browsing_project.feature +20 -0
  6. data/features/manage_projects.feature +36 -0
  7. data/features/manage_server.feature +17 -0
  8. data/features/step_definitions/manage_projects_steps.rb +35 -0
  9. data/features/step_definitions/manage_server_steps.rb +33 -0
  10. data/features/step_definitions/webrat_steps.rb +99 -0
  11. data/features/support/env.rb +29 -0
  12. data/features/support/git.rb +22 -0
  13. data/features/support/paths.rb +16 -0
  14. data/ginst.gemspec +8 -11
  15. data/lib/app/authorization.rb +1 -1
  16. data/lib/app/views/_commit.haml +8 -0
  17. data/lib/app/views/commit.haml +38 -8
  18. data/lib/app/views/commits.haml +1 -1
  19. data/lib/app/views/edit.haml +11 -0
  20. data/lib/app/views/layout.haml +10 -7
  21. data/lib/app/views/new.haml +19 -0
  22. data/lib/app/views/project.haml +4 -1
  23. data/lib/app/views/ref.haml +3 -0
  24. data/lib/app/views/style.sass +0 -1
  25. data/lib/app/webserver.rb +66 -76
  26. data/lib/ginst.rb +7 -5
  27. data/lib/ginst/core_extensions.rb +32 -0
  28. data/lib/ginst/ginst.rb +5 -72
  29. data/lib/ginst/project.rb +13 -38
  30. data/lib/ginst/project/base.rb +59 -0
  31. data/lib/ginst/project/build.rb +117 -0
  32. data/lib/ginst/project/commit_db.rb +29 -0
  33. data/lib/ginst/project/finders.rb +17 -0
  34. data/lib/ginst/project/grit.rb +53 -0
  35. data/lib/ginst/project/validations.rb +60 -0
  36. data/lib/ginst/test.rb +8 -0
  37. data/lib/ginst/test/base.rb +17 -0
  38. data/lib/ginst/test/dir.rb +39 -0
  39. data/lib/ginst/test/repo.rb +13 -0
  40. data/lib/ginst/test/run.rb +11 -0
  41. data/lib/ginst/web_server.rb +43 -0
  42. data/spec/fixtures/sample_repo.zip +0 -0
  43. data/spec/models/project_base_spec.rb +56 -0
  44. data/spec/models/project_build_spec.rb +18 -0
  45. data/spec/models/project_commit_db_spec.rb +19 -0
  46. data/spec/models/project_finders_spec.rb +34 -0
  47. data/spec/models/project_grit_spec.rb +19 -0
  48. data/spec/models/project_validations_spec.rb +72 -0
  49. data/spec/spec_helper.rb +8 -0
  50. metadata +56 -29
  51. metadata.gz.sig +0 -0
  52. data/lib/app/views/full_commit.haml +0 -38
  53. data/lib/app/views/project_index.haml +0 -11
  54. data/lib/ginst/command_line.rb +0 -47
  55. data/lib/ginst/master_command_line.rb +0 -40
  56. data/lib/ginst/plugin.rb +0 -16
  57. data/lib/ginst/server.rb +0 -51
  58. data/lib/ginst/templates/rgithook.rb +0 -6
@@ -5,7 +5,7 @@ module GINST
5
5
  @auth ||= Rack::Auth::Basic::Request.new(request.env)
6
6
  end
7
7
 
8
- def unauthorized!(realm="myApp.com")
8
+ def unauthorized!(realm="Ginst Auth")
9
9
  header 'WWW-Authenticate' => %(Basic realm="#{realm}")
10
10
  throw :halt, [ 401, 'Authorization Required' ]
11
11
  end
@@ -0,0 +1,8 @@
1
+ %li.commit{:class => commit.status }
2
+ %img{ :src => "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(commit.author.email)}.jpg?s=42", :widht => 42, :height => 42}
3
+ .sha1
4
+ %a{ :href => "/projects/#{@project.name.slug}/commits/#{commit.id_abbrev}"}= commit.id_abbrev
5
+ .message= commit.short_message
6
+ .author
7
+ %a{ :href => "mailto:#{commit.author.email}"}= commit.author.name
8
+ .time= commit.date
@@ -1,8 +1,38 @@
1
- %li.commit{:class => commit.properties['status'] && commit.properties['status'].to_i==(0) ? 'success' : 'fail' || 'notest' }
2
- %img{ :src => "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(commit.author.email)}.jpg?s=42", :widht => 42, :height => 42}
3
- .sha1
4
- %a{ :href => "/#{@project.name}/commit/#{commit.id_abbrev}"}= commit.id_abbrev
5
- .message= commit.short_message
6
- .author
7
- %a{ :href => "mailto:#{commit.author.email}"}= commit.author.name
8
- .time= commit.date
1
+ = haml :_commit, :layout => false, :locals => {:commit => @commit}
2
+ - unless nil
3
+ %form{:method => 'post'}
4
+ %input{:type =>'submit', :value => 'Test this commit'}
5
+ - else
6
+ %form{:method => 'post'}
7
+ %input{:type =>'submit', :value => 'Tests are runing now', :disabled => 'disabled'}
8
+
9
+ %p.separator
10
+ Commit Info
11
+ %p.message
12
+ = @commit.message
13
+ %p.separator
14
+ Files
15
+ %p.files
16
+ %ul
17
+ -@commit.diffs.each do |diff|
18
+ - op = diff.deleted_file ? 'deleted' : (diff.new_file ? 'new' : (diff.a_path == diff.b_path ? 'update' : 'moved'))
19
+ %li{ :class => op }
20
+ = "(#{(diff.a_path == diff.b_path) ? 'igual' : 'cambio'})"
21
+ = diff.a_path || diff.b_path
22
+ - @commit.build.each do |k,v|
23
+ %p.separator=k.inspect
24
+ %p.message=v.inspect
25
+
26
+ %p.separator
27
+ Specs
28
+ %ul
29
+ %li
30
+ %dt Author:
31
+ %dd= @commit.author.name
32
+ %dt Commiter:
33
+ %dd= @commit.committer.name
34
+ %dt Commit Date:
35
+ %dd= @commit.date
36
+ %dt Work Date
37
+ %dd= @commit.authored_date
38
+ %dt
@@ -5,4 +5,4 @@
5
5
  - last_commit_date = commit.date.to_i / (60*60*24)
6
6
  %li.separator
7
7
  = (commit.date.year == Time.now.year) ? commit.date.strftime('%A %b %d') : commit.date.strftime('%A %b %d %Y')
8
- = haml :commit, :layout => false, :locals => {:commit => commit}
8
+ = haml :_commit, :layout => false, :locals => {:commit => commit}
@@ -0,0 +1,11 @@
1
+ %h1 New Project
2
+
3
+ %form{:method => "post", :action => "/projects/#{@project.name.slug}"}
4
+ %input{:type => 'hidden', :name => '_method', :value => 'put'}
5
+ %fieldset
6
+ %label{:for => "build_process"}Build Process
7
+ %textarea{:name => "project[build_process]", :id => "build_process", :rows => 20, :cols => 80 }= @project.build_process
8
+ .error= @project.errors["build_process"]
9
+
10
+ %input{:type => "submit", :value => "Update"}
11
+
@@ -19,14 +19,17 @@
19
19
  %h2 Git Integration System
20
20
  #left
21
21
  %ul
22
- - @ginst.projects.each do |project|
22
+ - Ginst::Project.projects.each do |project|
23
23
  %li
24
- %a{:href => "/#{project.name}"}= project.name
25
- %ul
26
- - project.branches.each do |branch|
27
- %li
28
- %a{:href => "/#{project.name}/branch/#{branch.name}"}= branch.name
24
+ %a{:href => "/projects/#{project.name.slug}"}= project.name
25
+ - if @project == project
26
+ %ul
27
+ - project.refs.each do |r|
28
+ %li
29
+ %a{:href => "/projects/#{project.name.slug}/refs/#{CGI::escape(r.name)}"}= r.name
30
+ %li
31
+ %a{:href=> "/projects/new"}New Project
29
32
  #mainContent
30
33
  =yield
31
34
  #footer
32
- %p= "Ginst <span class='version'>(#{Ginst::VERSION})</span> -- Powered by RGitHook <span class='version'>(#{RGitHook::VERSION})</span>"
35
+ %p== Ginst <span class='version'>(Ginst::VERSION)</span> -- Powered by RGitHook <span class='version'>(RGitHook::VERSION)</span>
@@ -0,0 +1,19 @@
1
+ %h1 New Project
2
+
3
+ %form{:method => "post", :action => "/projects"}
4
+ %fieldset
5
+ %legend Project data
6
+ %label{:for => "project_name"}Name
7
+ %input{:type => "text", :name => "project[name]", :id => "project_name", :value => @project.name}
8
+ .error= @project.errors["name"]
9
+ %br/
10
+ %label{:for => "project_dir"}Local directory
11
+ %input{:type => "text", :name => "project[dir]", :id => "project_dir", :value => @project.dir}
12
+ .error= @project.errors["dir"]
13
+
14
+ %label{:for => "build_process"}Build Process
15
+ %textarea{:name => "project[build_process]", :id => "build_process" , :rows => 20, :cols => 80}= @project.build_process
16
+ .error= @project.errors["build_process"]
17
+
18
+ %input{:type => "submit", :value => "Create"}
19
+
@@ -1 +1,4 @@
1
- hello
1
+ %a{:href => "/projects/#{@project.name.slug}/edit"} Edit Project
2
+ %form{:method => "post", :action => "/projects/#{@project.name.slug}"}
3
+ %input{:type => 'hidden', :name => '_method', :value => 'delete'}
4
+ %input{:type => "submit", :value => "Delete"}
@@ -0,0 +1,3 @@
1
+ =haml :commits, :locals => { :commits => @commits}, :layout => false
2
+
3
+ Here will come the paginator :=)
@@ -35,7 +35,6 @@ body
35
35
  padding: 0px
36
36
  list-style-type: none
37
37
  font-family: Verdana, Geneva, sans-serif
38
- text-transform: uppercase
39
38
  line-height: 24px
40
39
  a
41
40
  text-decoration: none
data/lib/app/webserver.rb CHANGED
@@ -1,113 +1,103 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'sinatra'
4
- require 'optparse'
5
- require 'ruby-debug'
6
- require 'digest/md5'
7
- require File.join(File.dirname(__FILE__),'authorization')
8
-
9
- begin
10
- require 'ginst'
11
- require 'ginst/plugin'
12
- rescue LoadError
13
- require File.join(File.dirname(__FILE__),'..','ginst')
4
+ require File.dirname(__FILE__)+'/authorization'
5
+
6
+
7
+ unless defined?(Ginst)
8
+ begin
9
+ require File.dirname(__FILE__)+'/../ginst.rb'
10
+ require 'ruby-debug'
11
+ puts 'Using development ginst'
12
+ rescue LoadError
13
+ require 'ginst'
14
+ end
14
15
  end
15
16
 
16
17
 
18
+
17
19
  set :views, File.dirname(__FILE__) + '/views'
18
20
  set :public, File.dirname(__FILE__) + '/views/assets'
19
21
 
20
- helpers do
21
- def format_message(text)
22
- text.gsub!("\t",'&nbsp;&nbsp;')
23
- text.gsub!("\n",'<br/>')
24
- text
25
- end
26
-
27
- def redirect_back
28
- redirect request.referer
29
- end
22
+ get '/' do
23
+ haml :index
30
24
  end
31
25
 
32
- def load_ginst
33
- @ginst = Ginst::Ginst.new(ENV["REPO_PATH"] || Dir.pwd)
34
- #@ginst.add_project '~/Documents/ginst'
26
+ get '/style.css' do
27
+ content_type 'text/css', :charset => 'utf-8'
28
+ # css_files = Dir.glob(File.join(File.dirname(File.expand_path(__FILE__)),'views','assets','*.css'))
29
+ # css_files.map{|f| File.read f}.join("\n")
30
+ sass :style
35
31
  end
36
32
 
37
- def load_project
38
- load_ginst
39
- @project = @ginst[params[:project] || @ginst.projects.first ] or raise Sinatra::NotFound
33
+ post '/projects' do
34
+ @project = Ginst::Project.new(params[:project])
35
+ if @project.save
36
+ redirect "/projects/#{@project.name.slug}"
37
+ else
38
+ haml :new
39
+ end
40
40
  end
41
41
 
42
- def load_branch
43
- load_project
44
- @branch = @project.branch(params[:branch] || 'master')
45
- @per_page = (params[:per_page] && params[:per_page].to_i) || 30
46
- @page = (params[:page] && params[:page].to_i) || 0
47
- @commits = @project.repo.commits(@branch.commit.id,@per_page, @page*@per_page)
42
+ get '/projects/new' do
43
+ @project = Ginst::Project.new
44
+ haml :new
48
45
  end
49
46
 
50
- def load_commit
51
- load_project
52
- @commit = @project.repo.commit(params[:commit])
47
+ get '/projects/:id' do
48
+ @project = Ginst::Project.find_by_slug(params[:id]) or raise Sinatra::NotFound
49
+ haml :project
53
50
  end
54
51
 
55
-
56
- get '/' do
57
- load_ginst
58
- redirect @ginst.projects.first.name
59
- load_ginst
60
- haml :index
52
+ put '/projects/:id' do
53
+ @project = Ginst::Project.find_by_slug(params[:id]) or raise Sinatra::NotFound
54
+ @project.build_process = params[:project][:build_process]
55
+
56
+ if @project.save
57
+ redirect request.env["REQUEST_URI"] || request.env["PATH_INFO"]
58
+ else
59
+ redirect "/projects/#{@project.name.slug}/edit"
60
+ end
61
61
  end
62
62
 
63
- get '/:project' do
64
- load_project
65
- haml :project_index
63
+ delete '/projects/:id' do
64
+ @project = Ginst::Project.find_by_slug(params[:id]) or raise Sinatra::NotFound
65
+ @project.destroy
66
+
67
+ redirect request.env["REQUEST_URI"] || request.env["PATH_INFO"]
66
68
  end
67
69
 
68
- post '/:project' do
69
- load_project
70
- @project.install_ginst
71
- redirect_back
70
+ get '/projects/:project/edit' do
71
+ @project = Ginst::Project.find_by_slug(params[:project]) or raise Sinatra::NotFound
72
+ haml :edit
72
73
  end
73
74
 
74
- get '/:project/branch/:branch' do
75
- load_branch
76
- haml :branch_index
75
+ get '/projects/:project/refs/:refname' do
76
+ @project = Ginst::Project.find_by_slug(params[:project]) or raise Sinatra::NotFound
77
+ @ref = @project.find_ref(CGI::unescape(params[:refname])) or raise Sinatra::NotFound
78
+ @commits = @ref.commits
79
+ haml :ref
77
80
  end
78
81
 
79
- get '/:project/commit/:commit' do
80
- load_commit
81
- haml :full_commit
82
+ get '/projects/:project/commits/:commit' do
83
+ @project = Ginst::Project.find_by_slug(params[:project]) or raise Sinatra::NotFound
84
+ @commit = @project.find_commit(params[:commit]) or raise Sinatra::NotFound
85
+ haml :commit
82
86
  end
83
87
 
84
- post '/:project/commit/:commit' do
85
- load_commit
86
- @project.run_hooks_for_commit(@commit)
87
- redirect_back
88
+ post '/projects/:project/commits/:commit' do
89
+ @project = Ginst::Project.find_by_slug(params[:project]) or raise Sinatra::NotFound
90
+ @commit = @project.find_commit(params[:commit]) or raise Sinatra::NotFound
91
+ @commit.build!
92
+ redirect request.env["REQUEST_URI"]
88
93
  end
89
94
 
95
+
90
96
  not_found do
91
97
  haml :not_found, :layout => :clean_layout
92
98
  end
99
+
93
100
 
94
- error do
95
- 'Sorry there was a nasty error - ' + env['sinatra.error'].name
96
- end
97
-
98
- error Exception do
99
- 'Sorry there was a nasty error - ' + env['sinatra.error'].name
100
- end
101
101
 
102
- get '/about' do
103
- "I'm running on Version " + Sinatra::VERSION
104
- end
105
102
 
106
- get '/style.css' do
107
- content_type 'text/css', :charset => 'utf-8'
108
- # css_files = Dir.glob(File.join(File.dirname(File.expand_path(__FILE__)),'views','assets','*.css'))
109
- # css_files.map{|f| File.read f}.join("\n")
110
- sass :style
111
- end
112
-
113
-
103
+
data/lib/ginst.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  module Ginst
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.2'
5
5
  end
6
6
 
7
7
  require 'rubygems'
8
- require 'rgithook'
8
+ require 'grit'
9
+ require 'ginst/core_extensions'
9
10
 
10
- Ginst.autoload(:Ginst, 'ginst/ginst')
11
- Ginst.autoload(:Server, 'ginst/server')
12
- Ginst.autoload(:CommandLine, 'ginst/command_line')
11
+ require 'ginst/ginst'
12
+ Ginst.autoload(:Project, 'ginst/project')
13
+ Ginst.autoload(:WebServer, 'ginst/web_server')
14
+ Ginst.autoload(:Test,'ginst/test')
@@ -0,0 +1,32 @@
1
+ class String
2
+ def slug
3
+ str = self.dup
4
+ accents = {
5
+ ['á','à','â','ä','ã'] => 'a',
6
+ ['Ã','Ä','Â','À','�?'] => 'A',
7
+ ['é','è','ê','ë'] => 'e',
8
+ ['Ë','É','È','Ê'] => 'E',
9
+ ['í','ì','î','ï'] => 'i',
10
+ ['�?','Î','Ì','�?'] => 'I',
11
+ ['ó','ò','ô','ö','õ'] => 'o',
12
+ ['Õ','Ö','Ô','Ò','Ó'] => 'O',
13
+ ['ú','ù','û','ü'] => 'u',
14
+ ['Ú','Û','Ù','Ü'] => 'U',
15
+ ['ç'] => 'c', ['Ç'] => 'C',
16
+ ['ñ'] => 'n', ['Ñ'] => 'N'
17
+ }
18
+ accents.each do |ac,rep|
19
+ ac.each do |s|
20
+ str = str.gsub(s, rep)
21
+ end
22
+ end
23
+ str = str.gsub(/[^a-zA-Z0-9 ]/,"")
24
+
25
+ str = str.gsub(/[ ]+/," ")
26
+ str = str.strip
27
+ str = str.gsub(/ /,"-")
28
+
29
+ str = str.downcase
30
+
31
+ end
32
+ end
data/lib/ginst/ginst.rb CHANGED
@@ -1,73 +1,6 @@
1
- require 'fileutils'
2
- require 'rgithook'
3
- require 'ginst/project'
4
-
5
- module Ginst
6
- class Ginst
7
-
8
- attr_reader :projects
9
- def initialize(path = nil)
10
- @projects = [Project.new(path || Dir.pwd)]
11
- end
12
-
13
- def [](project_name)
14
- @projects.select{|p| p.name == project_name}.first
15
- end
16
-
17
- def add_project(path_or_project)
18
- case path_or_project
19
- when String
20
- @projects << Project.new(path_or_project)
21
- when Project
22
- @projects << path_or_project
23
- end
24
- end
25
- # Install Ginst in the given path
26
- # Options can be:
27
- # * :verbose: true/false
28
- def self.install(path,options={})
29
- self.new(path).install(options)
30
- end
31
-
32
- def install(options = {})
33
- opts={:verbose => true, :interactive => true}
34
- opts.merge(options)
35
-
36
- puts 'Installing rgithook' if opts[:verbose]
37
- @rgithook = RGitHook::RGitHook.new(@path)
38
- @rgithook.install(opts[:interactive])
39
-
40
- #check for a valid repo
41
- @path = Grit::Repo.new(@path).path
42
- @ginst_dir = File.join(@path,'ginst')
43
-
44
- puts 'Installing ginst' if opts[:verbose]
45
- install_ginst(opts)
46
-
47
- puts 'Installing hooks' if opts[:verbose]
48
- install_hook(opts)
49
- end
50
-
51
- def self.install_master(path,options)
52
- self.new(path).install_mater(options)
53
- end
54
-
55
- private
56
-
57
- def install_ginst(opts)
58
- puts "Installing Ginst in #{@path}" if opts[:verbose]
59
- FileUtils.mkdir(@ginst_dir) unless File.directory? @ginst_dir
60
- FileUtils.cp_r(template_path,@ginst_dir, {:preserve => true, :verbose => opts[:verbose]})
61
- end
62
-
63
- def install_hook(opts)
64
- puts
65
- @rgithook.conf_file
66
- end
67
-
68
-
69
- def template_path
70
- File.join(File.dirname(__FILE__),'..','app','.')
71
- end
1
+ module Ginst::Ginst
2
+ @working_dir = Dir.pwd
3
+ class << self
4
+ attr_accessor :working_dir
72
5
  end
73
- end
6
+ end