diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-10-24 14:45:19 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-10-24 14:45:19 +0200 |
commit | 1bfb0c463d49e939dabc71fbb6adbc154915e619 (patch) | |
tree | 3d61531d5e9eedf7bf253c43e25567391c4d7fe2 /mod | |
parent | 7728e2469fdf49307231d57a9fc5a2cf60aa535a (diff) |
Sketch
Diffstat (limited to 'mod')
-rw-r--r-- | mod/ci-common.cxx | 26 | ||||
-rw-r--r-- | mod/ci-common.hxx | 10 | ||||
-rw-r--r-- | mod/mod-ci-github-gh.hxx | 2 | ||||
-rw-r--r-- | mod/mod-ci-github.cxx | 33 |
4 files changed, 64 insertions, 7 deletions
diff --git a/mod/ci-common.cxx b/mod/ci-common.cxx index 11d55af..5b039ef 100644 --- a/mod/ci-common.cxx +++ b/mod/ci-common.cxx @@ -856,4 +856,30 @@ namespace brep return s; } + + optional<tenant_service> ci_start:: + find (odb::core::database& db, + const string& type, + const string& id) const + { + using namespace odb::core; + + assert (!transaction::has_current ()); + + transaction tr (db.begin ()); + + using query = query<build_tenant>; + + shared_ptr<build_tenant> t ( + db.query_one<build_tenant> (query::service.id == id && + query::service.type == type)); + + tr.commit (); + + optional<tenant_service> r; + if (t != nullptr) + r = move (t->service); + + return r; + } } diff --git a/mod/ci-common.hxx b/mod/ci-common.hxx index d155398..1703ae0 100644 --- a/mod/ci-common.hxx +++ b/mod/ci-common.hxx @@ -205,6 +205,16 @@ namespace brep optional<build_state> rebuild (odb::core::database&, const build_id&) const; + // Find the tenant given the tenant service type and id and return the + // associated data or nullopt if there is no such tenant. + // + // Note: should be called out of the database transaction. + // + optional<tenant_service> + find (odb::core::database&, + const string& type, + const string& id) const; + // Helpers. // diff --git a/mod/mod-ci-github-gh.hxx b/mod/mod-ci-github-gh.hxx index 001353d..3cbdb77 100644 --- a/mod/mod-ci-github-gh.hxx +++ b/mod/mod-ci-github-gh.hxx @@ -47,7 +47,7 @@ namespace brep struct gh_check_suite { string node_id; - string head_branch; + string head_branch; // @@ Make optional (can be NULL). string head_sha; explicit diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx index c1c31ae..4694599 100644 --- a/mod/mod-ci-github.cxx +++ b/mod/mod-ci-github.cxx @@ -473,15 +473,36 @@ namespace brep // string sid (cs.repository.node_id + ":" + cs.check_suite.head_sha); + // If the user requests a rebuilt of the (entire) PR, then this manifests + // as check_suite rather than pull_request event. Specifically: + // + // - For a local PR, this event is shared with the branch push and all we + // need to do is restart the CI for the head commit. + // + // - For a remote PR, this event will have no gh_check_suite::head_branch. + // In this case we need to load the existing service data for this head + // commit, extract the test merge commit, and restart the CI for that. + // + string check_sha; + + bool re_requested (cs.action == "rerequested"); + if (re_requested && !cs.check_suite.head_branch) + { + // @@ TODO: load data, copy check_sha. + } + else + check_sha = cs.check_suite.head_sha; + + // @@ Add check/report sha member to both ctors. + // service_data sd (warning_success, iat->token, iat->expires_at, cs.installation.id, move (cs.repository.node_id), - service_data::local, - false /* pre_check */, - cs.action == "rerequested" /* re_request */, - move (cs.check_suite.head_sha)); + service_data::local, false /* pre_check */, re_requested, + move (check_sha), + move (cs.check_suite.head_sha) /* report_sha */); // If this check suite is being re-run, replace the existing CI request if // it exists; otherwise create a new one, doing nothing if a request @@ -698,8 +719,6 @@ namespace brep // job might actually still be relevant (in both local and remote PR // cases). - // @@ TODO: what happens when the entire PR build is re-requested? - // @@ TODO Serialize the new service_data fields! // @@ -711,6 +730,8 @@ namespace brep ? service_data::local : service_data::remote); + // Note that PR rebuilds (re-requested) are handled by check_suite(). + // // Note that check_sha will be set later, in build_unloaded_pre_check(). // service_data sd (warning_success, |