shagit 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,137 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'views'))
4
+
5
+ require 'rubygems'
6
+ require 'sinatra'
7
+ require 'haml'
8
+
9
+ require 'helpers/helpers'
10
+ require 'enhancing_grit'
11
+ require 'shagit'
12
+
13
+ use Rack::Session::Cookie, :expire_after => 1200, :secret => 'only Shagit should have access!'
14
+
15
+ # read in configuration parameters from yaml file and check runtime environment
16
+ configure do
17
+ load_config "config.yml"
18
+ check_if_started_from_gem(File.dirname(__FILE__))
19
+ end
20
+
21
+ # set utf-8 as content type for all responses
22
+ before do
23
+ headers "Content-Type" => "text/html; charset=uft-8"
24
+ end
25
+
26
+ # display all existing repositories
27
+ get '/' do
28
+ requires_login!
29
+
30
+ @shagit = Shagit.new
31
+ @title = "all repositories"
32
+
33
+ # show paths of all available repositories
34
+ haml :index
35
+ end
36
+
37
+ # display the login form
38
+ get '/login' do
39
+ @title = "log in"
40
+ haml :login
41
+ end
42
+
43
+ # check whether the provided username and password are correct
44
+ post '/login' do
45
+ username = params[:username]
46
+ password = params[:password]
47
+
48
+ if authorize!(username, password)
49
+ redirect('/')
50
+ else
51
+ @title = "log in"
52
+ haml :login_failed
53
+ end
54
+ end
55
+
56
+ get '/logout' do
57
+ requires_login!
58
+
59
+ @title = "log out"
60
+ session[:authorized] = false
61
+ haml :logout
62
+ end
63
+
64
+ # if no repository has been specified, redirect to index
65
+ get '/repo' do
66
+ requires_login!
67
+ redirect('/')
68
+ end
69
+
70
+ # display form to create a new repository
71
+ get '/repo/new' do
72
+ requires_login!
73
+
74
+ @title = "create new repository"
75
+ # show form for data entry used to create a new repository
76
+ haml :new
77
+ end
78
+
79
+ # create a new repository
80
+ post '/repo/new/?' do
81
+ requires_login!
82
+
83
+ @title = "create new repository"
84
+ repo = params[:name]
85
+
86
+ if Shagit.create_repo(get_fullpath(repo))
87
+ @confirmation_message = "Repository <a href='#{repo}.git'>#{repo}</a> created successfully"
88
+ else
89
+ @confirmation_message = "Could not create repository"
90
+ end
91
+ haml :new_confirmation
92
+ end
93
+
94
+ # display information about one specific repository
95
+ get '/repo/:name' do |repo|
96
+ requires_login!
97
+
98
+ @title = "display repository"
99
+ @current_repo_name = repo
100
+ @current_repo = Repo.new(get_fullpath(repo))
101
+ haml :repo
102
+ end
103
+
104
+ # optimize specified repository
105
+ put '/repo/:name/optimize' do |repo|
106
+ requires_login!
107
+
108
+ current_repo = Repo.new(get_fullpath(repo))
109
+ current_repo.gc_auto
110
+ redirect "/repo/#{repo}"
111
+ end
112
+
113
+ # display a confirmation form if the repository really shall be deleted
114
+ get '/repo/:name/delete' do |repo|
115
+ requires_login!
116
+
117
+ @title = "delete repository"
118
+ @current_repo_name = repo
119
+ haml :delete
120
+ end
121
+
122
+ # delete specified repository
123
+ delete '/repo/:name' do |repo|
124
+ requires_login!
125
+
126
+ @title = "delete repository"
127
+ @confirmation_message = "the repository has been successfully deleted."
128
+ Shagit.delete_repo!(get_fullpath(repo))
129
+ haml :delete_confirmation
130
+ end
131
+
132
+ not_found do
133
+ requires_login!
134
+
135
+ status 404
136
+ "Sorry, couldn't find what you were looking for"
137
+ end
@@ -0,0 +1,86 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../lib'))
2
+
3
+ require 'shagit_app'
4
+
5
+ require "rack/test"
6
+ require "webrat"
7
+ require "test/unit"
8
+
9
+ Webrat.configure do |config|
10
+ config.mode = :rack
11
+ config.application_port = 4567
12
+ config.application_framework = :sinatra
13
+ end
14
+
15
+ class AcceptanceTest < Test::Unit::TestCase
16
+ include Rack::Test::Methods
17
+ include Webrat::Methods
18
+ include Webrat::Matchers
19
+
20
+ def app
21
+ Sinatra::Application.new
22
+ end
23
+
24
+ def test_00_log_in_screen_displayed
25
+ visit "/"
26
+ assert_contain("log in")
27
+ assert_contain("username")
28
+ assert_contain("password")
29
+ assert_contain("login")
30
+ end
31
+
32
+ def test_01_logging_in
33
+ visit "/login"
34
+ fill_in "username", :with => "admin"
35
+ fill_in "password", :with => "admin"
36
+ click_button "login"
37
+ assert_contain("all repositories")
38
+ end
39
+
40
+ def test_02_no_repositories_available
41
+ test_01_logging_in
42
+ visit "/"
43
+ assert_contain("None found?!")
44
+ end
45
+
46
+ def test_03_adding_new_repository
47
+ test_01_logging_in
48
+ visit "/"
49
+ click_link "create your first repository"
50
+ assert_contain("create new repository")
51
+ fill_in "name", :with => "webrat"
52
+ click_button "create"
53
+ assert_contain("Repository webrat created successfully")
54
+ end
55
+
56
+ def test_04_displaying_info_on_existing_repository
57
+ test_01_logging_in
58
+ visit "/repo/webrat.git"
59
+ assert_contain("display repository")
60
+ assert_contain("actions for this repository")
61
+ end
62
+
63
+ def test_05_optimizing_repository
64
+ test_01_logging_in
65
+ visit "/repo/webrat.git"
66
+ assert_contain("display repository")
67
+ assert_contain("actions for this repository")
68
+ click_button "optimize"
69
+ end
70
+
71
+ def test_06_deleting_repository
72
+ test_01_logging_in
73
+ visit "/repo/webrat.git/delete"
74
+ assert_contain("Are you sure you want to delete the following repository?")
75
+ click_button "yes"
76
+ assert_contain("the repository has been successfully deleted.")
77
+ end
78
+
79
+ def test_07_logging_out
80
+ test_01_logging_in
81
+ visit "/"
82
+ click_link "log out"
83
+ assert_contain("you have successfully been logged out. see you next time!")
84
+ assert_contain("or do you want to log in again?")
85
+ end
86
+ end
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ require '../../lib/shagit'
3
+ require '../../lib/enhancing_grit'
4
+
5
+ class ShagitTest < Test::Unit::TestCase
6
+ @@repo_name = 'unit_test.git'
7
+ $working_dir = '.'
8
+
9
+ def test_00_create
10
+ puts "Creating new repository"
11
+ Shagit.create_repo(@@repo_name)
12
+ repository_created = FileTest.directory?("#{@@repo_name}")
13
+ assert(repository_created, 'repository could not be created.')
14
+ end
15
+
16
+ def test_01_load_config
17
+ puts "Loading configuration file"
18
+ config_file = 'config.yml'
19
+ require 'lib/helpers/helpers'
20
+ load_config(config_file)
21
+ config_data = ConfigInfo.instance
22
+ assert_equal($working_dir, config_data.working_dir, 'loading configuration file failed')
23
+ end
24
+
25
+ def test_02_initialize
26
+ Shagit.create_repo(@@repo_name)
27
+ puts "Initializing repository"
28
+ shagit = Shagit.new
29
+ assert_equal(1, shagit.repositories.length, 'repository not initialized properly')
30
+ end
31
+
32
+ def test_03_gc_auto
33
+ puts "Optimizing repository for #{@@repo_name}"
34
+ Shagit.create_repo(@@repo_name)
35
+ test_repo = Repo.new("#{@@repo_name}")
36
+ assert(test_repo.gc_auto, 'could not auto optimize repository')
37
+ end
38
+
39
+ def test_04_delete
40
+ Shagit.create_repo(@@repo_name)
41
+ puts "Deleting repository"
42
+ result = Shagit.delete_repo!("#{@@repo_name}")
43
+ assert(result, 'repository could not be deleted')
44
+ end
45
+
46
+ def teardown
47
+ `rm -rf #{@@repo_name}`
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ %form{ :action => "/repo/#{@current_repo_name}", :method => :post }
2
+ %br/
3
+ %h3
4
+ Are you sure you want to delete the following repository?
5
+ %h3
6
+ = @current_repo_name
7
+ %br/
8
+ %input.text#repo_name{ :name => "_method", :value => "delete", :type => "hidden" }
9
+ %button{ :type => :submit }= "yes"
10
+
11
+ %form{ :action => "/repo/#{@current_repo_name}", :method => :get }
12
+ %button{ :type => :submit }= "no"
13
+ %br/
@@ -0,0 +1,6 @@
1
+ #confirmation_message
2
+ %br/
3
+ %h3= @confirmation_message
4
+ %br/
5
+ %h3
6
+ %a{ :href => "/" } go back to overview
@@ -0,0 +1,14 @@
1
+ - if @shagit.repositories.empty?
2
+ .blank_slate
3
+ %p None found?!
4
+ %h1
5
+ Let's
6
+ = succeed "?" do
7
+ %a{ :href => "/repo/new" } create your first repository
8
+ - else
9
+ %ul#projects
10
+ - @shagit.repositories.each do |repository|
11
+ %li{ :class => cycle("even", "odd") }
12
+ %a(title = "#{repository.shagit_name}"){:href => "/repo/#{repository.shagit_foldername}" } #{repository.shagit_name}
13
+ %p#new
14
+ %a{ :href => "/repo/new" } Add a new repository
@@ -0,0 +1,17 @@
1
+ !!! Strict
2
+ %html{ :lang => "en", :"xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml" }
3
+ %head
4
+ %meta{ :content => "text/html; charset=utf-8", :"http-equiv" => "Content-Type" }
5
+ %meta{ :content => "en", :"http-equiv" => "Content-Language" }
6
+ %title= "shagit"
7
+ - stylesheets(:reset, :buttons, :shagit)
8
+ %body
9
+ #header
10
+ %h1= @title
11
+ %address.watermark
12
+ managed with
13
+ %a{ :href => "http://www.github.com/unabatede/shagit", :title => "Easy Git Repository Management" } shagit
14
+ #content= yield
15
+ - if is_authorized?
16
+ #footer
17
+ %a{ :href => "/logout", :title => "log out", :method => "post"} log out
@@ -0,0 +1,15 @@
1
+ %form{ :action => "/login", :method => :post }
2
+ .blank_slate
3
+ %h1
4
+ please tell me who you are
5
+ %br/
6
+ username:
7
+ %input.text#repo_name{ :name => "username", :type => "text" }
8
+ %br/
9
+ %br/
10
+ password:
11
+ %input.text#repo_name{ :name => "password", :type => "password" }
12
+ %br/
13
+ %br/
14
+ %button{ :type => :submit }= "login"
15
+ %br/
@@ -0,0 +1,15 @@
1
+ %form{ :action => "/login", :method => :post }
2
+ .blank_slate
3
+ %h1
4
+ login failed, please try again
5
+ %br/
6
+ username:
7
+ %input.text#repo_name{ :name => "username", :type => "text" }
8
+ %br/
9
+ %br/
10
+ password:
11
+ %input.text#repo_name{ :name => "password", :type => "password" }
12
+ %br/
13
+ %br/
14
+ %button{ :type => :submit }= "login"
15
+ %br/
@@ -0,0 +1,9 @@
1
+ .blank_slate
2
+ %p
3
+ you have successfully been logged out. see you next time!
4
+ %br/
5
+ %h1
6
+ or do you want to
7
+ = succeed "" do
8
+ %a{ :href => "/login", :title => "log in"} log in
9
+ again?
@@ -0,0 +1,10 @@
1
+ %form{ :action => "/repo/new", :method => :post }
2
+ %br/
3
+ Repository Name:
4
+ %input.text#repo_name{ :name => "name", :type => "text" }
5
+ %br/
6
+ %br/
7
+ %button{ :type => :submit }= "create"
8
+ %form{ :action => "/", :method => :get }
9
+ %button{ :type => :submit }= "cancel"
10
+ %br/
@@ -0,0 +1,6 @@
1
+ #confirmation_message
2
+ %br/
3
+ %h3= @confirmation_message
4
+ %br/
5
+ %h3
6
+ %a{ :href => "/" } go back to overview
@@ -0,0 +1,41 @@
1
+ #repository_info
2
+ %h3
3
+ = "stats & info"
4
+ %p
5
+ = "name: #{@current_repo.shagit_name}"
6
+ %br/
7
+ = "size (in KBs): #{@current_repo.shagit_size}"
8
+ %br/
9
+ = "location: #{full_path}"
10
+ %br/
11
+ %h3
12
+ = "help on using new repositories"
13
+ .frame
14
+ %p
15
+ mkdir foo
16
+ %br/
17
+ cd foo
18
+ %br/
19
+ git init
20
+ %br/
21
+ touch README
22
+ %br/
23
+ git add README
24
+ %br/
25
+ git commit -m "initial commit"
26
+ %br/
27
+ = "git remote add origin #{full_path}"
28
+ %br/
29
+ git push origin master
30
+ %br/
31
+ %h3
32
+ = "actions for this repository"
33
+ %form{ :action => "#{@current_repo_name}/optimize", :method => :post }
34
+ %input.text#repo_name{ :name => "_method", :value => "put", :type => "hidden" }
35
+ %button{ :type => :submit }= "optimize"
36
+ %form{ :action => "#{@current_repo_name}/delete", :method => :get }
37
+ %button{ :type => :submit }= "delete"
38
+ %br/
39
+ %br/
40
+ %h3
41
+ %a{ :href => "/" } go back to overview
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shagit
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Martin Gajdos
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-18 00:00:00 +01:00
18
+ default_executable: shagit
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 4
31
+ version: 0.9.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: haml
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 2
44
+ - 20
45
+ version: 2.2.20
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: grit
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 0
58
+ - 0
59
+ version: 2.0.0
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 5
72
+ - 3
73
+ version: 0.5.3
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: webrat
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 7
86
+ - 0
87
+ version: 0.7.0
88
+ type: :development
89
+ version_requirements: *id005
90
+ description: A simple web application for local, private git repository management
91
+ email: contact@roboprojects.com
92
+ executables:
93
+ - shagit
94
+ extensions: []
95
+
96
+ extra_rdoc_files:
97
+ - LICENSE
98
+ - README.md
99
+ files:
100
+ - CHANGES
101
+ - LICENSE
102
+ - README.md
103
+ - VERSION.yml
104
+ - config.ru
105
+ - config.yml
106
+ - lib/authorization.rb
107
+ - lib/config_info.rb
108
+ - lib/enhancing_grit.rb
109
+ - lib/helpers/helpers.rb
110
+ - lib/shagit.rb
111
+ - public/buttons.css
112
+ - public/reset.css
113
+ - public/shagit.css
114
+ - rakefile
115
+ - shagit_app.rb
116
+ - test/acceptance/acceptance_test.rb
117
+ - test/unit/shagit_test.rb
118
+ - views/delete.haml
119
+ - views/delete_confirmation.haml
120
+ - views/index.haml
121
+ - views/layout.haml
122
+ - views/login.haml
123
+ - views/login_failed.haml
124
+ - views/logout.haml
125
+ - views/new.haml
126
+ - views/new_confirmation.haml
127
+ - views/repo.haml
128
+ has_rdoc: true
129
+ homepage: http://github.com/unabatede/shagit
130
+ licenses: []
131
+
132
+ post_install_message: "\n ========================================================================\n Thanks for installing Shagit!\n ------------------------------------------------------------------------\n Please set the path to your working directory within the config.yml file\n before starting Shagit.\n\n Once you're done, you can start Shagit by running the following command:\n shagit\n\n For a production environment you should consider using Phusion Passenger\n or any of the other known Ruby deployment solutions that can be run as a\n daemon. \n\n Find out more and get involved:\n http://github.com/unabatede/shagit\n ========================================================================\n "
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ requirements: []
152
+
153
+ rubyforge_project:
154
+ rubygems_version: 1.3.6
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: A simple web application for local, private git repository management
158
+ test_files:
159
+ - test/acceptance/acceptance_test.rb
160
+ - test/unit/shagit_test.rb