modules/web_hook: Add hook/shot request suite.

This commit is contained in:
Jason Volk 2023-04-16 13:45:40 -07:00
parent 4c06793980
commit 79f5e4fd8d
1 changed files with 85 additions and 0 deletions

View File

@ -848,6 +848,91 @@ github_markdown(unique_const_buffer &buf,
);
}
static bool
github_hook_for_each(const string_view &repo,
const function_bool<json::object> &closure)
{
unique_const_buffer buf;
const json::array response
{
github_request
(
buf, "GET", repo, "hooks"
)
};
for(const json::object hook : response)
if(!closure(hook))
return false;
return true;
}
static void
github_hook_ping(const string_view &repo,
const string_view &hook)
{
unique_const_buffer buf;
github_request
(
buf, "POST", repo, "hooks/%s/pings",
hook
);
}
static void
github_hook_ping(const string_view &repo)
{
github_hook_for_each(repo, [&repo]
(const json::object &hook)
{
const json::string id
{
hook["id"]
};
github_hook_ping(repo, id);
});
}
static bool
github_hook_shot_for_each(const string_view &repo,
const string_view &hook,
const bool &redelivery,
const function_bool<json::object> &closure)
{
unique_const_buffer buf;
const json::array response
{
github_request
(
//TODO: pagination token
buf, "GET", repo, "hooks/%s/deliveries?per_page=100",
hook
)
};
for(const json::object shot : response)
if(!closure(shot))
return false;
return true;
}
static void
github_hook_shot_retry(const string_view &repo,
const string_view &hook,
const string_view &id)
{
unique_const_buffer buf;
github_request
(
buf, "POST", repo, "hooks/%s/deliveries/%s/attempts",
hook,
id
);
}
static bool
github_run_for_each_jobs(const string_view &repo,
const string_view &run_id,