From cf0929f3afac32f27e191afbd8ee6b30eba5ad1a Mon Sep 17 00:00:00 2001 From: Francois Kritzinger Date: Tue, 5 Nov 2024 13:42:39 +0200 Subject: Implement handle_check_run_request() --- mod/mod-ci-github.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++++ mod/mod-ci-github.hxx | 8 ++++++++ 2 files changed, 53 insertions(+) (limited to 'mod') diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx index 0b04791..d5c2e74 100644 --- a/mod/mod-ci-github.cxx +++ b/mod/mod-ci-github.cxx @@ -334,6 +334,41 @@ namespace brep return true; } } + else if (event == "check_run") + { + gh_check_run_event cr; + try + { + json::parser p (body.data (), body.size (), "check_run event"); + + cr = gh_check_run_event (p); + } + catch (const json::invalid_json_input& e) + { + string m ("malformed JSON in " + e.name + " request body"); + + error << m << ", line: " << e.line << ", column: " << e.column + << ", byte offset: " << e.position << ", error: " << e; + + throw invalid_request (400, move (m)); + } + + if (cr.action == "rerequested") + { + // Someone manually requested to re-run a specific check run. + // + return handle_check_run_request (move (cr), warning_success); + } + else + { + // Ignore unknown actions by sending a 200 response with empty body + // but also log as an error since we want to notice new actions. + // + error << "unknown action '" << cr.action << "' in check_run event"; + + return true; + } + } else if (event == "pull_request") { gh_pull_request_event pr; @@ -585,6 +620,16 @@ namespace brep return true; } + bool ci_github:: + handle_check_run_request (gh_check_run_event cr, bool warning_success) + { + HANDLER_DIAG; + + l3 ([&]{trace << "check_run event { " << cr << " }";}); + + return true; + } + // Miscellaneous pull request facts // // - Although some of the GitHub documentation makes it sound like they diff --git a/mod/mod-ci-github.hxx b/mod/mod-ci-github.hxx index 8284f7f..45b97d5 100644 --- a/mod/mod-ci-github.hxx +++ b/mod/mod-ci-github.hxx @@ -83,6 +83,14 @@ namespace brep bool handle_check_suite_request (gh_check_suite_event, bool warning_success); + // Handle the check_run event `rerequested` action. + // + // If warning_success is true, then map result_status::warning to SUCCESS + // and to FAILURE otherwise. + // + bool + handle_check_run_request (gh_check_run_event, bool warning_success); + // Handle the pull_request event `opened` and `synchronize` actions. // // If warning_success is true, then map result_status::warning to SUCCESS -- cgit v1.1