Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
58368fbc
Commit
58368fbc
authored
Oct 07, 2016
by
Luke Bennett
Committed by
Z.J. van de Weg
Oct 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved ci_status environments logic to new action ci_envrionments_status and set up frontend polling
parent
fa58068b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
62 deletions
+96
-62
app/assets/javascripts/merge_request_widget.js.es6
app/assets/javascripts/merge_request_widget.js.es6
+37
-16
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+20
-18
app/views/projects/merge_requests/widget/_show.html.haml
app/views/projects/merge_requests/widget/_show.html.haml
+1
-0
config/routes.rb
config/routes.rb
+0
-5
config/routes/project.rb
config/routes/project.rb
+1
-0
spec/javascripts/merge_request_widget_spec.js
spec/javascripts/merge_request_widget_spec.js
+37
-23
No files found.
app/assets/javascripts/merge_request_widget.js.es6
View file @
58368fbc
...
@@ -35,13 +35,17 @@
...
@@ -35,13 +35,17 @@
});
});
this.firstCICheck = true;
this.firstCICheck = true;
this.readyForCICheck = false;
this.readyForCICheck = false;
this.readyForCIEnvironmentCheck = false;
this.cancel = false;
this.cancel = false;
clearInterval(this.fetchBuildStatusInterval);
clearInterval(this.fetchBuildStatusInterval);
clearInterval(this.fetchBuildEnvironmentStatusInterval);
this.clearEventListeners();
this.clearEventListeners();
this.addEventListeners();
this.addEventListeners();
this.getCIStatus(false);
this.getCIStatus(false);
this.getCIEnvironmentsStatus();
this.retrieveSuccessIcon();
this.retrieveSuccessIcon();
this.pollCIStatus();
this.pollCIStatus();
this.pollCIEnvironmentsStatus();
notifyPermissions();
notifyPermissions();
}
}
...
@@ -62,6 +66,7 @@
...
@@ -62,6 +66,7 @@
page = $('body').data('page').split(':').last();
page = $('body').data('page').split(':').last();
if (allowedPages.indexOf(page) < 0) {
if (allowedPages.indexOf(page) < 0) {
clearInterval(_this.fetchBuildStatusInterval);
clearInterval(_this.fetchBuildStatusInterval);
clearInterval(_this.fetchBuildEnvironmentStatusInterval);
_this.cancelPolling();
_this.cancelPolling();
return _this.clearEventListeners();
return _this.clearEventListeners();
}
}
...
@@ -178,23 +183,39 @@
...
@@ -178,23 +183,39 @@
})(this));
})(this));
};
};
MergeRequestWidget.prototype.pollCIEnvironmentsStatus = function() {
this.fetchBuildEnvironmentStatusInterval = setInterval(() => {
if (!this.readyForCIEnvironmentCheck) return;
this.getCIEnvironmentsStatus();
this.readyForCIEnvironmentCheck = false;
}, 300000);
};
MergeRequestWidget.prototype.getCIEnvironmentsStatus = function() {
$.getJSON(this.opts.ci_environments_status_url, (environments) => {
if (this.cancel) return;
this.readyForCIEnvironmentCheck = true;
if (environments && environments.length) this.renderEnvironments(environments);
});
};
MergeRequestWidget.prototype.renderEnvironments = function(environments) {
MergeRequestWidget.prototype.renderEnvironments = function(environments) {
for (let i = 0; i < environments.length; i++) {
for (let i = 0; i < environments.length; i++) {
const environment = environments[i];
const environment = environments[i];
if ($(`.mr-state-widget #${ environment.id }`).length) return;
if ($(`.mr-state-widget #${ environment.id }`).length) return;
const $template = $(DEPLOYMENT_TEMPLATE);
const $template = $(DEPLOYMENT_TEMPLATE);
if (!environment.external_url) $('.js-environment-link', $template).remove();
if (!environment.external_url) $('.js-environment-link', $template).remove();
if (environment.deployed_at) {
if (environment.deployed_at) {
environment.deployed_at = $.timeago(environment.deployed_at) + '.';
environment.deployed_at = $.timeago(environment.deployed_at) + '.';
} else {
} else {
$('.js-environment-timeago', $template).remove();
$('.js-environment-timeago', $template).remove();
environment.name += '.';
environment.name += '.';
}
}
environment.ci_success_icon = this.$ciSuccessIcon;
environment.ci_success_icon = this.$ciSuccessIcon;
const templateString = _.unescape($template[0].outerHTML);
const templateString = _.unescape($template[0].outerHTML);
const template = _.template(templateString)(environment)
const template = _.template(templateString)(environment)
this.$widgetBody.before(template);
this.$widgetBody.before(template);
}
}
};
};
MergeRequestWidget.prototype.showCIStatus = function(state) {
MergeRequestWidget.prototype.showCIStatus = function(state) {
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
58368fbc
...
@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action
:module_enabled
before_action
:module_enabled
before_action
:merge_request
,
only:
[
before_action
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:conflicts
,
:builds
,
:pipelines
,
:merge
,
:merge_check
,
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:conflicts
,
:builds
,
:pipelines
,
:merge
,
:merge_check
,
:ci_status
,
:toggle_subscription
,
:cancel_merge_when_build_succeeds
,
:remove_wip
,
:resolve_conflicts
,
:assign_related_issues
:ci_status
,
:
ci_environments_status
,
:
toggle_subscription
,
:cancel_merge_when_build_succeeds
,
:remove_wip
,
:resolve_conflicts
,
:assign_related_issues
]
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:pipelines
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:pipelines
]
before_action
:define_show_vars
,
only:
[
:show
,
:diffs
,
:commits
,
:conflicts
,
:builds
,
:pipelines
]
before_action
:define_show_vars
,
only:
[
:show
,
:diffs
,
:commits
,
:conflicts
,
:builds
,
:pipelines
]
...
@@ -393,11 +393,23 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -393,11 +393,23 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
end
end
environments
=
@merge_request
.
environments
.
map
do
|
environment
|
response
=
{
title:
merge_request
.
title
,
sha:
merge_request
.
diff_head_commit
.
short_id
,
status:
status
,
coverage:
coverage
}
render
json:
response
end
def
ci_environments_status
render
json:
@merge_request
.
environments
.
map
do
|
environment
|
next
unless
can?
(
current_user
,
:read_environment
,
environment
)
next
unless
can?
(
current_user
,
:read_environment
,
environment
)
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
environment
=
{
environment_data
=
{
name:
environment
.
name
,
name:
environment
.
name
,
id:
environment
.
id
,
id:
environment
.
id
,
url:
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
),
url:
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
),
...
@@ -405,26 +417,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -405,26 +417,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController
deployed_at:
deployment
?
deployment
.
created_at
:
nil
deployed_at:
deployment
?
deployment
.
created_at
:
nil
}
}
if
environment
[
:external_url
]
if
environment
_data
[
:external_url
]
environment
[
:external_url_formatted
]
=
environment
[
:external_url
].
gsub
(
/\A.*?:\/\//
,
''
)
environment
_data
[
:external_url_formatted
]
=
environment_data
[
:external_url
].
gsub
(
/\A.*?:\/\//
,
''
)
end
end
if
environment
[
:deployed_at
]
if
environment
_data
[
:deployed_at
]
environment
[
:deployed_at_formatted
]
=
environment
[
:deployed_at
].
to_time
.
in_time_zone
.
to_s
(
:medium
)
environment
_data
[
:deployed_at_formatted
]
=
environment_data
[
:deployed_at
].
to_time
.
in_time_zone
.
to_s
(
:medium
)
end
end
environment
environment
_data
end
.
compact
end
.
compact
response
=
{
title:
merge_request
.
title
,
sha:
merge_request
.
diff_head_commit
.
short_id
,
status:
status
,
coverage:
coverage
,
environments:
environments
}
render
json:
response
end
end
protected
protected
...
...
app/views/projects/merge_requests/widget/_show.html.haml
View file @
58368fbc
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
merge_check_url
:
"
#{
merge_check_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
merge_check_url
:
"
#{
merge_check_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
check_enable
:
#{
@merge_request
.
unchecked?
?
"true"
:
"false"
}
,
check_enable
:
#{
@merge_request
.
unchecked?
?
"true"
:
"false"
}
,
ci_status_url
:
"
#{
ci_status_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
ci_status_url
:
"
#{
ci_status_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
ci_environments_status_url
:
"
#{
ci_environments_status_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
)
}
"
,
gitlab_icon
:
"
#{
asset_path
'gitlab_logo.png'
}
"
,
gitlab_icon
:
"
#{
asset_path
'gitlab_logo.png'
}
"
,
ci_status
:
"
#{
@merge_request
.
pipeline
?
@merge_request
.
pipeline
.
status
:
''
}
"
,
ci_status
:
"
#{
@merge_request
.
pipeline
?
@merge_request
.
pipeline
.
status
:
''
}
"
,
ci_message
:
{
ci_message
:
{
...
...
config/routes.rb
View file @
58368fbc
...
@@ -83,9 +83,4 @@ Rails.application.routes.draw do
...
@@ -83,9 +83,4 @@ Rails.application.routes.draw do
draw
:group
draw
:group
draw
:user
draw
:user
draw
:project
draw
:project
# Get all keys of user
get
':username.keys'
=>
'profiles/keys#get_keys'
,
constraints:
{
username:
/.*/
}
root
to:
"root#index"
end
end
config/routes/project.rb
View file @
58368fbc
...
@@ -273,6 +273,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
...
@@ -273,6 +273,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
post
:merge
post
:merge
post
:cancel_merge_when_build_succeeds
post
:cancel_merge_when_build_succeeds
get
:ci_status
get
:ci_status
get
:ci_environments_status
post
:toggle_subscription
post
:toggle_subscription
post
:remove_wip
post
:remove_wip
get
:diff_for_path
get
:diff_for_path
...
...
spec/javascripts/merge_request_widget_spec.js
View file @
58368fbc
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
window
.
notify
=
function
()
{};
window
.
notify
=
function
()
{};
this
.
opts
=
{
this
.
opts
=
{
ci_status_url
:
"
http://sampledomain.local/ci/getstatus
"
,
ci_status_url
:
"
http://sampledomain.local/ci/getstatus
"
,
ci_environments_status_url
:
"
http://sampledomain.local/ci/getenvironmentsstatus
"
,
ci_status
:
""
,
ci_status
:
""
,
ci_message
:
{
ci_message
:
{
normal
:
"
Build {{status}} for
\"
{{title}}
\"
"
,
normal
:
"
Build {{status}} for
\"
{{title}}
\"
"
,
...
@@ -21,15 +22,45 @@
...
@@ -21,15 +22,45 @@
builds_path
:
"
http://sampledomain.local/sampleBuildsPath
"
builds_path
:
"
http://sampledomain.local/sampleBuildsPath
"
};
};
this
[
"
class
"
]
=
new
window
.
gl
.
MergeRequestWidget
(
this
.
opts
);
this
[
"
class
"
]
=
new
window
.
gl
.
MergeRequestWidget
(
this
.
opts
);
return
this
.
ciStatusData
=
{
"
title
"
:
"
Sample MR title
"
,
"
sha
"
:
"
12a34bc5
"
,
"
status
"
:
"
success
"
,
"
coverage
"
:
98
};
});
});
describe
(
'
getCIEnvironmentsStatus
'
,
function
()
{
beforeEach
(
function
()
{
this
.
ciEnvironmentsStatusData
=
{
created_at
:
'
2016-09-12T13:38:30.636Z
'
,
environment_id
:
1
,
environment_name
:
'
env1
'
,
external_url
:
'
https://test-url.com
'
,
external_url_formatted
:
'
test-url.com
'
};
spyOn
(
jQuery
,
'
getJSON
'
).
and
.
callFake
((
req
,
cb
)
=>
{
cb
(
this
.
ciEnvironmentsStatusData
);
});
});
it
(
'
should call renderEnvironments when the environments property is set
'
,
function
()
{
const
spy
=
spyOn
(
this
.
class
,
'
renderEnvironments
'
).
and
.
stub
();
this
.
class
.
getCIEnvironmentsStatus
();
expect
(
spy
).
toHaveBeenCalledWith
(
this
.
ciEnvironmentsStatusData
);
});
it
(
'
should not call renderEnvironments when the environments property is not set
'
,
function
()
{
const
spy
=
spyOn
(
this
.
class
,
'
renderEnvironments
'
).
and
.
stub
();
this
.
class
.
getCIEnvironmentsStatus
();
expect
(
spy
).
not
.
toHaveBeenCalled
();
});
});
return
describe
(
'
getCIStatus
'
,
function
()
{
return
describe
(
'
getCIStatus
'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
ciStatusData
=
{
"
title
"
:
"
Sample MR title
"
,
"
sha
"
:
"
12a34bc5
"
,
"
status
"
:
"
success
"
,
"
coverage
"
:
98
};
spyOn
(
jQuery
,
'
getJSON
'
).
and
.
callFake
((
function
(
_this
)
{
spyOn
(
jQuery
,
'
getJSON
'
).
and
.
callFake
((
function
(
_this
)
{
return
function
(
req
,
cb
)
{
return
function
(
req
,
cb
)
{
return
cb
(
_this
.
ciStatusData
);
return
cb
(
_this
.
ciStatusData
);
...
@@ -68,23 +99,6 @@
...
@@ -68,23 +99,6 @@
this
[
"
class
"
].
getCIStatus
(
true
);
this
[
"
class
"
].
getCIStatus
(
true
);
return
expect
(
spy
).
not
.
toHaveBeenCalled
();
return
expect
(
spy
).
not
.
toHaveBeenCalled
();
});
});
it
(
'
should call renderEnvironments when the environments property is set
'
,
function
()
{
this
.
ciStatusData
.
environments
=
[{
created_at
:
'
2016-09-12T13:38:30.636Z
'
,
environment_id
:
1
,
environment_name
:
'
env1
'
,
external_url
:
'
https://test-url.com
'
,
external_url_formatted
:
'
test-url.com
'
}];
var
spy
=
spyOn
(
this
[
'
class
'
],
'
renderEnvironments
'
).
and
.
stub
();
this
[
'
class
'
].
getCIStatus
(
false
);
expect
(
spy
).
toHaveBeenCalledWith
(
this
.
ciStatusData
.
environments
);
});
it
(
'
should not call renderEnvironments when the environments property is not set
'
,
function
()
{
var
spy
=
spyOn
(
this
[
'
class
'
],
'
renderEnvironments
'
).
and
.
stub
();
this
[
'
class
'
].
getCIStatus
(
false
);
expect
(
spy
).
not
.
toHaveBeenCalled
();
});
});
});
});
});
...
...
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