BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
601f50c6
Commit
601f50c6
authored
Mar 27, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint that returns a list of deployments that happened within last 8.hours
add index created_at
parent
19a44034
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
1 deletion
+81
-1
deployments_controller.rb
app/controllers/projects/deployments_controller.rb
+16
-0
project.rb
config/routes/project.rb
+2
-0
20170327091750_add_created_at_index_to_deployments.rb
...ate/20170327091750_add_created_at_index_to_deployments.rb
+11
-0
schema.rb
db/schema.rb
+2
-1
deployments_controller_spec.rb
spec/controllers/projects/deployments_controller_spec.rb
+50
-0
No files found.
app/controllers/projects/deployments_controller.rb
0 → 100644
View file @
601f50c6
class
Projects
::
DeploymentsController
<
Projects
::
ApplicationController
before_action
:authorize_read_deployment!
def
index
deployments
=
environment
.
deployments
.
where
(
'created_at > ?'
,
8
.
hours
.
ago
)
.
map
{
|
d
|
d
.
slice
(
:id
,
:iid
,
:created_at
,
:sha
,
:ref
,
:tag
)
}
render
json:
{
deployments:
deployments
}
end
private
def
environment
@environment
||=
project
.
environments
.
find
(
params
[
:environment_id
])
end
end
config/routes/project.rb
View file @
601f50c6
...
...
@@ -168,6 +168,8 @@ constraints(ProjectUrlConstrainer.new) do
collection
do
get
:folder
,
path:
'folders/:id'
end
resources
:deployments
,
only:
[
:index
]
end
resource
:cycle_analytics
,
only:
[
:show
]
...
...
db/migrate/20170327091750_add_created_at_index_to_deployments.rb
0 → 100644
View file @
601f50c6
class
AddCreatedAtIndexToDeployments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
change
add_concurrent_index
:deployments
,
:created_at
end
end
db/schema.rb
View file @
601f50c6
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201703
17203554
)
do
ActiveRecord
::
Schema
.
define
(
version:
201703
27091750
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20170317203554) do
t
.
string
"on_stop"
end
add_index
"deployments"
,
[
"created_at"
],
name:
"index_deployments_on_created_at"
,
using: :btree
add_index
"deployments"
,
[
"project_id"
,
"environment_id"
,
"iid"
],
name:
"index_deployments_on_project_id_and_environment_id_and_iid"
,
using: :btree
add_index
"deployments"
,
[
"project_id"
,
"iid"
],
name:
"index_deployments_on_project_id_and_iid"
,
unique:
true
,
using: :btree
...
...
spec/controllers/projects/deployments_controller_spec.rb
0 → 100644
View file @
601f50c6
require
'spec_helper'
describe
Projects
::
DeploymentsController
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
project
)
}
let
(
:deployment
)
{
create
(
:deployment
,
project:
project
,
environment:
environment
)
}
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
end
describe
'GET #index'
do
it
'returns list of deployments withing last 8 hours'
do
create
(
:deployment
,
environment:
environment
,
created_at:
9
.
hours
.
ago
)
create
(
:deployment
,
environment:
environment
,
created_at:
7
.
hours
.
ago
)
create
(
:deployment
,
environment:
environment
)
get
:index
,
environment_params
expect
(
response
).
to
be_ok
expect
(
json_response
[
'deployments'
].
count
).
to
eq
(
2
)
end
it
'returns a list with deployments information'
do
deployment
=
create
(
:deployment
,
environment:
environment
)
get
:index
,
environment_params
expect
(
response
).
to
be_ok
deployments
=
json_response
[
'deployments'
]
deployment_info
=
deployments
.
first
.
with_indifferent_access
created_at
=
deployment_info
.
delete
(
:created_at
).
to_time
.
utc
expect
(
deployments
.
count
).
to
eq
(
1
)
expect
(
deployment_info
).
to
include
(
:id
,
:iid
,
:sha
,
:ref
,
:tag
)
expect
(
deployment
).
to
have_attributes
(
deployment_info
)
expect
(
deployment
.
created_at
).
to
be_within
(
1
.
second
).
of
(
created_at
)
end
end
def
environment_params
(
opts
=
{})
opts
.
reverse_merge
(
namespace_id:
project
.
namespace
,
project_id:
project
,
environment_id:
environment
.
id
)
end
end
Write
Preview
Markdown
is supported
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