Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grid5000
g5k-api
Commits
b1da4c6c
Commit
b1da4c6c
authored
Aug 25, 2020
by
Samir Noir
🧀
Browse files
Add two new GET parameters to request reference api by date.
Instead of using version, this commit add timestamp and date parameters
parent
ccb664f1
Pipeline
#167178
passed with stages
in 22 minutes and 14 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
b1da4c6c
...
...
@@ -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
:
...
...
app/controllers/resources_controller.rb
View file @
b1da4c6c
...
...
@@ -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
)
...
...
lib/grid5000/repository.rb
View file @
b1da4c6c
...
...
@@ -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
...
...
spec/lib/grid5000/repository_spec.rb
View file @
b1da4c6c
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment