Commit 58a9df48 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Merge branch 'features/#11628' into 'master'

Add two new GET parameters to request reference api by date

See merge request !73
parents ccb664f1 b1da4c6c
Pipeline #167195 waiting for manual action with stages
in 22 minutes and 33 seconds
......@@ -72,7 +72,7 @@ deb-for-buster: &deb-for-buster
- mk-build-deps -ir -t 'apt-get -y --no-install-recommends'
- gem install bundler -v 2.1.4
- apt-get install -y curl pkg-config
- rm ../*deb
- rm -f ../*deb
- dpkg-buildpackage
- cp ../*deb .
artifacts:
......
......@@ -96,7 +96,9 @@ class ResourcesController < ApplicationController
object = repository.find(
path.gsub(%r{/?platforms}, ''),
branch: params[:branch],
version: params[:version]
version: params[:version],
timestamp: params[:timestamp],
date: params[:date]
)
raise ServerUnavailable if object.is_a?(Exception)
......
......@@ -112,14 +112,17 @@ module Grid5000
def find_commit_for(options = {})
options[:branch] ||= 'master'
version, branch = options.values_at(:version, :branch)
if version.nil?
instance.branches[branch].target
elsif version.to_s.length == 40 # SHA
version, branch, timestamp, date = options.values_at(:version, :branch, :timestamp, :date)
if version && version.to_s.length == 40 # SHA
instance.lookup(version)
else
# version should be a date, get the closest commit
date = version.to_i
elsif timestamp || date || version
if timestamp
ts = timestamp.to_i
elsif date
ts = Time.parse(date).to_i
else
ts = version.to_i
end
return nil if instance.branches[branch].nil?
......@@ -128,12 +131,14 @@ module Grid5000
walker.push(instance.branches[branch].target.oid)
commits = walker.select do |commit|
commit.epoch_time <= date
commit.epoch_time <= ts
end
commits.map! { |commit| commit.oid }
sha = commits.first
find_commit_for(options.merge(version: sha))
else
instance.branches[branch].target
end
rescue Rugged::OdbError
nil
......
......@@ -65,15 +65,21 @@ describe Grid5000::Repository do
expect(commit.oid).to eq(@latest_commit)
end
it 'should find the commit associated with the given version [version=DATE] 1/2' do
it 'should find the commit associated with the given timestamp [version=TS]' do
date = Time.parse('2009-03-13 17:24:20 +0100')
commit = @repository.find_commit_for(version: date.to_i)
expect(commit.oid).to eq('b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4')
end
it 'should find the commit associated with the given version [version=DATE] 2/2' do
date = Time.parse('2009-03-13 17:24:47 +0100')
commit = @repository.find_commit_for(version: date.to_i)
it 'should find the commit associated with the given timestamp [timestamp=TS] 1/2' do
date = Time.parse('2009-03-13 17:24:20 +0100')
commit = @repository.find_commit_for(timestamp: date.to_i)
expect(commit.oid).to eq('b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4')
end
it 'should find the commit associated with the given date [date=DATE] 2/2' do
date = '2009-03-13 17:24:47 +0100'
commit = @repository.find_commit_for(date: date)
expect(commit.oid).to eq('e07895a4b480aaa8e11c35549a97796dcc4a307d')
end
......@@ -87,7 +93,7 @@ describe Grid5000::Repository do
it 'should return nil when asking for a version from a branch that does not exist' do
date = Time.parse('Fri Mar 13 17:24:47 2009 +0100')
commit = @repository.find_commit_for(
version: date.to_i,
timestamp: date.to_i,
branch: 'doesnotexist'
)
expect(commit).to be_nil
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment