aboutsummaryrefslogtreecommitdiff
path: root/mod/mod-ci-github-gh.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'mod/mod-ci-github-gh.cxx')
-rw-r--r--mod/mod-ci-github-gh.cxx77
1 files changed, 57 insertions, 20 deletions
diff --git a/mod/mod-ci-github-gh.cxx b/mod/mod-ci-github-gh.cxx
index 6372ef0..99e19cc 100644
--- a/mod/mod-ci-github-gh.cxx
+++ b/mod/mod-ci-github-gh.cxx
@@ -7,6 +7,15 @@
namespace brep
{
+ [[noreturn]] static void
+ throw_json (const json::parser& p, const string& m)
+ {
+ throw json::invalid_json_input (
+ p.input_name,
+ p.line (), p.column (), p.position (),
+ m);
+ }
+
// Return the GitHub check run status corresponding to a build_state.
//
string
@@ -44,15 +53,15 @@ namespace brep
switch (rs)
{
case result_status::success:
- return "SUCCESS";
+ return "success";
case result_status::warning:
- return warning_success ? "SUCCESS" : "FAILURE";
+ return warning_success ? "success" : "failure";
case result_status::error:
case result_status::abort:
case result_status::abnormal:
- return "FAILURE";
+ return "failure";
// Valid values we should never encounter.
//
@@ -102,10 +111,7 @@ namespace brep
[[noreturn]] static void
missing_member (const json::parser& p, const char* o, const char* m)
{
- throw json::invalid_json_input (
- p.input_name,
- p.line (), p.column (), p.position (),
- o + string (" object is missing member '") + m + '\'');
+ throw_json (p, o + string (" object is missing member '") + m + '\'');
}
using event = json::event;
@@ -117,7 +123,7 @@ namespace brep
{
p.next_expect (event::begin_object);
- bool ni (false), hb (false), hs (false);
+ bool ni (false), hb (false), hs (false), cc (false), co (false);
// Skip unknown/uninteresting members.
//
@@ -136,12 +142,22 @@ namespace brep
head_branch = *v;
}
else if (c (hs, "head_sha")) head_sha = p.next_expect_string ();
+ else if (c (cc, "latest_check_runs_count"))
+ check_runs_count = p.next_expect_number <size_t> ();
+ else if (c (co, "conclusion"))
+ {
+ string* v (p.next_expect_string_null ());
+ if (v != nullptr)
+ conclusion = *v;
+ }
else p.next_expect_value_skip ();
}
if (!ni) missing_member (p, "gh_check_suite", "node_id");
if (!hb) missing_member (p, "gh_check_suite", "head_branch");
if (!hs) missing_member (p, "gh_check_suite", "head_sha");
+ if (!cc) missing_member (p, "gh_check_suite", "latest_check_runs_count");
+ if (!co) missing_member (p, "gh_check_suite", "conclusion");
}
ostream&
@@ -149,7 +165,9 @@ namespace brep
{
os << "node_id: " << cs.node_id
<< ", head_branch: " << (cs.head_branch ? *cs.head_branch : "null")
- << ", head_sha: " << cs.head_sha;
+ << ", head_sha: " << cs.head_sha
+ << ", latest_check_runs_count: " << cs.check_runs_count
+ << ", conclusion: " << (cs.conclusion ? *cs.conclusion : "null");
return os;
}
@@ -350,7 +368,7 @@ namespace brep
{
p.next_expect (event::begin_object);
- bool ni (false), nm (false), fn (false), cu (false);
+ bool ni (false), fn (false), cu (false);
// Skip unknown/uninteresting members.
//
@@ -362,14 +380,12 @@ 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 (fn, "full_name")) path = p.next_expect_string ();
else if (c (cu, "clone_url")) clone_url = p.next_expect_string ();
else p.next_expect_value_skip ();
}
if (!ni) missing_member (p, "gh_repository", "node_id");
- if (!nm) missing_member (p, "gh_repository", "name");
if (!fn) missing_member (p, "gh_repository", "full_name");
if (!cu) missing_member (p, "gh_repository", "clone_url");
}
@@ -378,7 +394,6 @@ namespace brep
operator<< (ostream& os, const gh_repository& rep)
{
os << "node_id: " << rep.node_id
- << ", name: " << rep.name
<< ", path: " << rep.path
<< ", clone_url: " << rep.clone_url;
@@ -478,10 +493,6 @@ namespace brep
return p.name () == s ? (v = true) : false;
};
- // Pass true to gh_check_run() to indicate that the we're parsing a
- // webhook event or REST API response (in which case more fields are
- // expected to be present than in a GraphQL response).
- //
if (c (ac, "action")) action = p.next_expect_string ();
else if (c (cs, "check_run")) check_run = gh_check_run_ex (p);
else if (c (rp, "repository")) repository = gh_repository (p);
@@ -513,7 +524,7 @@ namespace brep
{
p.next_expect (event::begin_object);
- bool ac (false), pr (false), rp (false), in (false);
+ bool ac (false), pr (false), bf (false), rp (false), in (false);
// Skip unknown/uninteresting members.
//
@@ -526,6 +537,7 @@ namespace brep
if (c (ac, "action")) action = p.next_expect_string ();
else if (c (pr, "pull_request")) pull_request = gh_pull_request (p);
+ else if (c (bf, "before")) before = p.next_expect_string ();
else if (c (rp, "repository")) repository = gh_repository (p);
else if (c (in, "installation")) installation = gh_installation (p);
else p.next_expect_value_skip ();
@@ -542,6 +554,7 @@ namespace brep
{
os << "action: " << pr.action;
os << ", pull_request { " << pr.pull_request << " }";
+ os << ", before: " << (pr.before ? *pr.before : "null");
os << ", repository { " << pr.repository << " }";
os << ", installation { " << pr.installation << " }";
@@ -575,7 +588,29 @@ namespace brep
};
if (c (tk, "token")) token = p.next_expect_string ();
- else if (c (ea, "expires_at")) expires_at = gh_from_iso8601 (p.next_expect_string ());
+ else if (c (ea, "expires_at"))
+ {
+ string v (p.next_expect_string ());
+
+ try
+ {
+ expires_at = gh_from_iso8601 (v);
+ }
+ catch (const invalid_argument& e)
+ {
+ throw_json (p,
+ "invalid IAT expires_at value '" + v +
+ "': " + e.what ());
+ }
+ catch (const system_error& e)
+ {
+ // Translate for simplicity.
+ //
+ throw_json (p,
+ "unable to convert IAT expires_at value '" + v +
+ "': " + e.what ());
+ }
+ }
else p.next_expect_value_skip ();
}
@@ -610,6 +645,8 @@ namespace brep
timestamp
gh_from_iso8601 (const string& s)
{
- return butl::from_string (s.c_str (), "%Y-%m-%dT%TZ", false /* local */);
+ return butl::from_string (s.c_str (),
+ "%Y-%m-%dT%TZ",
+ false /* local */);
}
}