Skip to content

Commit

Permalink
modules/web_hook: Add requests for workflows and dispatching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed May 1, 2023
1 parent 759871c commit e5ae70c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions modules/web_hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,33 @@ github_hook_shot_retry(const string_view &repo,
);
}

static bool
github_hook_shot_for_each_fail(const string_view &repo,
const string_view &hook,
const function_bool<json::object> &closure)
{
bool ret {true};
github_hook_shot_for_each(repo, hook, true, [&ret, &closure]
(const json::object &object)
{
if(object.at<bool>("redelivery"))
return true;

const json::string status
{
object["status"]
};

if(status == "OK")
return false;

ret = closure(object);
return ret;
});

return ret;
}

static bool
github_run_for_each_jobs(const string_view &repo,
const string_view &run_id,
Expand Down Expand Up @@ -992,6 +1019,59 @@ github_run_rerun_failed(const string_view &repo,
github_request(buf, "POST", repo, "actions/runs/%s/rerun-failed-jobs", run_id);
}

static void
github_run_dispatch(const string_view &repo,
const string_view &name,
const string_view &ref = "master",
const json::members inputs = {})
{
const json::strung content{json::members
{
{ "ref", ref },
{ "inputs", inputs },
}};

unique_const_buffer buf;
github_request(content, buf, "POST", repo, "actions/workflows/%s/dispatches", name);
}

static bool
github_flow_for_each(const string_view &repo,
const function_bool<json::object> &closure,
const bool active_only = true)
{
unique_const_buffer buf;
const json::object response
{
github_request
(
//TODO: pagination token
buf, "GET", repo, "actions/workflows?per_page=100&page=1"
)
};

const json::array workflows
{
response["workflows"]
};

for(const json::object flow : workflows)
{
const json::string state
{
flow["state"]
};

if(active_only && state != "active")
continue;

if(!closure(flow))
return false;
}

return true;
}

bool
github_handle__workflow_run(std::ostream &out,
std::ostream &alt,
Expand Down

0 comments on commit e5ae70c

Please sign in to comment.