Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
update digests when updating tags
Browse files Browse the repository at this point in the history
If an already existing tag is pushed again, the digest is updated.

Fixes #826

Signed-off-by: Thomas Hipp <thipp@suse.de>
  • Loading branch information
Thomas Hipp committed Jul 7, 2016
1 parent 70b10ca commit ba32d14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ def self.add_repo(event, namespace, repo, tag)
return if actor.nil?

# Get or create the repository as "namespace/repo". If both the repo and
# the given tag already exists, return early.
# the given tag already exists, update the digest and return early.
repository = Repository.find_by(namespace: namespace, name: repo)
if repository.nil?
repository = Repository.create(namespace: namespace, name: repo)
elsif repository.tags.exists?(name: tag)
# Update digest if the given tag already exists.
_, digest = Repository.id_and_digest_from_event(event, repository.full_name)
repository.tags.find_by(name: tag).update!(digest: digest)
return
end

Expand Down
10 changes: 10 additions & 0 deletions spec/models/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ def get_url(repo, tag)
Repository.add_repo(event, registry.global_namespace, repository_name, tag_name)
end.to change(PublicActivity::Activity, :count).by(0)
end

it "updates the digest of an already existing tag" do
event = { "actor" => { "name" => user.username }, "target" => { "digest" => "foo" } }
Repository.add_repo(event, registry.global_namespace, repository_name, tag_name)
expect(Repository.find_by(name: repository_name).tags.first.digest).to eq("foo")

event["target"]["digest"] = "bar"
Repository.add_repo(event, registry.global_namespace, repository_name, tag_name)
expect(Repository.find_by(name: repository_name).tags.first.digest).to eq("bar")
end
end

context "event does not match regexp of manifest" do
Expand Down

0 comments on commit ba32d14

Please sign in to comment.