Skip to content

Commit

Permalink
Update check run title (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Sep 10, 2024
1 parent 0eab700 commit bebf346
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
18 changes: 14 additions & 4 deletions dco2/src/dco/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<()> {
Expand Down Expand Up @@ -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")?;
}
Expand Down Expand Up @@ -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")?;

Expand Down Expand Up @@ -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(),
Expand All @@ -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")?;

Expand Down
13 changes: 11 additions & 2 deletions dco2/src/dco/event/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down Expand Up @@ -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")))));
Expand Down Expand Up @@ -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(()))));
Expand Down Expand Up @@ -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")))));
Expand Down Expand Up @@ -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(()))));
Expand Down Expand Up @@ -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")))));
Expand Down Expand Up @@ -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(()))));
Expand Down Expand Up @@ -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(()))));
Expand Down Expand Up @@ -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(()))));
Expand Down
10 changes: 9 additions & 1 deletion dco2/src/github/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -197,6 +197,7 @@ pub struct CheckRun {
started_at: DateTime<Utc>,
status: CheckRunStatus,
summary: String,
title: String,
}

impl CheckRun {
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -518,4 +525,5 @@ pub struct NewCheckRunInput {
pub started_at: DateTime<Utc>,
pub status: CheckRunStatus,
pub summary: String,
pub title: String,
}

0 comments on commit bebf346

Please sign in to comment.