Unverified Commit 7df8fedb authored by Jonas Bulik's avatar Jonas Bulik
Browse files

add PipelineHook type


Signed-off-by: default avatarJonas Bulik <jonas@bulik.dev>
parent 8725f030
# (unreleased) v0.1302.3
## Additions
- Added `gitlab::webhooks::PipelineHook`
# v0.1302.2
## Additions
......
{
"object_kind": "pipeline",
"object_attributes": {
"id": 187788219,
"ref": "1-test",
"tag": false,
"sha": "17dd664bfcda26cd14c5ecad518c16c7ef62b618",
"before_sha": "0000000000000000000000000000000000000000",
"source": "merge_request_event",
"status": "success",
"detailed_status": "passed",
"stages": [
"build",
"test",
"deploy"
],
"created_at": "2020-09-09 10:24:13 UTC",
"finished_at": "2020-09-09 10:25:09 UTC",
"duration": 51,
"variables": []
},
"merge_request": {
"id": 70293529,
"iid": 1,
"title": "Draft: Resolve \"test\"",
"source_branch": "1-test",
"source_project_id": 21026315,
"target_branch": "master",
"target_project_id": 21026315,
"state": "opened",
"merge_status": "unchecked",
"url": "https://gitlab.com/mr.example/webhook-testing/-/merge_requests/1"
},
"user": {
"name": "Example User",
"username": "mr.example",
"avatar_url": null,
"email": "example@web.com"
},
"project": {
"id": 21026315,
"name": "webhook-testing",
"description": "",
"web_url": "https://gitlab.com/mr.example/webhook-testing",
"avatar_url": null,
"git_ssh_url": "git@gitlab.com:mr.example/webhook-testing.git",
"git_http_url": "https://gitlab.com/mr.example/webhook-testing.git",
"namespace": "Example User",
"visibility_level": 0,
"path_with_namespace": "mr.example/webhook-testing",
"default_branch": "master",
"ci_config_path": ""
},
"commit": {
"id": "17dd664bfcda26cd14c5ecad518c16c7ef62b618",
"message": "Update .gitlab-ci.yml",
"title": "Update .gitlab-ci.yml",
"timestamp": "2020-09-09T10:24:11+00:00",
"url": "https://gitlab.com/mr.example/webhook-testing/-/commit/17dd664bfcda26cd14c5ecad518c16c7ef62b618",
"author": {
"name": "Example User",
"email": "example@web.com"
}
},
"builds": [
{
"id": 728716900,
"stage": "deploy",
"name": "deploy1",
"status": "success",
"created_at": "2020-09-09 10:24:13 UTC",
"started_at": "2020-09-09 10:24:51 UTC",
"finished_at": "2020-09-09 10:25:09 UTC",
"when": "on_success",
"manual": false,
"allow_failure": false,
"user": {
"name": "Example User",
"username": "mr.example",
"avatar_url": null,
"email": "example@web.com"
},
"runner": {
"id": 380987,
"description": "shared-runners-manager-6.gitlab.com",
"active": true,
"is_shared": true
},
"artifacts_file": {
"filename": null,
"size": null
}
},
{
"id": 728716897,
"stage": "test",
"name": "test1",
"status": "success",
"created_at": "2020-09-09 10:24:13 UTC",
"started_at": "2020-09-09 10:24:33 UTC",
"finished_at": "2020-09-09 10:24:50 UTC",
"when": "on_success",
"manual": false,
"allow_failure": false,
"user": {
"name": "Example User",
"username": "mr.example",
"avatar_url": null,
"email": "example@web.com"
},
"runner": {
"id": 44949,
"description": "shared-runners-manager-4.gitlab.com",
"active": true,
"is_shared": true
},
"artifacts_file": {
"filename": null,
"size": null
}
},
{
"id": 728716898,
"stage": "test",
"name": "test2",
"status": "success",
"created_at": "2020-09-09 10:24:13 UTC",
"started_at": "2020-09-09 10:24:33 UTC",
"finished_at": "2020-09-09 10:24:49 UTC",
"when": "on_success",
"manual": false,
"allow_failure": false,
"user": {
"name": "Example User",
"username": "mr.example",
"avatar_url": null,
"email": "example@web.com"
},
"runner": {
"id": 380987,
"description": "shared-runners-manager-6.gitlab.com",
"active": true,
"is_shared": true
},
"artifacts_file": {
"filename": null,
"size": null
}
},
{
"id": 728716896,
"stage": "build",
"name": "build1",
"status": "success",
"created_at": "2020-09-09 10:24:13 UTC",
"started_at": "2020-09-09 10:24:14 UTC",
"finished_at": "2020-09-09 10:24:30 UTC",
"when": "on_success",
"manual": false,
"allow_failure": false,
"user": {
"name": "Example User",
"username": "mr.example",
"avatar_url": null,
"email": "example@web.com"
},
"runner": {
"id": 44949,
"description": "shared-runners-manager-4.gitlab.com",
"active": true,
"is_shared": true
},
"artifacts_file": {
"filename": null,
"size": null
}
}
]
}
......@@ -8,6 +8,8 @@ use chrono::{TimeZone, Utc};
use serde_json::from_str;
use crate::webhooks::*;
use std::fs::File;
use std::io::BufReader;
#[test]
fn test_hookdate_deserialize() {
......@@ -27,3 +29,16 @@ fn test_hookdate_deserialize() {
Utc.ymd(2019, 3, 1).and_hms_milli(22, 50, 2, 36),
);
}
#[test]
fn test_pipeline_hook() {
let file = File::open("src/test/examples/pipeline.json").unwrap();
let reader = BufReader::new(file);
let pipeline: PipelineHook = serde_json::from_reader(reader).unwrap();
assert_eq!(pipeline.object_kind, "pipeline");
assert_eq!(pipeline.user.username, "mr.example");
assert_eq!(
pipeline.object_attributes.before_sha,
"0000000000000000000000000000000000000000"
);
}
......@@ -19,8 +19,8 @@ use serde_json::{self, Value};
use crate::types::{
IssueId, IssueInternalId, IssueState, JobId, MergeRequestId, MergeRequestInternalId,
MergeRequestState, MergeStatus, MilestoneId, NoteId, NoteType, NoteableId, ObjectId, ProjectId,
SnippetId, UserId,
MergeRequestState, MergeStatus, MilestoneId, NoteId, NoteType, NoteableId, ObjectId,
PipelineId, ProjectId, RunnerId, SnippetId, StatusState, UserId,
};
/// A wrapper struct for dates in web hooks.
......@@ -700,6 +700,114 @@ pub struct BuildHook {
pub repository: BuildProjectHookAttrs,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineVariable {
/// Environment variable key
pub key: String,
/// Environment variable value
pub value: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineHookAttrs {
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,
pub before_sha: String,
/// Was this pipeline triggered by a tag.
pub tag: bool,
/// When the pipeline was created.
pub created_at: HookDate,
/// When the pipeline completed.
pub finished_at: Option<HookDate>,
/// Duration of pipeline in seconds.
pub duration: Option<u64>,
/// What triggered the pipeline.
pub source: String,
/// The stages of the pipeline.
pub stages: Vec<String>,
/// Environment variables manually set by the user starting the pipeline.
pub variables: Vec<PipelineVariable>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineBuildRunner {
/// The runner id.
pub id: RunnerId,
/// The runner description
pub description: String,
/// Whether the runner is active.
pub active: bool,
/// Whether the runner is shared.
pub is_shared: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineMergeRequestAttrs {
pub id: MergeRequestId,
pub iid: MergeRequestInternalId,
/// The title of the merge request.
pub title: String,
/// The target branch of the merge request.
pub target_branch: String,
/// The ID of the target project.
pub target_project_id: ProjectId,
/// The source branch of the merge request.
pub source_branch: String,
/// The ID of the source project.
pub source_project_id: Option<ProjectId>,
pub state: MergeRequestState,
pub merge_status: MergeStatus,
pub url: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineProjectAttrs {
pub id: ProjectId,
/// The display name of the project.
pub name: String,
/// The description of the project.
pub description: Option<String>,
/// The URL for the project's homepage.
pub web_url: String,
/// The URL to the project avatar.
pub avatar_url: Option<String>,
/// The URL to clone the repository over SSH.
pub git_ssh_url: String,
/// The URL to clone the repository over HTTPS.
pub git_http_url: String,
/// The namespace the project lives in.
pub namespace: String,
/// Integral value for the project's visibility.
pub visibility_level: u64,
/// The path to the project's repository with its namespace.
pub path_with_namespace: String,
/// The default branch for the project.
pub default_branch: Option<String>,
pub ci_config_path: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineHook {
/// The event which occured.
pub object_kind: String,
/// The pipeline.
pub object_attributes: PipelineHookAttrs,
/// The merge request this pipeline is running for.
pub merge_request: Option<PipelineMergeRequestAttrs>,
/// The user that started the the pipeline.
pub user: UserHookAttrs,
/// The project this pipeline is running in.
pub project: PipelineProjectAttrs,
/// The commit this pipeline is running for
pub commit: Option<CommitHookAttrs>,
}
/// A wiki page hook.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct WikiPageHook {
......@@ -728,6 +836,8 @@ pub enum WebHook {
Note(Box<NoteHook>),
/// A build hook.
Build(Box<BuildHook>),
/// A pipeline hook.
Pipeline(Box<PipelineHook>),
/// A wiki page hook.
WikiPage(Box<WikiPageHook>),
}
......@@ -767,6 +877,8 @@ impl<'de> Deserialize<'de> for WebHook {
"build" => serde_json::from_value(val).map(|hook| WebHook::Build(Box::new(hook))),
"pipeline" => serde_json::from_value(val).map(|hook| WebHook::Pipeline(Box::new(hook))),
_ => {
return Err(D::Error::invalid_value(
Unexpected::Other("object kind"),
......
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