bulb 0.3.0 → 0.4.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: 4d8fbeacdbc0bd0d8bdb90769e4bb4e25e3a9327847f5b690605a72ad7c29d29
4
+ data.tar.gz: 5f3cc7e8cd6778b4afbee05e73de2371929b3fac18b82263c10e643927d36124
5
5
  SHA512:
6
- metadata.gz: 5b9621fb449e3985fb2ff2bbc110bfae13480ade7c744531a5417eac13b9714547326d35c696b87b487fe1fd1341a2af118a55e289a87db0b37fcd159608c7a9
7
- data.tar.gz: ee4d4b2f85f9a6ea2b9245ee6589c431920de6941a7aada5f279cad71e81d0d9f54b27fa8ddb1f822ccce165128eb7a5f12031764f4adddf846fcf70003e0587
6
+ metadata.gz: f9c474bbb7aabc5cf420731d94ce969ac2327f3b3e6bf37f9b8a3ac1edd1214747d34aaba27319a8460c1dc8cf1b0fac46eac1446955e838ec52ef43e6771b42
7
+ data.tar.gz: d1e1ccedb16cfbbe54ae1ef1253feba5d77d9fef8c1bb2bcd36b191915e6c419d6f543890a3a515c864483f7fffbea9177e5c8232d999e347eff48a24d87217c
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.4.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.4.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: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,10 +86,10 @@ files:
86
86
  - app/helpers/bulb/application_helper.rb
87
87
  - app/helpers/bulb/text_helper.rb
88
88
  - app/jobs/bulb/application_job.rb
89
- - app/mailers/bulb/application_mailer.rb
90
89
  - app/models/bulb/application_record.rb
91
90
  - app/models/bulb/group.rb
92
91
  - app/models/bulb/repository.rb
92
+ - app/validators/bulb/unexisting_validator.rb
93
93
  - app/views/bulb/blob/show.html.erb
94
94
  - app/views/bulb/repositories/show.html.erb
95
95
  - app/views/bulb/tree/_blob.html.erb
@@ -99,6 +99,7 @@ files:
99
99
  - config/routes.rb
100
100
  - db/migrate/20210809182658_create_bulb_groups.rb
101
101
  - db/migrate/20210809182912_create_bulb_repositories.rb
102
+ - db/migrate/20220116171708_add_unique_index_on_slugs.rb
102
103
  - lib/bulb.rb
103
104
  - lib/bulb/engine.rb
104
105
  - lib/bulb/version.rb
@@ -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