aboutsummaryrefslogtreecommitdiff
path: root/mod/mod-ci-github-service-data.hxx
diff options
context:
space:
mode:
authorFrancois Kritzinger <francois@codesynthesis.com>2024-12-10 16:27:24 +0200
committerFrancois Kritzinger <francois@codesynthesis.com>2024-12-10 16:32:40 +0200
commitc7cb981910fd97128ca5e3f7aa77355a18a56738 (patch)
tree1a93dd62a9ee676cf62253af28f849f0f61da28b /mod/mod-ci-github-service-data.hxx
parenteedef97cd9679ae68d7c989f194d957a35a00dd1 (diff)
Handle queued, building notifications
Diffstat (limited to 'mod/mod-ci-github-service-data.hxx')
-rw-r--r--mod/mod-ci-github-service-data.hxx92
1 files changed, 92 insertions, 0 deletions
diff --git a/mod/mod-ci-github-service-data.hxx b/mod/mod-ci-github-service-data.hxx
new file mode 100644
index 0000000..0d94b55
--- /dev/null
+++ b/mod/mod-ci-github-service-data.hxx
@@ -0,0 +1,92 @@
+// file : mod/mod-ci-github-service-data.hxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#ifndef MOD_MOD_CI_GITHUB_SERVICE_DATA_HXX
+#define MOD_MOD_CI_GITHUB_SERVICE_DATA_HXX
+
+#include <libbrep/types.hxx>
+#include <libbrep/utility.hxx>
+
+#include <mod/mod-ci-github-gh.hxx>
+
+namespace brep
+{
+ // Service data associated with the tenant (corresponds to GH check suite).
+ //
+ // It is always a top-level JSON object and the first member is always the
+ // schema version.
+
+ // Unsynchronized state means we were unable to (conclusively) notify
+ // GitHub about the last state transition (e.g., due to a transient
+ // network error). The "conclusively" part means that the notification may
+ // or may not have gone through. Note: node_id can be absent for the same
+ // reason.
+ //
+ struct check_run
+ {
+ string build_id; // Full build id.
+ optional<string> node_id; // GitHub id.
+
+ build_state state;
+ bool state_synced;
+
+ string
+ state_string () const
+ {
+ string r (to_string (state));
+ if (!state_synced)
+ r += "(unsynchronized)";
+ return r;
+ }
+ };
+
+ struct service_data
+ {
+ // The data schema version. Note: must be first member in the object.
+ //
+ uint64_t version = 1;
+
+ // Check suite-global data.
+ //
+ gh_installation_access_token installation_access;
+
+ uint64_t installation_id;
+
+ string repository_node_id; // GitHub-internal opaque repository id.
+
+ string head_sha;
+
+ vector<check_run> check_runs;
+
+ // Return the check run with the specified build ID or nullptr if not
+ // found.
+ //
+ check_run*
+ find_check_run (const string& build_id);
+
+ // Construct from JSON.
+ //
+ // Throw invalid_argument if the schema version is not supported.
+ //
+ explicit
+ service_data (const string& json);
+
+ service_data (string iat_token,
+ timestamp iat_expires_at,
+ uint64_t installation_id,
+ string repository_node_id,
+ string head_sha);
+
+ service_data () = default;
+
+ // Serialize to JSON.
+ //
+ string
+ json () const;
+ };
+
+ ostream&
+ operator<< (ostream&, const check_run&);
+}
+
+#endif // MOD_MOD_CI_GITHUB_SERVICE_DATA_HXX