bulb 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 984ba929900ecc1d616b8f807f1fdd9f6500f4cb8e62ab22523d936ccb57fd00
4
- data.tar.gz: ea4d21695522c109fb53b767d993e481b9b679c162c4ce2e3fcdfbdc26cca4d7
3
+ metadata.gz: c7dbedd43a634514f1bf09c0bb403e0b58ae53581ba15b2efb53912524f75d68
4
+ data.tar.gz: 664df5f0802b66a6da0ac6fffb8b83c2863c248b04cc3885fdbb3b43734f2384
5
5
  SHA512:
6
- metadata.gz: 5b9621fb449e3985fb2ff2bbc110bfae13480ade7c744531a5417eac13b9714547326d35c696b87b487fe1fd1341a2af118a55e289a87db0b37fcd159608c7a9
7
- data.tar.gz: ee4d4b2f85f9a6ea2b9245ee6589c431920de6941a7aada5f279cad71e81d0d9f54b27fa8ddb1f822ccce165128eb7a5f12031764f4adddf846fcf70003e0587
6
+ metadata.gz: a6993095967f81af611273989c1f5a8e04288d031f6d31a3bdfdb13c7221d55d862ffbf4ef64b15ff63b8d1ce456cc90395508624db7ec7830aca5de1f1e250d
7
+ data.tar.gz: af58dea6f761f1641dc32a4d2655df044187585c80c74bb3e59456b0fb4a6b2190de42d4810ef1204bf65f90d6c27ebc3969639d8d61e537732f4a87f27eb13b
data/README.md CHANGED
@@ -24,8 +24,15 @@ $ bundle
24
24
 
25
25
  ## Usage
26
26
 
27
- Once installed, you can mount the engine to whichever path you
28
- like:
27
+ Once installed, you need to generate the needed migrations to
28
+ create the tables and migrate your database:
29
+
30
+ ```bash
31
+ $ rake bulb:install:migrations
32
+ $ rake db:migrate
33
+ ```
34
+
35
+ Then, you can mount the engine to whichever path you like:
29
36
 
