From bebf346f1f3bb335dde5797e9982a9e10eb9937c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Casta=C3=B1o=20Arteaga?= Date: Tue, 10 Sep 2024 16:31:32 +0200 Subject: [PATCH] Update check run title (#43) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio CastaƱo Arteaga --- dco2/src/dco/event/mod.rs | 18 ++++++++++++++---- dco2/src/dco/event/tests.rs | 13 +++++++++++-- dco2/src/github/client.rs | 10 +++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/dco2/src/dco/event/mod.rs b/dco2/src/dco/event/mod.rs index ed7ebab..28a7816 100644 --- a/dco2/src/dco/event/mod.rs +++ b/dco2/src/dco/event/mod.rs @@ -16,8 +16,14 @@ mod tests; /// Name of the check that will be displayed in GitHub. const CHECK_NAME: &str = "DCO"; +/// Title of the check run when the check fails. +const CHECK_FAILED_TITLE: &str = "Check failed"; + +/// Title of the check run when the check passes. +const CHECK_PASSED_TITLE: &str = "Check passed!"; + /// Summary of the check when requested by a merge group. -const MERGE_GROUP_CHECKS_REQUESTED_SUMMARY: &str = "Check result set to passed for the merge group."; +const MERGE_GROUP_CHECKS_REQUESTED_SUMMARY: &str = "Check result set to passed for the merge group"; /// Identifier of the override action (set check result to passed). const OVERRIDE_ACTION_IDENTIFIER: &str = "override"; @@ -29,7 +35,7 @@ const OVERRIDE_ACTION_LABEL: &str = "Set DCO to pass"; const OVERRIDE_ACTION_DESCRIPTION: &str = "Manually set DCO check result to passed"; /// Summary of the override action. -const OVERRIDE_ACTION_SUMMARY: &str = "Check result was manually set to passed."; +const OVERRIDE_ACTION_SUMMARY: &str = "Check result was manually set to passed"; /// Process the GitHub webhook event provided, taking the appropriate action. pub async fn process_event(gh_client: DynGHClient, event: &Event) -> Result<()> { @@ -62,6 +68,7 @@ async fn process_check_run_event(gh_client: DynGHClient, event: &CheckRunEvent) started_at, status: CheckRunStatus::Completed, summary: OVERRIDE_ACTION_SUMMARY.to_string(), + title: OVERRIDE_ACTION_SUMMARY.to_string(), }); gh_client.create_check_run(&ctx, &check_run).await.context("error creating check run")?; } @@ -90,6 +97,7 @@ async fn process_merge_group_event(gh_client: DynGHClient, event: &MergeGroupEve started_at, status: CheckRunStatus::Completed, summary: MERGE_GROUP_CHECKS_REQUESTED_SUMMARY.to_string(), + title: MERGE_GROUP_CHECKS_REQUESTED_SUMMARY.to_string(), }); gh_client.create_check_run(&ctx, &check_run).await.context("error creating check run")?; @@ -142,11 +150,12 @@ async fn process_pull_request_event(gh_client: DynGHClient, event: &PullRequestE let output = check(&input); // Create check run - let (conclusion, actions) = if output.num_commits_with_errors == 0 { - (CheckRunConclusion::Success, vec![]) + let (conclusion, title, actions) = if output.num_commits_with_errors == 0 { + (CheckRunConclusion::Success, CHECK_PASSED_TITLE, vec![]) } else { ( CheckRunConclusion::ActionRequired, + CHECK_FAILED_TITLE, vec![CheckRunAction { label: OVERRIDE_ACTION_LABEL.to_string(), description: OVERRIDE_ACTION_DESCRIPTION.to_string(), @@ -163,6 +172,7 @@ async fn process_pull_request_event(gh_client: DynGHClient, event: &PullRequestE started_at, status: CheckRunStatus::Completed, summary: output.render().context("error rendering output template")?, + title: title.to_string(), }); gh_client.create_check_run(&ctx, &check_run).await.context("error creating check run")?; diff --git a/dco2/src/dco/event/tests.rs b/dco2/src/dco/event/tests.rs index ed65daa..9506811 100644 --- a/dco2/src/dco/event/tests.rs +++ b/dco2/src/dco/event/tests.rs @@ -1,8 +1,9 @@ use crate::{ dco::{ event::{ - CHECK_NAME, MERGE_GROUP_CHECKS_REQUESTED_SUMMARY, OVERRIDE_ACTION_DESCRIPTION, - OVERRIDE_ACTION_IDENTIFIER, OVERRIDE_ACTION_LABEL, OVERRIDE_ACTION_SUMMARY, + CHECK_FAILED_TITLE, CHECK_NAME, CHECK_PASSED_TITLE, MERGE_GROUP_CHECKS_REQUESTED_SUMMARY, + OVERRIDE_ACTION_DESCRIPTION, OVERRIDE_ACTION_IDENTIFIER, OVERRIDE_ACTION_LABEL, + OVERRIDE_ACTION_SUMMARY, }, process_event, }, @@ -98,6 +99,7 @@ async fn check_run_event_requested_action_override_error_creating_check_run() { && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed && check_run.summary() == OVERRIDE_ACTION_SUMMARY + && check_run.title() == OVERRIDE_ACTION_SUMMARY }) .times(1) .returning(|_, _| Box::pin(future::ready(Err(anyhow!("test error"))))); @@ -137,6 +139,7 @@ async fn check_run_event_requested_action_override_success() { && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed && check_run.summary() == OVERRIDE_ACTION_SUMMARY + && check_run.title() == OVERRIDE_ACTION_SUMMARY }) .times(1) .returning(|_, _| Box::pin(future::ready(Ok(())))); @@ -199,6 +202,7 @@ async fn merge_group_checks_requested_error_creating_check_run() { && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed && check_run.summary() == MERGE_GROUP_CHECKS_REQUESTED_SUMMARY + && check_run.title() == MERGE_GROUP_CHECKS_REQUESTED_SUMMARY }) .times(1) .returning(|_, _| Box::pin(future::ready(Err(anyhow!("test error"))))); @@ -237,6 +241,7 @@ async fn merge_group_checks_requested_success() { && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed && check_run.summary() == MERGE_GROUP_CHECKS_REQUESTED_SUMMARY + && check_run.title() == MERGE_GROUP_CHECKS_REQUESTED_SUMMARY }) .times(1) .returning(|_, _| Box::pin(future::ready(Ok(())))); @@ -506,6 +511,7 @@ async fn pull_request_event_opened_action_error_creating_check_run() { && check_run.head_sha() == "head_sha" && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed + && check_run.title() == CHECK_PASSED_TITLE }) .times(1) .returning(|_, _| Box::pin(future::ready(Err(anyhow!("test error"))))); @@ -580,6 +586,7 @@ async fn pull_request_event_opened_action_success_check_passed() { && check_run.head_sha() == "head_sha" && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed + && check_run.title() == CHECK_PASSED_TITLE }) .times(1) .returning(|_, _| Box::pin(future::ready(Ok(())))); @@ -660,6 +667,7 @@ async fn pull_request_event_opened_action_success_check_passed_author_is_member( && check_run.head_sha() == "head_sha" && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed + && check_run.title() == CHECK_PASSED_TITLE }) .times(1) .returning(|_, _| Box::pin(future::ready(Ok(())))); @@ -739,6 +747,7 @@ async fn pull_request_event_opened_action_success_check_failed() { && check_run.head_sha() == "head_sha" && check_run.name() == CHECK_NAME && check_run.status() == &CheckRunStatus::Completed + && check_run.title() == CHECK_FAILED_TITLE }) .times(1) .returning(|_, _| Box::pin(future::ready(Ok(())))); diff --git a/dco2/src/github/client.rs b/dco2/src/github/client.rs index bc940b9..981d3a6 100644 --- a/dco2/src/github/client.rs +++ b/dco2/src/github/client.rs @@ -114,7 +114,7 @@ impl GHClient for GHClientOctorust { images: vec![], summary: check_run.summary.clone(), text: String::new(), - title: check_run.name.clone(), + title: check_run.title.clone(), }), started_at: Some(check_run.started_at), status: Some(check_run.status.clone().into()), @@ -197,6 +197,7 @@ pub struct CheckRun { started_at: DateTime, status: CheckRunStatus, summary: String, + title: String, } impl CheckRun { @@ -212,6 +213,7 @@ impl CheckRun { started_at: input.started_at, status: input.status, summary: input.summary, + title: input.title, }; // Make sure the length of some fields is below the maximum allowed by @@ -290,6 +292,11 @@ impl CheckRun { pub fn summary(&self) -> &str { &self.summary } + + /// Get the title of the check run. + pub fn title(&self) -> &str { + &self.title + } } /// Check run action. @@ -518,4 +525,5 @@ pub struct NewCheckRunInput { pub started_at: DateTime, pub status: CheckRunStatus, pub summary: String, + pub title: String, }