Commit a869be24 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'chrono-0.4'

8841d8da chrono: update to 0.4
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !95
parents b2bcc6ae 8841d8da
Pipeline #63850 failed with stage
in 0 seconds
......@@ -20,7 +20,7 @@ reqwest = "~0.6"
serde_derive = "^1.0"
url = "^1.4"
chrono = { version = "~0.3.1", features = ["serde"] }
chrono = { version = "~0.4", features = ["serde"] }
error-chain = ">= 0.9, < 0.11"
serde = "~1.0"
serde_json = "^1.0"
......
......@@ -14,7 +14,7 @@
//! Gitlab does not have consistent structures for its hooks, so they often change from
//! version to version.
use crates::chrono::{DateTime, UTC};
use crates::chrono::{DateTime, Utc};
use crates::serde::{Deserialize, Deserializer, Serialize, Serializer};
use crates::serde::de::{Error, Unexpected};
use crates::serde_json::{self, Value};
......@@ -64,9 +64,9 @@ pub struct ProjectSystemHook {
/// The event which occurred.
pub event_name: ProjectEvent,
/// When the project was created.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the project was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The display name of the project.
pub name: String,
......@@ -140,9 +140,9 @@ pub struct ProjectMemberSystemHook {
/// The event which occurred.
pub event_name: ProjectMemberEvent,
/// When the membership was created.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the membership was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The name of the project.
pub project_name: String,
/// The path of the project (used for URLs).
......@@ -185,9 +185,9 @@ pub struct UserSystemHook {
/// The event which occurred.
pub event_name: UserEvent,
/// When the user account was created.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the user account was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The name of the user.
pub name: String,
/// The email address of the user.
......@@ -218,9 +218,9 @@ pub struct KeySystemHook {
/// The event which occurred.
pub event_name: KeyEvent,
/// When the key was added.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the key was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The username of the user.
pub username: String,
/// The content of the key.
......@@ -249,9 +249,9 @@ pub struct GroupSystemHook {
/// The event which occurred.
pub event_name: GroupEvent,
/// When the group was created.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the group was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The name of the group.
pub name: String,
/// The path of the group (used for URLs).
......@@ -284,9 +284,9 @@ pub struct GroupMemberSystemHook {
/// The event which occurred.
pub event_name: GroupMemberEvent,
/// When the group membership was added.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the group membership was last updated.
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The name of the group.
pub group_name: String,
/// The path of the group (used for URLs).
......@@ -327,9 +327,9 @@ pub struct PushSystemHook {
/// XXX(gitlab): Bug in Gitlab; it should not send this.
object_kind: String,
/// When the push occurred.
pub created_at: DateTime<UTC>,
pub created_at: DateTime<Utc>,
/// When the push
pub updated_at: DateTime<UTC>,
pub updated_at: DateTime<Utc>,
/// The old object ID of the ref that was pushed.
pub before: ObjectId,
/// The new object ID of the ref that was pushed.
......
......@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use crates::chrono::{NaiveDate, TimeZone, UTC};
use crates::chrono::{NaiveDate, TimeZone, Utc};
use crates::serde::de::DeserializeOwned;
use crates::serde_json::from_reader;
......@@ -36,10 +36,10 @@ fn test_read_award_emoji() {
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon");
assert_eq!(award_emoji.user.id, UserId::new(13));
assert_eq!(award_emoji.created_at,
UTC.ymd(2016, 12, 7)
Utc.ymd(2016, 12, 7)
.and_hms_milli(16, 23, 46, 742));
assert_eq!(award_emoji.updated_at,
UTC.ymd(2016, 12, 7)
Utc.ymd(2016, 12, 7)
.and_hms_milli(16, 23, 46, 742));
assert_eq!(award_emoji.awardable_id(),
AwardableId::Note(NoteId::new(177359)));
......@@ -63,7 +63,7 @@ fn test_read_commit_note() {
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon");
assert_eq!(commit_note.author.id, UserId::new(13));
assert_eq!(commit_note.created_at,
UTC.ymd(2016, 12, 7)
Utc.ymd(2016, 12, 7)
.and_hms_milli(16, 28, 33, 966));
}
......@@ -82,11 +82,11 @@ fn test_read_commit_status() {
.to_string()));
assert_eq!(commit_status.description, Some("expected".to_string()));
assert_eq!(commit_status.created_at,
UTC.ymd(2016, 11, 8)
Utc.ymd(2016, 11, 8)
.and_hms_milli(14, 35, 32, 627));
assert_eq!(commit_status.started_at, None);
assert_eq!(commit_status.finished_at,
Some(UTC.ymd(2016, 11, 8)
Some(Utc.ymd(2016, 11, 8)
.and_hms_milli(14, 35, 32, 629)));
assert_eq!(commit_status.allow_failure, false);
assert_eq!(commit_status.author.username, "buildbot");
......@@ -111,10 +111,10 @@ fn test_read_issue() {
assert_eq!(issue.description, Some("".to_string()));
assert_eq!(issue.state, IssueState::Closed);
assert_eq!(issue.created_at,
UTC.ymd(2016, 10, 30)
Utc.ymd(2016, 10, 30)
.and_hms_milli(18, 54, 28, 954));
assert_eq!(issue.updated_at,
UTC.ymd(2017, 1, 13)
Utc.ymd(2017, 1, 13)
.and_hms_milli(21, 45, 20, 901));
assert!(issue.labels.is_empty());
assert!(issue.milestone.is_none());
......@@ -161,10 +161,10 @@ fn test_read_issue_reference() {
a webhook for new projects. An API needs added for this.\n\nCc: @brad.king".to_string()));
assert_eq!(issue.state, IssueState::Closed);
assert_eq!(issue.created_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(18, 59, 37, 178));
assert_eq!(issue.updated_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(20, 18, 57, 519));
assert!(issue.labels.is_empty());
assert!(issue.milestone.is_none());
......@@ -226,10 +226,10 @@ fn test_read_merge_request() {
assert_eq!(merge_request.description, Some("Fixes #5.".to_string()));
assert_eq!(merge_request.state, MergeRequestState::Merged);
assert_eq!(merge_request.created_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(19, 56, 43, 276));
assert_eq!(merge_request.updated_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(20, 18, 57, 940));
assert_eq!(merge_request.target_branch, "master");
assert_eq!(merge_request.source_branch, "add_hook-api");
......@@ -288,10 +288,10 @@ fn test_read_note() {
"https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon");
assert_eq!(note.author.id, UserId::new(10));
assert_eq!(note.created_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(20, 18, 57, 786));
assert_eq!(note.updated_at,
UTC.ymd(2016, 10, 4)
Utc.ymd(2016, 10, 4)
.and_hms_milli(20, 18, 57, 786));
assert_eq!(note.system, true);
assert_eq!(note.noteable_id(),
......@@ -324,10 +324,10 @@ fn test_read_project() {
assert_eq!(project.path_with_namespace, "utils/rust-gitlab");
assert_eq!(project.container_registry_enabled, Some(true));
assert_eq!(project.created_at,
UTC.ymd(2016, 6, 29)
Utc.ymd(2016, 6, 29)
.and_hms_milli(17, 35, 12, 495));
assert_eq!(project.last_activity_at,
UTC.ymd(2017, 5, 24)
Utc.ymd(2017, 5, 24)
.and_hms_milli(19, 40, 9, 941));
assert_eq!(project.shared_runners_enabled, true);
assert_eq!(project.lfs_enabled, true);
......@@ -374,7 +374,7 @@ fn test_read_project_hook() {
assert_eq!(project_hook.id, HookId::new(1262));
assert_eq!(project_hook.url, "http://kwrobot02:8082/gitlab.kitware.com");
assert_eq!(project_hook.created_at,
UTC.ymd(2016, 12, 16)
Utc.ymd(2016, 12, 16)
.and_hms_milli(16, 37, 24, 589));
assert_eq!(project_hook.push_events, true);
assert_eq!(project_hook.tag_push_events, true);
......@@ -396,13 +396,13 @@ fn test_read_repo_branch() {
assert_eq!(commit.author_email, "ben.boeckel@kitware.com");
assert_eq!(commit.author_name, "Ben Boeckel");
assert_eq!(commit.authored_date,
UTC.ymd(2017, 5, 24)
Utc.ymd(2017, 5, 24)
.and_hms_milli(19, 40, 9, 0));
assert_eq!(commit.committed_date,
UTC.ymd(2017, 5, 24)
Utc.ymd(2017, 5, 24)
.and_hms_milli(19, 40, 14, 0));
assert_eq!(commit.created_at,
UTC.ymd(2017, 5, 24)
Utc.ymd(2017, 5, 24)
.and_hms_milli(19, 40, 14, 0));
assert_eq!(commit.committer_email, "kwrobot@kitware.com");
assert_eq!(commit.committer_name, "Kitware Robot");
......@@ -439,7 +439,7 @@ fn test_read_repo_commit_detail() {
assert_eq!(repo_commit_detail.committer_name, "Kitware Robot");
assert_eq!(repo_commit_detail.committer_email, "kwrobot@kitware.com");
assert_eq!(repo_commit_detail.created_at,
UTC.ymd(2016, 11, 8)
Utc.ymd(2016, 11, 8)
.and_hms_milli(14, 30, 13, 0));
assert_eq!(repo_commit_detail.message,
"Merge topic 'mr-awards'\n\na222c553 gitlab: add a method for MR award \
......@@ -451,10 +451,10 @@ fn test_read_repo_commit_detail() {
ObjectId::new("a222c5539569cda6999b8069f1e51a5202c30711"),
]);
assert_eq!(repo_commit_detail.committed_date,
UTC.ymd(2016, 11, 8)
Utc.ymd(2016, 11, 8)
.and_hms_milli(14, 30, 13, 0));
assert_eq!(repo_commit_detail.authored_date,
UTC.ymd(2016, 11, 8)
Utc.ymd(2016, 11, 8)
.and_hms_milli(14, 30, 13, 0));
assert_eq!(repo_commit_detail.stats.additions, 8);
assert_eq!(repo_commit_detail.stats.deletions, 0);
......@@ -473,7 +473,7 @@ fn test_read_user() {
"https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon");
assert_eq!(user.web_url, "https://gitlab.kitware.com/kwrobot");
assert_eq!(user.created_at,
UTC.ymd(2015, 2, 26)
Utc.ymd(2015, 2, 26)
.and_hms_milli(15, 58, 34, 670));
assert_eq!(user.bio, Some("".to_string()));
assert_eq!(user.location, None);
......@@ -497,7 +497,7 @@ fn test_read_user_public() {
assert_eq!(user_public.web_url,
"https://gitlab.kitware.com/kwrobot");
assert_eq!(user_public.created_at,
UTC.ymd(2015, 2, 26)
Utc.ymd(2015, 2, 26)
.and_hms_milli(15, 58, 34, 670));
assert_eq!(user_public.bio, Some("".to_string()));
assert_eq!(user_public.location, None);
......@@ -507,18 +507,18 @@ fn test_read_user_public() {
assert_eq!(user_public.website_url, "");
assert_eq!(user_public.organization, None);
assert_eq!(user_public.last_sign_in_at,
Some(UTC.ymd(2017, 4, 27)
Some(Utc.ymd(2017, 4, 27)
.and_hms_milli(14, 59, 16, 823)));
assert_eq!(user_public.last_activity_on,
Some(NaiveDate::from_ymd(2017, 6, 6)));
assert_eq!(user_public.confirmed_at,
UTC.ymd(2015, 2, 26)
Utc.ymd(2015, 2, 26)
.and_hms_milli(15, 58, 34, 660));
assert_eq!(user_public.email, "kwrobot@kitware.com");
assert_eq!(user_public.color_scheme_id, ColorSchemeId::new(4));
assert_eq!(user_public.projects_limit, 50);
assert_eq!(user_public.current_sign_in_at,
Some(UTC.ymd(2017, 6, 5)
Some(Utc.ymd(2017, 6, 5)
.and_hms_milli(18, 46, 29, 512)));
assert!(user_public.identities.is_empty());
assert_eq!(user_public.can_create_group, true);
......
This diff is collapsed.
......@@ -13,7 +13,7 @@
//! Gitlab does not have consistent structures for its hooks, so they often change from
//! version to version.
use crates::chrono::{DateTime, NaiveDate, TimeZone, UTC};
use crates::chrono::{DateTime, NaiveDate, TimeZone, Utc};
use crates::serde::{Deserialize, Deserializer, Serialize, Serializer};
use crates::serde::de::{Error, Unexpected};
use crates::serde_json::{self, Value};
......@@ -26,7 +26,7 @@ use types::{BuildId, IssueId, IssueState, MergeRequestId, MergeRequestState, Mer
///
/// Gitlab does not use a standard date format for dates in web hooks. This structure supports
/// deserializing the formats that have been observed.
pub struct HookDate(DateTime<UTC>);
pub struct HookDate(DateTime<Utc>);
impl Serialize for HookDate {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
......@@ -40,21 +40,21 @@ impl<'de> Deserialize<'de> for HookDate {
{
let val = String::deserialize(deserializer)?;
UTC.datetime_from_str(&val, "%Y-%m-%d %H:%M:%S UTC")
Utc.datetime_from_str(&val, "%Y-%m-%d %H:%M:%S UTC")
.or_else(|_| {
DateTime::parse_from_str(&val, "%Y-%m-%d %H:%M:%S %z")
.map_err(|err| {
D::Error::invalid_value(Unexpected::Other("hook date"),
&format!("{:?}", err).as_str())
})
.map(|dt| dt.with_timezone(&UTC))
.map(|dt| dt.with_timezone(&Utc))
})
.map(HookDate)
}
}
impl AsRef<DateTime<UTC>> for HookDate {
fn as_ref(&self) -> &DateTime<UTC> {
impl AsRef<DateTime<Utc>> for HookDate {
fn as_ref(&self) -> &DateTime<Utc> {
&self.0
}
}
......@@ -135,7 +135,7 @@ pub struct CommitHookAttrs {
pub id: ObjectId,
/// The commit message.
pub message: String,
pub timestamp: DateTime<UTC>,
pub timestamp: DateTime<Utc>,
/// The URL of the commit.
pub url: String,
/// The author of the commit.
......
Markdown is supported
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