Skip to content

Commit

Permalink
Correction de comparaison des SHAs (#1999)
Browse files Browse the repository at this point in the history
* git repository : previous sha

* fix

* no fallback + gitlab note

* previous_sha to abstract
  • Loading branch information
SebouChu committed Jun 7, 2024
1 parent 29c27df commit 6d7eda2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/services/git/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def previous_path
end

def previous_sha
git_file.previous_sha
repository.previous_sha(git_file)
end

def exists_on_git?
Expand All @@ -72,7 +72,7 @@ def exists_on_git?
def synchronized_with_git?
exists_on_git? && # File exists
git_file.previous_path == git_file.path && # at the same place
repository.git_sha(git_file.path) == git_file.previous_sha # with the same content
repository.git_sha(git_file.path) == previous_sha # with the same content
end

end
4 changes: 4 additions & 0 deletions app/services/git/providers/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def push(commit_message)
raise NotImplementedError
end

def previous_sha(git_file)
git_sha(git_file.previous_path)
end

def computed_sha(string)
raise NotImplementedError
end
Expand Down
10 changes: 1 addition & 9 deletions app/services/git/providers/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ def computed_sha(string)
def git_sha(path)
return if path.nil?
# Try to find in stored tree to avoid multiple queries
return tree_item_at_path(path)&.dig(:sha)
begin
# The fast way, with no query, does not work.
# Let's query the API.
content = client.content repository, path: path
return content[:sha]
rescue
end
nil
tree_item_at_path(path)&.dig(:sha)
end

def valid?
Expand Down
1 change: 1 addition & 0 deletions app/services/git/providers/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def computed_sha(string)
end

# https://gitlab.com/gitlab-org/gitlab/-/issues/23504
# TODO : Il faudrait, comme sur GitHub, stocker le tree pour éviter N requêtes pour N objets.
def git_sha(path)
begin
file = find path
Expand Down
4 changes: 4 additions & 0 deletions app/services/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def computed_sha(string)
provider.computed_sha(string)
end

def previous_sha(git_file)
provider.previous_sha(git_file)
end

def git_sha(path)
provider.git_sha path
end
Expand Down

0 comments on commit 6d7eda2

Please sign in to comment.