aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2025-02-19 11:12:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2025-02-19 11:12:16 +0200
commit87837b7aea82b817d61460601e76e7ae587ad31d (patch)
tree54fa293c2e8d2b2d8c2230551d7c608fe4fb47b5
parentef9deaa518ee80420f7eed8af011a69f865583fb (diff)
Sketch
-rw-r--r--mod/mod-ci-github-gh.hxx5
-rw-r--r--mod/mod-ci-github-gq.cxx36
-rw-r--r--mod/mod-ci-github-gq.hxx5
-rw-r--r--mod/mod-ci-github.cxx4
4 files changed, 36 insertions, 14 deletions
diff --git a/mod/mod-ci-github-gh.hxx b/mod/mod-ci-github-gh.hxx
index 5f6e5b7..13cbd2f 100644
--- a/mod/mod-ci-github-gh.hxx
+++ b/mod/mod-ci-github-gh.hxx
@@ -84,6 +84,11 @@ namespace brep
string name;
string status;
+ // Check suite node id this check runs belongs to. Note: only returned
+ // in certain cases thus optional.
+ //
+ optional<string> check_suite_node_id;
+
explicit
gh_check_run (json::parser&);
diff --git a/mod/mod-ci-github-gq.cxx b/mod/mod-ci-github-gq.cxx
index d49dfa2..f5e510c 100644
--- a/mod/mod-ci-github-gq.cxx
+++ b/mod/mod-ci-github-gq.cxx
@@ -396,8 +396,9 @@ namespace brep
// Send a GraphQL mutation request `rq` that creates (create=true) or
// updates (create=false) one or more check runs. The requested build state
// is taken from each check_run object. Update the check runs in `crs` with
- // the new data (state, node ID if unset, and state_synced). Return false
- // and issue diagnostics if the request failed.
+ // the new data (state, node ID if unset, and state_synced). Return nullopt
+ // and issue diagnostics if the request failed. Return check suite node id
+ // if creating a single check run and empty string otherwise.
//
struct gq_create_data
{
@@ -406,7 +407,7 @@ namespace brep
reference_wrapper<const string> head_sha;
};
- static bool
+ static optional<string>
gq_mutate_check_runs (const basic_mark& error,
check_runs::iterator crs_b,
check_runs::iterator crs_e,
@@ -416,6 +417,8 @@ namespace brep
{
size_t crs_n (crs_e - crs_b);
+ bool check_suite_node_id (create_data && crs_n == 1);
+
const char* what (nullptr);
try
{
@@ -458,7 +461,8 @@ namespace brep
gq_query_get_check_runs (create_data->app_id,
create_data->repository_id,
create_data->head_sha,
- crs_n)));
+ crs_n,
+ check_suite_node_id))); // @@ TODO: need cs node id.
// Type that parses the result of the above GraphQL query.
//
@@ -545,7 +549,14 @@ namespace brep
cr.state_synced = (rst == st);
}
- return true;
+ if (check_suite_node_id)
+ {
+ optional<string>& r (rcrs.front ().check_suite_node_id);
+ assert (r);
+ return move (r);
+ }
+ else
+ return string ();
}
else
error << "unexpected number of check_run objects in response";
@@ -594,7 +605,7 @@ namespace brep
error << "unable to " << what << " check runs: " << e;
}
- return false;
+ return nullopt;
}
// Serialize `createCheckRun` mutations for one or more builds to GraphQL.
@@ -868,7 +879,7 @@ namespace brep
return true;
}
- bool
+ optional<string>
gq_create_check_run (const basic_mark& error,
check_run& cr,
const string& iat,
@@ -896,11 +907,12 @@ namespace brep
brep::check_runs crs {move (cr)};
crs[0].state = st;
- bool r (gq_mutate_check_runs (error,
- crs.begin (), crs.end (),
- iat,
- move (rq),
- gq_create_data {ai, rid, hs}));
+ optional<string> r (
+ gq_mutate_check_runs (error,
+ crs.begin (), crs.end (),
+ iat,
+ move (rq),
+ gq_create_data {ai, rid, hs}));
cr = move (crs[0]);
diff --git a/mod/mod-ci-github-gq.hxx b/mod/mod-ci-github-gq.hxx
index 2a8138a..77b78e4 100644
--- a/mod/mod-ci-github-gq.hxx
+++ b/mod/mod-ci-github-gq.hxx
@@ -47,7 +47,8 @@ namespace brep
// conclusion is required.
//
// Update `cr` with the new data (node id, state, and state_synced). Return
- // false and issue diagnostics if the request failed.
+ // nullopt and issue diagnostics if the request failed. Return the check
+ // suite node id otherwise (so can be used as bool).
//
// Throw invalid_argument if the passed data is invalid, missing, or
// inconsistent.
@@ -55,7 +56,7 @@ namespace brep
// If the details_url is absent GitHub will use the app's homepage. Title
// and summary are required and cannot be empty.
//
- bool
+ optional<string>
gq_create_check_run (const basic_mark& error,
check_run& cr,
const string& installation_access_token,
diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx
index d53c46e..c61ef0d 100644
--- a/mod/mod-ci-github.cxx
+++ b/mod/mod-ci-github.cxx
@@ -2008,6 +2008,8 @@ namespace brep
// Let unlikely invalid_argument propagate (see above).
//
+ // @@ TODO: get check suite node id.
+ //
if (gq_create_check_run (error,
cr,
iat->token,
@@ -2182,6 +2184,8 @@ namespace brep
if (!cni.empty ())
sd.conclusion_node_id = cni;
+ //@@ TODO: save check suite node id.
+
return sd.json ();
};
}