From 4bcadc03c96bebd2391736e49c92b873d57cfc8e Mon Sep 17 00:00:00 2001 From: Francois Kritzinger Date: Fri, 26 Apr 2024 13:37:51 +0200 Subject: Post-review changes --- mod/mod-ci-github-gq.cxx | 76 ++++++++++++++++---------------------- mod/mod-ci-github-gq.hxx | 8 +--- mod/mod-ci-github-service-data.cxx | 5 ++- mod/mod-ci-github.cxx | 32 ++++++++-------- 4 files changed, 52 insertions(+), 69 deletions(-) (limited to 'mod') diff --git a/mod/mod-ci-github-gq.cxx b/mod/mod-ci-github-gq.cxx index bedf301..b9e5908 100644 --- a/mod/mod-ci-github-gq.cxx +++ b/mod/mod-ci-github-gq.cxx @@ -198,11 +198,11 @@ namespace brep // if unset. Return false and issue diagnostics if the request failed. // static bool - gq_mutate_check_runs (vector& crs, + gq_mutate_check_runs (const basic_mark& error, + vector& crs, const string& iat, string rq, - build_state st, - const basic_mark& error) noexcept + build_state st) noexcept { vector rcrs; @@ -321,12 +321,11 @@ namespace brep // 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>& bs, // Pass build ids. - build_state st, optional rs, - const build_queued_hints* bh) + gq_mutation_create_check_runs (const string& ri, // Repository ID + const string& hs, // Head SHA + const vector& crs, + build_state st, + optional rs = nullopt) { ostringstream os; @@ -334,25 +333,20 @@ namespace brep // Serialize a `createCheckRun` for each build. // - for (size_t i (0); i != bs.size (); ++i) + for (size_t i (0); i != crs.size (); ++i) { - const build& b (bs[i]); - string al ("cr" + to_string (i)); // Field alias. - // Check run name. - // - string nm (gh_check_run_name (b, bh)); - os << gq_name (al) << ":createCheckRun(input: {" << '\n' - << " name: " << gq_str (nm) << ',' << '\n' + << " name: " << gq_str (crs[i].name) << ',' << '\n' << " repositoryId: " << gq_str (ri) << ',' << '\n' << " headSha: " << gq_str (hs) << ',' << '\n' << " status: " << gq_enum (gh_to_status (st)); if (rs) { + // @@ TODO Pass valid boolean os << ',' << '\n' - << " conclusion: " << gq_enum (gh_to_conclusion (*rs)); + << " conclusion: " << gq_enum (gh_to_conclusion (*rs, false)); } os << "})" << '\n' // Specify the selection set (fields to be returned). @@ -391,8 +385,9 @@ namespace brep << " status: " << gq_enum (gh_to_status (st)); if (rs) { + // @@ TODO Pass valid boolean os << ',' << '\n' - << " conclusion: " << gq_enum (gh_to_conclusion (*rs)); + << " conclusion: " << gq_enum (gh_to_conclusion (*rs, false)); } os << "})" << '\n' // Specify the selection set (fields to be returned). @@ -410,51 +405,42 @@ namespace brep } bool - gq_create_check_runs (vector& crs, + gq_create_check_runs (const basic_mark& error, + vector& crs, const string& iat, const string& rid, const string& hs, - const vector>& bs, - build_state st, - const build_queued_hints& bh, - const basic_mark& error) + build_state st) { // 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, - nullopt /* result_status */, - &bh))); - - return gq_mutate_check_runs (crs, iat, move (rq), st, error); + gq_mutation_create_check_runs (rid, hs, crs, st))); + + return gq_mutate_check_runs (error, crs, iat, move (rq), st); } bool - gq_create_check_run (check_run& cr, + gq_create_check_run (const basic_mark& error, + check_run& cr, const string& iat, const string& rid, const string& hs, - const build& b, build_state st, - optional rs, - const build_queued_hints& bh, - const basic_mark& error) + optional rs) { // 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 crs {move (cr)}; - bool r (gq_mutate_check_runs (crs, iat, move (rq), st, error)); + string rq (gq_serialize_request ( + gq_mutation_create_check_runs (rid, hs, crs, st, rs))); + + bool r (gq_mutate_check_runs (error, crs, iat, move (rq), st)); cr = move (crs[0]); @@ -462,13 +448,13 @@ namespace brep } bool - gq_update_check_run (check_run& cr, + gq_update_check_run (const basic_mark& error, + check_run& cr, const string& iat, const string& rid, const string& nid, build_state st, - optional rs, - const basic_mark& error) + optional rs) { // Must have a result if state is built. // @@ -479,7 +465,7 @@ namespace brep vector crs {move (cr)}; - bool r (gq_mutate_check_runs (crs, iat, move (rq), st, error)); + bool r (gq_mutate_check_runs (error, crs, iat, move (rq), st)); cr = move (crs[0]); diff --git a/mod/mod-ci-github-gq.hxx b/mod/mod-ci-github-gq.hxx index 16117ea..33aeec4 100644 --- a/mod/mod-ci-github-gq.hxx +++ b/mod/mod-ci-github-gq.hxx @@ -29,9 +29,7 @@ namespace brep const string& installation_access_token, const string& repository_id, const string& head_sha, - const vector>&, - build_state, - const build_queued_hints&); + build_state); // Create a new check run on GitHub for a build. Update `cr` with the new // state and the node ID. Return false and issue diagnostics if the request @@ -48,10 +46,8 @@ namespace brep const string& installation_access_token, const string& repository_id, const string& head_sha, - const build&, build_state, - optional = nullopt, - const build_queued_hints&); + optional = nullopt); // Update a check run on GitHub. // diff --git a/mod/mod-ci-github-service-data.cxx b/mod/mod-ci-github-service-data.cxx index f79550c..a53f445 100644 --- a/mod/mod-ci-github-service-data.cxx +++ b/mod/mod-ci-github-service-data.cxx @@ -43,6 +43,7 @@ namespace brep while (p.next_expect (event::begin_object, event::end_array)) { string bid (p.next_expect_member_string ("build_id")); + string nm (p.next_expect_member_string ("name")); optional nid; { @@ -54,7 +55,7 @@ namespace brep build_state s (to_build_state (p.next_expect_member_string ("state"))); bool ss (p.next_expect_member_boolean ("state_synced")); - check_runs.emplace_back (move (bid), move (nid), s, ss); + check_runs.emplace_back (move (bid), move (nm), move (nid), s, ss); p.next_expect (event::end_object); } @@ -101,6 +102,7 @@ namespace brep { s.begin_object (); s.member ("build_id", cr.build_id); + s.member ("name", cr.name); s.member_name ("node_id"); if (cr.node_id) @@ -136,6 +138,7 @@ namespace brep { os << "node_id: " << cr.node_id.value_or ("null") << ", build_id: " << cr.build_id + << ", name: " << cr.name << ", state: " << cr.state_string (); return os; diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx index 3e6803e..644993b 100644 --- a/mod/mod-ci-github.cxx +++ b/mod/mod-ci-github.cxx @@ -501,6 +501,7 @@ namespace brep bs.push_back (b); crs.emplace_back (move (bid), + gh_check_run_name (b, &hs), nullopt, /* node_id */ build_state::queued, false /* state_synced */); @@ -537,13 +538,11 @@ namespace brep { // Create a check_run for each build. // - if (gq_create_check_runs (crs, + if (gq_create_check_runs (error, + crs, iat->token, sd.repository_id, sd.head_sha, - bs, - build_state::queued, - hs, - error)) + build_state::queued)) { for (const check_run& cr: crs) { @@ -675,13 +674,12 @@ namespace brep // if (iat != nullptr) { - if (gq_update_check_run (*cr, + if (gq_update_check_run (error, + *cr, iat->token, sd.repository_id, *cr->node_id, - build_state::building, - nullopt, /* result_status */ - error)) + build_state::building)) { // Do nothing further if the state was already built on GitHub (note // that this is based on the above-mentioned special GitHub semantics @@ -821,12 +819,13 @@ namespace brep { // Update existing check run to built. // - if (gq_update_check_run (cr, + if (gq_update_check_run (error, + cr, iat->token, sd.repository_id, *cr.node_id, - build_state::built, b.status, - error)) + build_state::built, + b.status)) { assert (cr.state == build_state::built); @@ -843,14 +842,13 @@ namespace brep // check run to the service data it will create another check run with // the shortened name which will never get to the built state. // - if (gq_create_check_run (cr, + if (gq_create_check_run (error, + cr, iat->token, sd.repository_id, sd.head_sha, - b, - build_state::built, b.status, - build_queued_hints (false, false), - error)) + build_state::built, + b.status)) { assert (cr.state == build_state::built); -- cgit v1.1