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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b4645b55
Commit
b4645b55
authored
Sep 04, 2019
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse date in NotificationPayloadParser
Use `DateTime.parse` to support dates of various formats
parent
178c00c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
+17
-5
ee/lib/gitlab/alerting/notification_payload_parser.rb
ee/lib/gitlab/alerting/notification_payload_parser.rb
+6
-4
ee/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb
...c/lib/gitlab/alerting/notification_payload_parser_spec.rb
+11
-1
No files found.
ee/lib/gitlab/alerting/notification_payload_parser.rb
View file @
b4645b55
...
...
@@ -42,12 +42,14 @@ module Gitlab
payload
[
:hosts
]
&&
Array
(
payload
[
:hosts
])
end
def
starts_at
payload
[
:start_time
].
presence
||
current_time
def
current_time
Time
.
current
.
change
(
usec:
0
).
rfc3339
end
def
current_time
Time
.
now
.
change
(
usec:
0
).
rfc3339
def
starts_at
DateTime
.
parse
(
payload
[
:start_time
].
to_s
).
rfc3339
rescue
ArgumentError
current_time
end
end
end
...
...
ee/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb
View file @
b4645b55
...
...
@@ -4,7 +4,7 @@ require 'fast_spec_helper'
describe
Gitlab
::
Alerting
::
NotificationPayloadParser
do
describe
'.call'
do
let
(
:starts_at
)
{
Time
.
now
.
change
(
usec:
0
)
}
let
(
:starts_at
)
{
Time
.
current
.
change
(
usec:
0
)
}
let
(
:payload
)
do
{
'title'
=>
'alert title'
,
...
...
@@ -53,6 +53,16 @@ describe Gitlab::Alerting::NotificationPayloadParser do
end
end
context
'when the time is in unsupported format'
do
before
do
payload
[
:start_time
]
=
'invalid/date/format'
end
it
'sets startsAt to a currurrent time in RFC3339 format'
do
expect
(
subject
[
'startsAt'
]).
to
eq
(
starts_at
.
rfc3339
)
end
end
context
'when payload is blank'
do
let
(
:payload
)
{
{}
}
...
...
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