rjgit_grack 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b3b6f0083eb09801ec9ab63c21d3cc61c0b4ee76
4
- data.tar.gz: 35ba1805472c93b622aed689fbf90386b20b7369
2
+ SHA256:
3
+ metadata.gz: 34c2343905a45fd0f5b0630de0d1d51d648bd2dadd6384af3db5e8f86203796e
4
+ data.tar.gz: 7df53ace4f4bebd370fe2f42a79dfde2c121070ff02a0597a60edf4f44a575fb
5
5
  SHA512:
6
- metadata.gz: a9ba14877655ed68438964b979f292a27a0be4e28643c20b310cfa1a98b680d702572c313b331cb6e3285728aeae945658210fb643db442c5c4262d5a62dba57
7
- data.tar.gz: debe40b287309f60ec97fdaf595b73d10b142cd9e5edac3f5a60aef89bbfb3086330dc498818c5bda0d20f5b48d57e2306163a96f1f16bd0a455dbb10afad314
6
+ metadata.gz: af136a2150625b2cfd1a7d03262ee875da5f905b124ddd56e4b25f7d12ef9f23b7b2460a3e24fed8ddde4bd959d075b7d298d42fa01b6d46760113edbc69a8d5
7
+ data.tar.gz: e3f3d4925e05894fb82a9a1d5f41359c45a0d571d98f5efe563859a57fe097a810af52da0bbc957478ed81b6e16a1af46d2e5d5e8af6ea60c373055de1fea3eb
data/Gemfile CHANGED
@@ -1,13 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'coveralls', require: false
4
+ gem 'coveralls', '~> 0.8.23', require: false
5
5
 
6
6
  group :test do
7
7
  gem "minitest"
8
8
  gem "rack-test"
9
9
  gem "mocha"
10
- gem "grack", :git => 'https://github.com/grackorg/grack'
10
+ gem "grack"
11
11
  gem "simplecov", :require => false
12
12
  end
13
13
 
data/README.md CHANGED
@@ -2,6 +2,7 @@ rjgit_grack
2
2
  ===========
