diff options
author | Francois Kritzinger <francois@codesynthesis.com> | 2024-04-26 07:18:33 +0200 |
---|---|---|
committer | Francois Kritzinger <francois@codesynthesis.com> | 2024-06-05 09:12:46 +0200 |
commit | 62a5da8b67ac0ea91a5bbe433d38b35f3dbd7f80 (patch) | |
tree | 178ba7405159283fe5d0ecfd159aad81fcda3b83 /mod | |
parent | 884a6c0b9cd625e18bc70864322d4c8093e1b56c (diff) |
Support GitHub conclusion in check run create/update
Diffstat (limited to 'mod')
-rw-r--r-- | mod/mod-ci-github-gh.cxx | 29 | ||||
-rw-r--r-- | mod/mod-ci-github-gh.hxx | 3 | ||||
-rw-r--r-- | mod/mod-ci-github-gq.cxx | 59 | ||||
-rw-r--r-- | mod/mod-ci-github-gq.hxx | 12 |
4 files changed, 92 insertions, 11 deletions
diff --git a/mod/mod-ci-github-gh.cxx b/mod/mod-ci-github-gh.cxx index 44eb7ca..5c4809c 100644 --- a/mod/mod-ci-github-gh.cxx +++ b/mod/mod-ci-github-gh.cxx @@ -41,6 +41,35 @@ namespace brep } string + gh_to_conclusion (result_status rs) + { + switch (rs) + { + case result_status::success: + case result_status::warning: + return "SUCCESS"; + + case result_status::error: + case result_status::abort: + case result_status::abnormal: + return "FAILURE"; + + // Valid values we should never encounter. + // + case result_status::skip: + case result_status::interrupt: + throw invalid_argument ("unexpected result_status value: " + + to_string (rs)); + + // Invalid value. + // + default: + throw invalid_argument ("invalid result_status value: " + + to_string (static_cast<int> (rs))); + } + } + + string gh_check_run_name (const build& b, const build_queued_hints* bh) { string r; diff --git a/mod/mod-ci-github-gh.hxx b/mod/mod-ci-github-gh.hxx index 7d10a15..45b5359 100644 --- a/mod/mod-ci-github-gh.hxx +++ b/mod/mod-ci-github-gh.hxx @@ -81,6 +81,9 @@ namespace brep build_state gh_from_status (const string&); + string + gh_to_conclusion (result_status); + // Create a check_run name from a build. If the second argument is not // NULL, return an abbreviated id if possible. // diff --git a/mod/mod-ci-github-gq.cxx b/mod/mod-ci-github-gq.cxx index 4a84f2b..4e13199 100644 --- a/mod/mod-ci-github-gq.cxx +++ b/mod/mod-ci-github-gq.cxx @@ -317,12 +317,15 @@ namespace brep // Serialize `createCheckRun` mutations for one or more builds to GraphQL. // + // The result_status is required if the build_state is built because GitHub + // does not allow a check run status of completed without a conclusion. + // static string gq_mutation_create_check_runs ( const string& ri, // Repository ID const string& hs, // Head SHA const vector<reference_wrapper<const build>>& bs, - build_state st, + build_state st, optional<result_status> rs, const build_queued_hints* bh) { ostringstream os; @@ -345,8 +348,13 @@ namespace brep << " name: " << gq_str (nm) << ',' << '\n' << " repositoryId: " << gq_str (ri) << ',' << '\n' << " headSha: " << gq_str (hs) << ',' << '\n' - << " status: " << gq_enum (gh_to_status (st)) << '\n' - << "})" << '\n' + << " status: " << gq_enum (gh_to_status (st)); + if (rs) + { + os << ',' << '\n' + << " conclusion: " << gq_enum (gh_to_conclusion (*rs)); + } + os << "})" << '\n' // Specify the selection set (fields to be returned). // << "{" << '\n' @@ -365,10 +373,14 @@ namespace brep // Serialize an `updateCheckRun` mutation for one build to GraphQL. // + // The result_status is required if the build_state is built because GitHub + // does not allow updating a check run to completed without a conclusion. + // static string gq_mutation_update_check_run (const string& ri, // Repository ID. const string& ni, // Node ID. - build_state st) + build_state st, + optional<result_status> rs) { ostringstream os; @@ -376,8 +388,13 @@ namespace brep << "cr0:updateCheckRun(input: {" << '\n' << " checkRunId: " << gq_str (ni) << ',' << '\n' << " repositoryId: " << gq_str (ri) << ',' << '\n' - << " status: " << gq_enum (gh_to_status (st)) << '\n' - << "})" << '\n' + << " status: " << gq_enum (gh_to_status (st)); + if (rs) + { + os << ',' << '\n' + << " conclusion: " << gq_enum (gh_to_conclusion (*rs)); + } + os << "})" << '\n' // Specify the selection set (fields to be returned). // << "{" << '\n' @@ -402,8 +419,17 @@ namespace brep const build_queued_hints& bh, const basic_mark& error) { + // No support for result_status so state cannot be built. + // + assert (st != build_state::built); + string rq (gq_serialize_request ( - gq_mutation_create_check_runs (rid, hs, bs, st, &bh))); + gq_mutation_create_check_runs (rid, + hs, + bs, + st, + nullopt /* result_status */, + &bh))); return gq_mutate_check_runs (crs, iat, move (rq), st, error); } @@ -415,12 +441,20 @@ namespace brep const string& hs, const build& b, build_state st, + optional<result_status> rs, const build_queued_hints& bh, const basic_mark& error) { + // Must have a result if state is built. + // + assert (st != build_state::built || rs); + + string rq (gq_serialize_request ( + gq_mutation_create_check_runs (rid, hs, {b}, st, rs, &bh))); + vector<check_run> crs {move (cr)}; - bool r (gq_create_check_runs (crs, iat, rid, hs, {b}, st, bh, error)); + bool r (gq_mutate_check_runs (crs, iat, move (rq), st, error)); cr = move (crs[0]); @@ -433,10 +467,15 @@ namespace brep const string& rid, const string& nid, build_state st, + optional<result_status> rs, const basic_mark& error) { - string rq ( - gq_serialize_request (gq_mutation_update_check_run (rid, nid, st))); + // Must have a result if state is built. + // + assert (st != build_state::built || rs); + + string rq (gq_serialize_request ( + gq_mutation_update_check_run (rid, nid, st, rs))); vector<check_run> crs {move (cr)}; diff --git a/mod/mod-ci-github-gq.hxx b/mod/mod-ci-github-gq.hxx index 3d8c6cc..9331b2b 100644 --- a/mod/mod-ci-github-gq.hxx +++ b/mod/mod-ci-github-gq.hxx @@ -37,6 +37,11 @@ namespace brep // state and the node ID. Return false and issue diagnostics if the request // failed. // + // The result_status is required if the build_state is built because GitHub + // does not allow a check run status of `completed` without a conclusion. + // + // @@ TODO Support output (title, summary, text). + // bool gq_create_check_run (check_run& cr, const string& installation_access_token, @@ -44,6 +49,7 @@ namespace brep const string& head_sha, const build&, build_state, + optional<result_status>, const build_queued_hints&, const basic_mark& error); @@ -53,7 +59,10 @@ namespace brep // with the new state. Return false and issue diagnostics if the request // failed. // - // @@ TODO Support conclusion, output, etc. + // The result_status is required if the build_state is built because GitHub + // does not allow updating a check run to `completed` without a conclusion. + // + // @@ TODO Support output (title, summary, text). // bool gq_update_check_run (check_run& cr, @@ -61,6 +70,7 @@ namespace brep const string& repository_id, const string& node_id, build_state, + optional<result_status>, const basic_mark& error); } |