diff options
author | Francois Kritzinger <francois@codesynthesis.com> | 2025-02-19 14:15:27 +0200 |
---|---|---|
committer | Francois Kritzinger <francois@codesynthesis.com> | 2025-02-20 15:46:07 +0200 |
commit | 2abb3ab35426189a9c478564a6426680c7cd3af0 (patch) | |
tree | 503087a1aef7159d9c23baffa39acb58605c5422 | |
parent | 87837b7aea82b817d61460601e76e7ae587ad31d (diff) |
ci-github: Get check suite id when creating check run and save in service data
-rw-r--r-- | mod/mod-ci-github-gh.cxx | 9 | ||||
-rw-r--r-- | mod/mod-ci-github-gq.cxx | 43 | ||||
-rw-r--r-- | mod/mod-ci-github-service-data.cxx | 12 | ||||
-rw-r--r-- | mod/mod-ci-github-service-data.hxx | 4 | ||||
-rw-r--r-- | mod/mod-ci-github.cxx | 30 |
5 files changed, 69 insertions, 29 deletions
diff --git a/mod/mod-ci-github-gh.cxx b/mod/mod-ci-github-gh.cxx index 42afe1b..57c4700 100644 --- a/mod/mod-ci-github-gh.cxx +++ b/mod/mod-ci-github-gh.cxx @@ -268,6 +268,15 @@ namespace brep if (c (ni, "node_id")) node_id = p.next_expect_string (); else if (c (nm, "name")) name = p.next_expect_string (); else if (c (st, "status")) status = p.next_expect_string (); + // checkSuite is only present in some GraphQL responses and we select + // only the node id so there won't be any other members. + // + else if (p.name () == "checkSuite") + { + p.next_expect (event::begin_object); + check_suite_node_id = p.next_expect_member_string ("node_id"); + p.next_expect (event::end_object); + } else p.next_expect_value_skip (); } diff --git a/mod/mod-ci-github-gq.cxx b/mod/mod-ci-github-gq.cxx index f5e510c..24f8b47 100644 --- a/mod/mod-ci-github-gq.cxx +++ b/mod/mod-ci-github-gq.cxx @@ -230,7 +230,8 @@ namespace brep gq_query_get_check_runs (uint64_t ai, // App id const string& ri, // Repository id const string& ci, // Commit id - size_t cn) // Check run count + size_t cn, // Check run count + bool csi) // Get check suite node id { ostringstream os; @@ -272,14 +273,17 @@ namespace brep os << " checkRuns(last: " << gq_int (cn) << '\n' << " filterBy: {appId: " << gq_int (ai) << '\n' << " checkType: LATEST}) {" << '\n' - << " edges { node { node_id: id name status } }" << '\n' - << " }" /* checkRuns */ << '\n' - << " } }" /* node, edges */ << '\n' - << " }" /* checkSuites */ << '\n' - << " }" /* ... on Commit */ << '\n' - << " }" /* object */ << '\n' - << "}" /* ... on Repository */ << '\n' - << "}" /* node */ << '\n'; + << " edges { node { node_id: id name status" << '\n'; + if (csi) + os << " checkSuite { node_id: id }" << '\n'; + os << " } }" /* node, edges */ << '\n' + << " }" /* checkRuns */ << '\n' + << " } }" /* node, edges */ << '\n' + << " }" /* checkSuites */ << '\n' + << " }" /* ... on Commit */ << '\n' + << " }" /* object */ << '\n' + << "}" /* ... on Repository */ << '\n' + << "}" /* node */ << '\n'; os << '}' /* query */ << '\n'; @@ -462,7 +466,7 @@ namespace brep create_data->repository_id, create_data->head_sha, crs_n, - check_suite_node_id))); // @@ TODO: need cs node id. + check_suite_node_id))); // Type that parses the result of the above GraphQL query. // @@ -539,7 +543,7 @@ namespace brep error << "unexpected check_run status: received '" << rcr.status << "' but expected '" << gh_to_status (st) << '\''; - return false; // Fail because something is clearly very wrong. + return nullopt; // Fail because something is clearly very wrong. } if (!cr.node_id) @@ -702,9 +706,10 @@ namespace brep const string& hs, // Head SHA const optional<string>& du, // Details URL. const check_run& cr, - const string& st, // Check run status. - const string& ti, // Output title. - const string& su, // Output summary. + bool csi, // Get check suite node id + const string& st, // Check run status. + const string& ti, // Output title. + const string& su, // Output summary. optional<string> co = nullopt) // Conclusion. { // Ensure details URL is non-empty if present. @@ -747,8 +752,10 @@ namespace brep << " checkRun {" << '\n' << " node_id: id" << '\n' << " name" << '\n' - << " status" << '\n' - << " }" << '\n' + << " status" << '\n'; + if (csi) + os << " checkSuite { node_id: id }" << '\n'; + os << " }" << '\n' << "}" << '\n'; os << "}" << '\n'; @@ -900,6 +907,7 @@ namespace brep hs, du, cr, + true /* Get check suite node id */, gh_to_status (st), move (ti), move (su), nullopt /* conclusion */))); @@ -914,6 +922,8 @@ namespace brep move (rq), gq_create_data {ai, rid, hs})); + assert (!r || !r->empty ()); + cr = move (crs[0]); return r; @@ -935,6 +945,7 @@ namespace brep hs, du, cr, + false /* Get check suite id */, gh_to_status (build_state::built), move (br.title), move (br.summary), move (br.conclusion)))); diff --git a/mod/mod-ci-github-service-data.cxx b/mod/mod-ci-github-service-data.cxx index aa2e619..d165b02 100644 --- a/mod/mod-ci-github-service-data.cxx +++ b/mod/mod-ci-github-service-data.cxx @@ -71,6 +71,12 @@ namespace brep check_sha = p.next_expect_member_string ("check_sha"); report_sha = p.next_expect_member_string ("report_sha"); + { + string* s (p.next_expect_member_string_null ("check_suite_node_id")); + if (s != nullptr) + check_suite_node_id = *s; + } + p.next_expect_member_array ("check_runs"); while (p.next_expect (event::begin_object, event::end_array)) { @@ -265,6 +271,12 @@ namespace brep s.member ("check_sha", check_sha); s.member ("report_sha", report_sha); + s.member_name ("check_suite_node_id"); + if (check_suite_node_id) + s.value (*check_suite_node_id); + else + s.value (nullptr); + s.member_begin_array ("check_runs"); for (const check_run& cr: check_runs) { diff --git a/mod/mod-ci-github-service-data.hxx b/mod/mod-ci-github-service-data.hxx index 9aa512a..bd30386 100644 --- a/mod/mod-ci-github-service-data.hxx +++ b/mod/mod-ci-github-service-data.hxx @@ -125,6 +125,10 @@ namespace brep // string report_sha; + // GitHub-internal opaque check suite id. + // + optional<string> check_suite_node_id; + brep::check_runs check_runs; // Flag indicating that all the elements in check_runs are built and this diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx index c61ef0d..8f0af2e 100644 --- a/mod/mod-ci-github.cxx +++ b/mod/mod-ci-github.cxx @@ -1991,11 +1991,14 @@ namespace brep if (iat == nullptr) return nullptr; // Try again on the next call. + optional<string> check_suite_node_id; + // Create a synthetic check run with an in-progress state. Return the // check run on success or nullopt on failure. // auto create_synthetic_cr = [&tenant_id, iat, + &check_suite_node_id, &sd, &error, this] (string name, @@ -2008,17 +2011,16 @@ namespace brep // Let unlikely invalid_argument propagate (see above). // - // @@ TODO: get check suite node id. - // - if (gq_create_check_run (error, - cr, - iat->token, - sd.app_id, - sd.repository_node_id, - sd.report_sha, - details_url (tenant_id), - build_state::building, - title, summary)) + if (check_suite_node_id = gq_create_check_run (error, + cr, + iat->token, + sd.app_id, + sd.repository_node_id, + sd.report_sha, + details_url (tenant_id), + build_state::building, + title, + summary)) { return cr; } @@ -2156,6 +2158,7 @@ namespace brep return [&error, tenant_id, iat = move (new_iat), + csi = move (check_suite_node_id), cni = move (conclusion_node_id)] (const string& ti, const tenant_service& ts) -> optional<string> @@ -2181,11 +2184,12 @@ namespace brep if (iat) sd.installation_access = *iat; + if (csi) + sd.check_suite_node_id = *csi; + if (!cni.empty ()) sd.conclusion_node_id = cni; - //@@ TODO: save check suite node id. - return sd.json (); }; } |