3
3
  [![Gem Version](https://badge.fury.io/rb/rjgit_grack.svg)](http://badge.fury.io/rb/rjgit_grack)
4
4
  [![Build Status](https://travis-ci.org/grackorg/rjgit_grack.svg?branch=master)](https://travis-ci.org/grackorg/rjgit_grack.svg?branch=master)
5
+ [![Coverage Status](https://coveralls.io/repos/github/grackorg/rjgit_grack/badge.svg?branch=master)](https://coveralls.io/github/grackorg/rjgit_grack?branch=master)
5
6
  [![Dependency Status](https://gemnasium.com/dometto/rjgit_grack.svg)](https://gemnasium.com/grackorg/rjgit_grack)
6
7
 
7
8
  Alternative Adapter for [grack](http://github.com/grackorg/grack); uses the [RJGit](http://github.com/repotag/rjgit) gem for a pure jruby interface to git repos. Together with Grack, this yields a pure jruby implementation of git's smart-http protocol.
@@ -14,16 +15,15 @@ Installation
14
15
  Usage
15
16
  ===========
16
17
 
17
- 1. Get [grack](https://github.com/grackorgs/grack).
18
+ 1. Get [grack](https://github.com/grackorg/grack).
18
19
  2. After requiring `rjgit_grack.rb`, you can tell Grack to use the `RJGitAdapter` by editing its configuration, for example:
19
20
 
20
21
  ```ruby
21
22
  require 'grack/app'
22
- require 'grack/git_adapter'
23
- require 'rjgit_grack'
23
+ require 'grack/rjgit_adapter'
24
24
 
25
25
  config = {
26
- :root => '/path/to/bare/repositories',
26
+ :root => '/tmp/',
27
27
  :allow_push => true,
28
28
  :allow_pull => true,
29
29
  :git_adapter_factory => ->{ Grack::RJGitAdapter.new }
@@ -49,12 +49,12 @@ This adapter allows you to specify hooks to be called when receive operations (i
49
49
 
50
50
  You can specify the following hooks:
51
51
  * `:preReceive` executed immediately before a receive-operation is performed. Yields an `Array` with `Hash` objects containing info about each ref that is about to be pushed, of the following form:
52
- ```ruby
53
- {:ref_name => 'refs/heads/masters', :old_id => 'somesha1', :new_id => 'someothersha1', :type => "FAST_FORWARD", :result => "OK"}
52
+ ```
53
+ {:ref_name => 'refs/heads/masters', :old_id => 'somesha1', :new_id => 'someothersha1', :type => "FAST_FORWARD"}
54
54
  ```
55
55
  * `:postReceive` executed after a receive-operation is completed. Yields an `Array` with `Hash` objects for each ref that was pushed, of the same form as above, plus a `:result` field. The result will be a `String`, and can have one of the values [defined by JGit](http://download.eclipse.org/jgit/site/4.3.0.201604071810-r/apidocs/index.html).
56
- * `:preReceive` executed immediately before an upload-operation is performed, i.e. before data is sent to the client. Yields an `Array` of `String` object-id's (SHA1-hashes) already in common between client and server.
57
- * `:postReceive` executed after an upload-operation to a client is complete. Returns an `org.eclipse.jgit.storage.pack.PackStatistics` object (see [here](http://download.eclipse.org/jgit/site/4.3.0.201604071810-r/apidocs/org/eclipse/jgit/storage/pack/PackStatistics.html)).
56
+ * `:preUpload` executed immediately before an upload-operation is performed, i.e. before data is sent to the client. Yields an `Array` of `String` object-id's (SHA1-hashes) already in common between client and server.
57
+ * `:postUpload` executed after an upload-operation to a client is complete. Returns an `org.eclipse.jgit.storage.pack.PackStatistics` object (see [here](http://download.eclipse.org/jgit/site/4.3.0.201604071810-r/apidocs/org/eclipse/jgit/storage/pack/PackStatistics.html)).
58
58
 
59
59
  Note that JGit blocks all read and write operations on the repository until a hook is complete, so the hooks should only contain code that runs quickly (e.g. running workers or threads to perform the heavy work).
60
60
 
@@ -0,0 +1,110 @@
1
+ task :default => :test
2
+
3
+ desc "Run the tests."
4
+ task :test do
5
+ rename_test_git_dir
6
+ Dir.glob("tests/*_test.rb").each do |file|
7
+ require "./#{file}"
8
+ end
9
+ end
10
+
11
+ def rename_test_git_dir
12
+ dot_git = File.join(File.dirname(__FILE__), 'tests', 'example')
13
+ cp_r File.join(dot_git, '_git'), File.join(dot_git, 'test_repo', '.git'), :remove_destination => true
14
+ end
15
+
16
+
17
+ require 'rubygems'
18
+ require 'date'
19
+
20
+ #############################################################################
21
+ #
22
+ # Helper functions
23
+ #
24
+ #############################################################################
25
+
26
+ def name
27
+ @name ||= Dir['*.gemspec'].first.split('.').first
28
+ end
29
+
30
+ def date
31
+ Date.today.to_s
32
+ end
33
+
34
+ def gemspec_file
35
+ "#{name}.gemspec"
36
+ end
37
+
38
+ def gem_file
39
+ "#{name}-#{version}.gem"
40
+ end
41
+
42
+ def replace_header(head, header_name)
43
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
44
+ end
45
+
46
+ def version
47
+ spec = File.read(gemspec_file)
48
+ spec.match(/s\.version = \'(.*)\'/)[1]
49
+ end
50
+
51
+ #############################################################################
52
+ #
53
+ # Packaging tasks
54
+ #
55
+ #############################################################################
56
+
57
+ desc 'Create a release build and push to rubygems'
58
+ task :release => :build do
59
+ unless `git branch` =~ /^\* master$/
60
+ puts "You must be on the master branch to release!"
61
+ exit!
62
+ end
63
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
64
+ sh "git pull --rebase origin master"
65
+ sh "git tag v#{version}"
66
+ sh "git push origin master"
67
+ sh "git push origin v#{version}"
68
+ sh "gem push pkg/#{name}-#{version}.gem"
69
+ end
70
+
71
+ desc 'Publish to rubygems. Same as release'
72
+ task :publish => :release
73
+
74
+ desc 'Build gem'
75
+ task :build => :gemspec do
76
+ sh "mkdir -p pkg"
77
+ sh "gem build #{gemspec_file}"
78
+ sh "mv #{gem_file} pkg"
79
+ end
80
+
81
+ desc "Build and install"
82
+ task :install => :build do
83
+ sh "gem install --local --no-document pkg/#{name}-#{version}.gem"
84
+ end
85
+
86
+ desc 'Update gemspec'
87
+ task :gemspec do
88
+ # read spec file and split out manifest section
89
+ spec = File.read(gemspec_file)
90
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
91
+
92
+ # replace name and date
93
+ replace_header(head, :name)
94
+ replace_header(head, :date)
95
+
96
+ # determine file list from git ls-files
97
+ files = `git ls-files`.
98
+ split("\n").
99
+ sort.
100
+ reject { |file| file =~ /^\./ }.
101
+ reject { |file| file =~ /^(rdoc|pkg|test|Home\.md|\.gitattributes)/ }.
102
+ map { |file| " #{file}" }.
103
+ join("\n")
104
+
105
+ # piece file back together and write
106
+ manifest = " s.files = %w[\n#{files}\n ]\n"
107
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
108
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
109
+ puts "Updated #{gemspec_file}"
110
+ end
@@ -0,0 +1,59 @@
1
+ module Grack
2
+ module Hooks
3
+
4
+ class Hook
5
+ def initialize(hook)
6
+ @hook = hook
7
+ end
8
+ end
9
+
10
+ class PreReceiveHook < Hook
11
+ include org.eclipse.jgit.transport.PreReceiveHook
12
+ def onPreReceive(pack, commands)
13
+ @hook.call(commands.to_a.map {|cmd|
14
+ {
15
+ :ref_name => cmd.getRefName,
16
+ :old_id => cmd.getOldId.getName,
17
+ :new_id => cmd.getNewId.getName,
18
+ :type => cmd.getType.toString,
19
+ }
20
+ })
21
+ end
22
+ end
23
+
24
+ class PostReceiveHook < Hook
25
+ include org.eclipse.jgit.transport.PostReceiveHook
26
+ def onPostReceive(pack, commands)
27
+ @hook.call(commands.to_a.map {|cmd|
28
+ {
29
+ :ref_name => cmd.getRefName,
30
+ :old_id => cmd.getOldId.getName,
31
+ :new_id => cmd.getNewId.getName,
32
+ :type => cmd.getType.toString,
33
+ :result => cmd.getResult.toString
34
+ }
35
+ })
36
+ end
37
+ end
38
+
39
+ class PostUploadHook < Hook
40
+ include org.eclipse.jgit.transport.PostUploadHook
41
+ def onPostUpload(stats)
42
+ @hook.call(stats)
43
+ end
44
+ end
45
+
46
+ class PreUploadHook < Hook
47
+ include org.eclipse.jgit.transport.PreUploadHook
48
+
49
+ def onSendPack(pack, wants, haves)
50
+ @hook.call(wants.to_a.map {|obj| obj.getName}, haves.to_a.map {|obj| obj.getName})
51
+ end
52
+
53
+ def onBeginNegotiateRound(pack, wants, cnt_offered); end
54
+ def onEndNegotiateRound(pack, wants, cnt_common, cnt_not_found, ready ); end
55
+
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ require 'rjgit'
2
+
3
+ module Grack
4
+
5
+ class RJGitAdapter < GitAdapter
6
+
7
+ def initialize(hooks = nil)
8
+ @repository_path = nil
9
+ @hooks = hooks
10
+ end
11
+
12
+ def handle_pack(pack_type, io_in, io_out, opts = {})
13
+ pack = case pack_type
14
+ when 'git-upload-pack'
15
+ RJGit::RJGitUploadPack.new(repo)
16
+ when 'git-receive-pack'
17
+ RJGit::RJGitReceivePack.new(repo)
18
+ end
19
+ return nil if pack.nil?
20
+ set_hooks(pack) if @hooks
21
+ if opts[:advertise_refs] then
22
+ io_out.write advertisement_prefix(pack_type)
23
+ result = pack.advertise_refs
24
+ else
25
+ result = pack.process(io_in.read).first.read
26
+ end
27
+ io_out.write(result)
28
+ end
29
+
30
+ def update_server_info
31
+ repo.update_server_info
32
+ end
33
+
34
+ def config(key)
35
+ begin
36
+ settings = repo.config
37
+ rescue
38
+ return nil
39
+ end
40
+ key.split(".").each do |domain|
41
+ begin
42
+ settings = settings[domain]
43
+ rescue
44
+ return nil
45
+ end
46
+ end
47
+ settings.is_a?(Hash) ? settings : settings.to_s
48
+ end
49
+
50
+ private
51
+
52
+ def repo
53
+ RJGit::Repo.new(repository_path)
54
+ end
55
+
56
+ def set_hooks(pack)
57
+ if pack.is_a?(RJGit::RJGitUploadPack)
58
+ pack.jpack.setPostUploadHook(Grack::Hooks::PostUploadHook.new(@hooks[:postUpload])) if @hooks[:postUpload]
59
+ pack.jpack.setPreUploadHook(Grack::Hooks::PreUploadHook.new(@hooks[:preUpload])) if @hooks[:preUpload]
60
+ elsif pack.is_a?(RJGit::RJGitReceivePack)
61
+ pack.jpack.setPostReceiveHook(Grack::Hooks::PostReceiveHook.new(@hooks[:postReceive])) if @hooks[:postReceive]
62
+ pack.jpack.setPreReceiveHook(Grack::Hooks::PreReceiveHook.new(@hooks[:preReceive])) if @hooks[:preReceive]
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -1,69 +1,2 @@
1
- require 'rjgit'
2
- require 'hooks'
3
-
4
- module Grack
5
-
6
- class RJGitAdapter < GitAdapter
7
-
8
- def initialize(hooks = nil)
9
- @repository_path = nil
10
- @hooks = hooks
11
- end
12
-
13
- def handle_pack(pack_type, io_in, io_out, opts = {})
14
- pack = case pack_type
15
- when 'git-upload-pack'
16
- RJGit::RJGitUploadPack.new(repo)
17
- when 'git-receive-pack'
18
- RJGit::RJGitReceivePack.new(repo)
19
- end
20
- return nil if pack.nil?
21
- set_hooks(pack) if @hooks
22
- if opts[:advertise_refs] then
23
- io_out.write advertisement_prefix(pack_type)
24
- result = pack.advertise_refs
25
- else
26
- result = pack.process(io_in.read).first.read
27
- end
28
- io_out.write(result)
29
- end
30
-
31
- def update_server_info
32
- repo.update_server_info
33
- end
34
-
35
- def config(key)
36
- begin
37
- settings = repo.config
38
- rescue
39
- return nil
40
- end
41
- key.split(".").each do |domain|
42
- begin
43
- settings = settings[domain]
44
- rescue
45
- return nil
46
- end
47
- end
48
- settings.is_a?(Hash) ? settings : settings.to_s
49
- end
50
-
51
- private
52
-
53
- def repo
54
- RJGit::Repo.new(repository_path)
55
- end
56
-
57
- def set_hooks(pack)
58
- if pack.is_a?(RJGit::RJGitUploadPack)
59
- pack.jpack.setPostUploadHook(Grack::Hooks::PostUploadHook.new(@hooks[:postUpload])) if @hooks[:postUpload]
60
- pack.jpack.setPreUploadHook(Grack::Hooks::PreUploadHook.new(@hooks[:preUpload])) if @hooks[:preUpload]
61
- elsif pack.is_a?(RJGit::RJGitReceivePack)
62
- pack.jpack.setPostReceiveHook(Grack::Hooks::PostReceiveHook.new(@hooks[:postReceive])) if @hooks[:postReceive]
63
- pack.jpack.setPreReceiveHook(Grack::Hooks::PreReceiveHook.new(@hooks[:preReceive])) if @hooks[:preReceive]
64
- end
65
- end
66
-
67
- end
68
-
69
- end
1
+ require File.expand_path('../grack/rjgit_adapter.rb', __FILE__)
2
+ require File.expand_path('../grack/hooks.rb', __FILE__)
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rjgit_grack'
3
+ s.version = '0.5.0'
4
+ s.date = '2020-03-14'
5
+ s.summary = "Adapts grack (http://github.com/grackorg/grack) to use JGit."
6
+ s.description = "Alternative Adapter for grack; uses the RJGit gem for a pure jruby interface to git repos. Together with Grack, this yields a pure JRuby implementation of git's smart-http protocol."
7
+ s.authors = ['Dawa Ometto']
8
+ s.email = 'd.ometto@gmail.com'
9
+ s.files = ['lib/rjgit_grack.rb', 'README.md', 'LICENSE', 'Gemfile']
10
+ s.require_paths = ['lib']
11
+ s.homepage = "http://github.com/grackorg/rjgit_grack"
12
+ s.license = 'MIT'
13
+
14
+ s.add_dependency 'rjgit', '~> 5.6'
15
+ # = MANIFEST =
16
+ s.files = %w[
17
+ Gemfile
18
+ LICENSE
19
+ README.md
20
+ Rakefile
21
+ lib/grack/hooks.rb
22
+ lib/grack/rjgit_adapter.rb
23
+ lib/rjgit_grack.rb
24
+ rjgit_grack.gemspec
25
+ ]
26
+ # = MANIFEST =
27
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjgit_grack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dawa Ometto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-30 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rjgit
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '4.0'
20
- type: :runtime
18
+ version: '5.6'
19
+ name: rjgit
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.6'
27
27
  description: Alternative Adapter for grack; uses the RJGit gem for a pure jruby interface
28
28
  to git repos. Together with Grack, this yields a pure JRuby implementation of git's
29
29
  smart-http protocol.
@@ -35,30 +35,33 @@ files:
35
35
  - Gemfile
36
36
  - LICENSE
37
37
  - README.md
38
+ - Rakefile
39
+ - lib/grack/hooks.rb
40
+ - lib/grack/rjgit_adapter.rb
38
41
  - lib/rjgit_grack.rb
42
+ - rjgit_grack.gemspec
39
43
  homepage: http://github.com/grackorg/rjgit_grack
40
44
  licenses:
41
45
  - MIT
42
46
  metadata: {}
43
- post_install_message:
47
+ post_install_message:
44
48
  rdoc_options: []
45
49
  require_paths:
46
50
  - lib
47
51
  required_ruby_version: !ruby/object:Gem::Requirement
48
52
  requirements:
49
- - - '>='
53
+ - - ">="
50
54
  - !ruby/object:Gem::Version
51
55
  version: '0'
52
56
  required_rubygems_version: !ruby/object:Gem::Requirement
53
57
  requirements:
54
- - - '>='
58
+ - - ">="
55
59
  - !ruby/object:Gem::Version
56
60
  version: '0'
57
61
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 2.2.2
60
- signing_key:
62
+ rubyforge_project:
63
+ rubygems_version: 2.7.6
64
+ signing_key:
61
65
  specification_version: 4
62
66
  summary: Adapts grack (http://github.com/grackorg/grack) to use JGit.
63
67
  test_files: []
64
- has_rdoc: