Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nicholas Bailey
rust-gitlab
Commits
08395fbf
Commit
08395fbf
authored
Aug 26, 2019
by
Dan Anderson dan.hillier.anderson@gmail.com
Committed by
Brad King
Sep 16, 2019
Browse files
types: add pipeline api types
parent
7134adce
Changes
6
Hide whitespace changes
Inline
Side-by-side
data/fetch_from_gitlab.py
View file @
08395fbf
...
...
@@ -33,6 +33,7 @@ ISSUE_ID = 6 # https://gitlab.kitware.com/utils/rust-gitlab/issues/6
MR_ID
=
35
# https://gitlab.kitware.com/utils/rust-gitlab/merge_requests/35
MR_DISCUSSION_ID
=
158
# https://gitlab.kitware.com/utils/rust-gitlab/merge_requests/35
NOTE_ID
=
177359
PIPELINE_ID
=
145400
if
__name__
==
'__main__'
:
...
...
@@ -54,3 +55,7 @@ if __name__ == '__main__':
write_result
(
token
,
'discussion'
,
'/projects/%s/merge_requests/%d/discussions'
%
(
REPO
,
MR_ID
),
dumpall
=
True
)
write_result
(
token
,
'award_emoji'
,
'/projects/%s/merge_requests/%d/notes/%d/award_emoji'
%
(
REPO
,
MR_ID
,
NOTE_ID
))
write_result
(
token
,
'resource_label_event'
,
'/projects/%s/issues/%d/resource_label_events'
%
(
REPO
,
ISSUE_ID
))
write_result
(
token
,
'pipeline_basic'
,
'/projects/%s/pipelines'
%
REPO
)
write_result
(
token
,
'pipeline'
,
'/projects/%s/pipelines/%d'
%
(
REPO
,
PIPELINE_ID
))
# FIXME: these are hidden behind a `403 forbidden`, so we use a hardcoded example instead.
# write_result(token, 'pipeline_variable', '/projects/%s/pipelines/%d/variables' % (REPO, PIPELINE_ID))
data/pipeline.json
0 → 100644
View file @
08395fbf
{
"before_sha"
:
null
,
"committed_at"
:
null
,
"coverage"
:
null
,
"created_at"
:
"2019-09-03T14:09:47.178-04:00"
,
"detailed_status"
:
{
"details_path"
:
"/utils/rust-gitlab/pipelines/145400"
,
"favicon"
:
"/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
,
"group"
:
"success"
,
"has_details"
:
true
,
"icon"
:
"status_success"
,
"illustration"
:
null
,
"label"
:
"passed"
,
"text"
:
"passed"
,
"tooltip"
:
"passed"
},
"duration"
:
0
,
"finished_at"
:
"2019-09-03T14:15:47.013-04:00"
,
"id"
:
145400
,
"ref"
:
"master"
,
"sha"
:
"7134adce4522c399cdab16e128b0a1af15b93f14"
,
"started_at"
:
"2019-09-03T14:09:51.465-04:00"
,
"status"
:
"success"
,
"tag"
:
false
,
"updated_at"
:
"2019-09-03T14:15:47.018-04:00"
,
"user"
:
{
"avatar_url"
:
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
,
"id"
:
35
,
"name"
:
"buildbot"
,
"state"
:
"active"
,
"username"
:
"buildbot"
,
"web_url"
:
"https://gitlab.kitware.com/buildbot"
},
"web_url"
:
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
,
"yaml_errors"
:
null
}
data/pipeline_basic.json
0 → 100644
View file @
08395fbf
{
"id"
:
145400
,
"ref"
:
"master"
,
"sha"
:
"7134adce4522c399cdab16e128b0a1af15b93f14"
,
"status"
:
"success"
,
"web_url"
:
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
}
data/pipeline_variable.json
0 → 100644
View file @
08395fbf
{
"key"
:
"RUN_NIGHTLY_BUILD"
,
"variable_type"
:
"env_var"
,
"value"
:
"true"
}
src/test/types.rs
View file @
08395fbf
...
...
@@ -6,7 +6,7 @@
use
crates
::
chrono
::{
NaiveDate
,
TimeZone
,
Utc
};
use
crates
::
serde
::
de
::
DeserializeOwned
;
use
crates
::
serde_json
::
from_reader
;
use
crates
::
serde_json
::
{
from_reader
,
json
}
;
use
types
::
*
;
...
...
@@ -867,3 +867,68 @@ fn test_read_resoruce_label_events() {
assert_eq!
(
label
.color
,
LabelColor
::
from_rgb
(
0x58
,
0x43
,
0xAD
));
assert_eq!
(
label
.description
,
Some
(
"Documentation issues"
.to_string
()));
}
#[test]
fn
test_read_pipelines
()
{
let
pipeline_basic
:
PipelineBasic
=
read_test_file
(
"pipeline_basic"
);
assert_eq!
(
pipeline_basic
.id
,
PipelineId
::
new
(
145400
));
assert_eq!
(
pipeline_basic
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline_basic
.ref_
,
Some
(
"master"
.to_string
()));
assert_eq!
(
pipeline_basic
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()));
assert_eq!
(
pipeline_basic
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
);
}
#[test]
fn
test_read_pipeline
()
{
let
pipeline
:
Pipeline
=
read_test_file
(
"pipeline"
);
assert_eq!
(
pipeline
.id
,
PipelineId
::
new
(
145400
));
assert_eq!
(
pipeline
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline
.ref_
,
Some
(
"master"
.to_string
()));
assert_eq!
(
pipeline
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()));
assert_eq!
(
pipeline
.before_sha
,
None
);
assert_eq!
(
pipeline
.tag
,
false
);
assert_eq!
(
pipeline
.yaml_errors
,
None
);
assert_eq!
(
pipeline
.created_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
47
,
178
)));
assert_eq!
(
pipeline
.updated_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
18
)));
assert_eq!
(
pipeline
.started_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
51
,
465
)));
assert_eq!
(
pipeline
.finished_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
13
)));
assert_eq!
(
pipeline
.committed_at
,
None
);
assert_eq!
(
pipeline
.duration
,
Some
(
0
));
assert_eq!
(
pipeline
.coverage
,
None
);
assert_eq!
(
pipeline
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
);
// nested user
assert_eq!
(
pipeline
.user.avatar_url
,
Some
(
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
.to_owned
()));
assert_eq!
(
pipeline
.user.id
,
UserId
::
new
(
35
));
assert_eq!
(
pipeline
.user.name
,
"buildbot"
);
assert_eq!
(
pipeline
.user.username
,
"buildbot"
);
assert_eq!
(
pipeline
.user.state
,
UserState
::
Active
);
assert_eq!
(
pipeline
.user.web_url
,
"https://gitlab.kitware.com/buildbot"
);
// nested detailed status
assert_eq!
(
pipeline
.detailed_status
,
json!
({
"details_path"
:
"/utils/rust-gitlab/pipelines/145400"
,
"favicon"
:
"/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
,
"group"
:
"success"
,
"has_details"
:
true
,
"icon"
:
"status_success"
,
"illustration"
:
null
,
"label"
:
"passed"
,
"text"
:
"passed"
,
"tooltip"
:
"passed"
}),
);
}
#[test]
fn
test_read_pipeline_variables
()
{
let
var
:
PipelineVariable
=
read_test_file
(
"pipeline_variable"
);
assert_eq!
(
var
.key
,
"RUN_NIGHTLY_BUILD"
);
assert_eq!
(
var
.variable_type
,
PipelineVariableType
::
EnvVar
);
assert_eq!
(
var
.value
,
"true"
);
}
src/types.rs
View file @
08395fbf
...
...
@@ -2563,6 +2563,78 @@ pub struct PipelineBasic {
pub
web_url
:
String
,
}
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// More information about a pipeline in Gitlab CI.
pub
struct
Pipeline
{
/// The ID of the pipeline.
pub
id
:
PipelineId
,
/// The object ID that was tested.
pub
sha
:
ObjectId
,
#[serde(rename
=
"ref"
)]
/// The name of the reference that was tested.
pub
ref_
:
Option
<
String
>
,
/// The status of the pipeline.
pub
status
:
StatusState
,
/// The URL to the pipeline page.
pub
web_url
:
String
,
/// FIXME What are the semantics of this field?
pub
before_sha
:
Option
<
ObjectId
>
,
/// Was this pipeline triggered by a tag.
pub
tag
:
bool
,
/// Error returned by the parser of `gitlab-ci.yml`, if any.
pub
yaml_errors
:
Option
<
String
>
,
/// When the pipeline was created.
pub
created_at
:
Option
<
DateTime
<
Utc
>>
,
/// When the pipeline was last updated.
pub
updated_at
:
Option
<
DateTime
<
Utc
>>
,
/// When the pipeline began running.
pub
started_at
:
Option
<
DateTime
<
Utc
>>
,
/// When the pipeline completed.
pub
finished_at
:
Option
<
DateTime
<
Utc
>>
,
/// FIXME What are the semantics of this field?
pub
committed_at
:
Option
<
DateTime
<
Utc
>>
,
/// Duration of pipeline in seconds.
pub
duration
:
Option
<
u64
>
,
/// FIXME What are the semantics of this field?
pub
coverage
:
Option
<
String
>
,
/// The user who triggered this pipeline.
pub
user
:
UserBasic
,
/// FIXME: What are the semantics of this field?
/// See <https://gitlab.com/gitlab-org/gitlab-foss/blob/master/app/serializers/detailed_status_entity.rb>.
pub
detailed_status
:
Value
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord)]
pub
enum
PipelineVariableType
{
EnvVar
,
File
,
}
enum_serialize!
(
PipelineVariableType
->
"variable type"
,
EnvVar
=>
"env_var"
,
File
=>
"file"
,
);
impl
Default
for
PipelineVariableType
{
fn
default
()
->
Self
{
PipelineVariableType
::
EnvVar
}
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A pipeline variable.
pub
struct
PipelineVariable
{
/// Name of the variable.
pub
key
:
String
,
/// Value of the variable.
pub
value
:
String
,
/// Type of the variable (eg. `env_var`).
#[serde(default)]
pub
variable_type
:
PipelineVariableType
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone,
Copy,
PartialEq,
Eq)]
/// Type-safe label event ID.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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