Skip to content

Commit

Permalink
Merge pull request #105 from railsbump/fixes/issue-104-slug-taken
Browse files Browse the repository at this point in the history
Redirect to existing slug when Gemfile.lock content has been already processed
  • Loading branch information
etagwerker authored Nov 13, 2024
2 parents 3ea9a31 + a11895e commit 191cdb6
Show file tree
Hide file tree
Showing 4 changed files with 4,076 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/models/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def gem_names
parser.dependencies.keys - %w(rails)
end

def calculated_slug
ActiveSupport::Digest.hexdigest(gem_names.join("#"))
end

private

def add_gemmies
Expand All @@ -45,7 +49,7 @@ def add_gemmies
def generate_slug
return if self.slug.present?

self.slug = ActiveSupport::Digest.hexdigest(gem_names.join("#"))
self.slug = calculated_slug
end

def validate_content
Expand Down
12 changes: 4 additions & 8 deletions app/services/lockfiles/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ def call(content)
def build(content)
result = Lockfile.new(content: content)

if result.valid?
if existing_lockfile = Lockfile.find_by(slug: result.slug)
raise AlreadyExists.new(existing_lockfile)
end

result
else
result
if existing_lockfile = Lockfile.find_by(slug: result.calculated_slug)
raise AlreadyExists.new(existing_lockfile)
end

result
end
end
end
Loading

0 comments on commit 191cdb6

Please sign in to comment.