30
37
  ```ruby
31
38
  mount Bulb::Engine => "/git"
@@ -34,6 +41,18 @@ mount Bulb::Engine => "/git"
34
41
  Then your repositories will be available through `/git/:group-slug/:slug`
35
42
  like `/git/sites/personal`.
36
43
 
44
+ To configure where your repositories are stored and who own them, you can
45
+ open your `config/application.rb` or any environment-specific file and add
46
+ the following:
47
+
48
+ ```ruby
49
+ config.bulb.repositories_path = '/srv/git/'
50
+ config.bulb.repositories_owner = 'git'
51
+ ```
52
+
53
+ Where `git` is a Unix user on your system that must be the owner of the
54
+ repository folders.
55
+
37
56
  ## License
38
57
 
39
58
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -5,8 +5,10 @@ module Bulb
5
5
 
6
6
  def show
7
7
  @git_repository = @repository.git_repository
8
-
9
8
  @blob_hash = @git_repository.head.target.tree.path(params[:path])
9
+
10
+ redirect_to repository_tree_path if @blob_hash[:type] == :tree
11
+
10
12
  @blob = @git_repository.lookup(@blob_hash[:oid])
11
13
  end
12
14
  end
@@ -5,8 +5,10 @@ module Bulb
5
5
 
6
6
  def show
7
7
  @git_repository = @repository.git_repository
8
-
9
8
  tree_hash = @git_repository.head.target.tree.path(params[:path])
9
+
10
+ redirect_to repository_blob_path if tree_hash[:type] == :blob
11
+
10
12
  @tree = @git_repository.lookup(tree_hash[:oid])
11
13
  end
12
14
  end
@@ -9,5 +9,32 @@ module Bulb
9
9
  root = root ? (root + "/") : ""
10
10
  bulb.repository_blob_path(reference: 'master', path: root + name)
11
11
  end
12
+
13
+ def breadcrumb
14
+ parts = params[:path].split("/")
15
+ last = parts.pop
16
+
17
+ reference = params[:reference]
18
+ group_slug = params[:group_slug]
19
+ slug = params[:slug]
20
+
21
+ elements = []
22
+
23
+ elements << content_tag(:li) do
24
+ link_to @repository.slug, bulb.repository_path(group_slug, slug)
25
+ end
26
+
27
+ parts.each_with_index do |part, index|
28
+ path = parts[0..index].join("/")
29
+
30
+ elements << content_tag(:li) do
31
+ link_to part, bulb.repository_tree_path(reference: reference, path: path)
32
+ end
33
+ end
34
+
35
+ elements << content_tag(:li, last)
36
+
37
+ content_tag(:ul, elements.join.html_safe, class: 'breadcrumb')
38
+ end
12
39
  end
13
40
  end
@@ -1,5 +1,7 @@
1
1
  module Bulb
2
2
  class Group < ApplicationRecord
3
3
  has_many :repositories
4
+
5
+ validates_uniqueness_of :slug, case_sensitive: false
4
6
  end
5
7
  end
@@ -6,6 +6,9 @@ module Bulb
6
6
 
7
7
  before_create :create_git_repository
8
8
 
9
+ validates_uniqueness_of :slug, scope: :bulb_group_id
10
+ validates :fs_repository_path, 'bulb/unexisting': true, on: :create
11
+
9
12
  def git_repository
10
13
  @git_repository ||= Rugged::Repository.new(fs_repository_path)
11
14
  end
@@ -14,17 +17,19 @@ module Bulb
14
17
  def create_git_repository
15
18
  full_path = fs_repository_path
16
19
 
17
- raise RuntimeError.new if File.exist?(full_path)
18
-
19
20
  FileUtils.mkdir_p(full_path)
20
21
  Rugged::Repository.init_at(full_path, :bare)
22
+
23
+ if (owner = Bulb.repositories_owner).present?
24
+ FileUtils.chown_R(owner, owner, full_path)
25
+ end
21
26
  end
22
27
 
23
28
  def fs_repository_path
24
29
  if group.nil?
25
- File.join(Bulb.repositories_path, slug)
30
+ File.join(Bulb.repositories_path, "#{slug}.git")
26
31
  else
27
- File.join(Bulb.repositories_path, group.slug, slug)
32
+ File.join(Bulb.repositories_path, group.slug, "#{slug}.git")
28
33
  end
29
34
  end
30
35
  end
@@ -0,0 +1,9 @@
1
+ module Bulb
2
+ class UnexistingValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+ if File.exist?(value)
5
+ record.errors.add attribute, 'must not exist'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,16 @@
1
- <div class="blob highlight">
2
- <%= raw highlight_blob @blob_hash[:name], @blob.content %>
3
- </div>
1
+ <%= breadcrumb %>
2
+
3
+ <% unless @blob.binary? %>
4
+ <div class="blob highlight">
5
+ <%= raw highlight_blob @blob_hash[:name], @blob.content.force_encoding(Encoding::UTF_8) %>
6
+ </div>
7
+ <% else %>
8
+ <div class="blob">
9
+ <% match = @blob_hash[:name].match(/\.(jpg|jpeg|png|gif)$/) %>
10
+ <% if match %>
11
+ <img src="data:image/<%= match[1] %>;base64,<%= Base64.strict_encode64(@blob.content) %>">
12
+ <% else %>
13
+ Nothing to display.
14
+ <% end %>
15
+ </div>
16
+ <% end %>
@@ -1 +1,3 @@
1
+ <%= breadcrumb %>
2
+
1
3
  <%= render partial: 'tree', locals: { tree: @tree } %>
@@ -0,0 +1,6 @@
1
+ class AddUniqueIndexOnSlugs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_index :bulb_groups, :slug, unique: true
4
+ add_index :bulb_repositories, [:bulb_group_id, :slug], unique: true
5
+ end
6
+ end
data/lib/bulb/engine.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Bulb
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Bulb
4
+
5
+ config.bulb = Bulb
4
6
  end
5
7
  end
data/lib/bulb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bulb
2
- VERSION = '0.3.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/bulb.rb CHANGED
@@ -2,4 +2,5 @@ require "bulb/engine"
2
2
 
3
3
  module Bulb
4
4
  mattr_accessor :repositories_path
5
+ mattr_accessor :repositories_owner
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Dupret
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-16 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 6.1.4
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,20 +27,29 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 6.1.4
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rugged
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 1.1.0
39
+ version: '1.6'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.6.3
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
47
  - - "~>"
39
48
  - !ruby/object:Gem::Version
40
- version: 1.1.0
49
+ version: '1.6'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.6.3
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: rouge
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -86,10 +98,10 @@ files:
86
98
  - app/helpers/bulb/application_helper.rb
87
99
  - app/helpers/bulb/text_helper.rb
88
100
  - app/jobs/bulb/application_job.rb
89
- - app/mailers/bulb/application_mailer.rb
90
101
  - app/models/bulb/application_record.rb
91
102
  - app/models/bulb/group.rb
92
103
  - app/models/bulb/repository.rb
104
+ - app/validators/bulb/unexisting_validator.rb
93
105
  - app/views/bulb/blob/show.html.erb
94
106
  - app/views/bulb/repositories/show.html.erb
95
107
  - app/views/bulb/tree/_blob.html.erb
@@ -99,6 +111,7 @@ files:
99
111
  - config/routes.rb
100
112
  - db/migrate/20210809182658_create_bulb_groups.rb
101
113
  - db/migrate/20210809182912_create_bulb_repositories.rb
114
+ - db/migrate/20220116171708_add_unique_index_on_slugs.rb
102
115
  - lib/bulb.rb
103
116
  - lib/bulb/engine.rb
104
117
  - lib/bulb/version.rb
@@ -122,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
135
  - !ruby/object:Gem::Version
123
136
  version: '0'
124
137
  requirements: []
125
- rubygems_version: 3.2.22
138
+ rubygems_version: 3.4.12
126
139
  signing_key:
127
140
  specification_version: 4
128
141
  summary: A Rails engine to deal with Git repositories
@@ -1,6 +0,0 @@
1
- module Bulb
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
6
- end