0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-24 15:52:34 +01:00

modules/web_hook: Add post-push handler for reacting to push events.

This commit is contained in:
Jason Volk 2023-04-27 22:33:46 -07:00
parent e5ae70c521
commit 0624b69246

View file

@ -174,6 +174,10 @@ static bool
github_handle__push(std::ostream &,
const json::object &content);
static bool
github_post_handle__push(const m::event::id &,
const json::object &content);
static bool
github_handle__pull_request(std::ostream &,
const json::object &content);
@ -355,6 +359,9 @@ github_handle(client &client,
m::msghtml(room_id, user_id, view(out, buf[0]), view(alt, buf[1]), "m.notice")
};
if(type == "push")
github_post_handle__push(evid, request.content);
log::info
{
"Webhook [%s] '%s' delivered to %s %s",
@ -1591,9 +1598,8 @@ try
json::object{relates_content}.get("body")
};
if(!startswith(relates_body, "job status table "))
return;
if(startswith(relates_body, "job status table "))
{
const auto suffix
{
lstrip(relates_body, "job status table ")
@ -1627,6 +1633,44 @@ try
break;
}
}
else if(startswith(relates_body, "push by "))
{
const auto suffix
{
lstrip(relates_body, "push by ")
};
string_view token[5];
ircd::tokens(suffix, ' ', token);
const auto &[pusher, _by_, repo, _at_, commit] {token};
assert(pusher);
assert(repo);
assert(commit);
if(!repo)
return;
if(startswith(key, "▶️"))
{
const auto id
{
between(key, '(', ')')
};
const auto ref
{
// commit // hash not supported by github
"master"
};
github_run_dispatch(repo, id, ref, json::members
{
});
return;
}
}
}
catch(const ctx::interrupted &)
{
throw;
@ -1944,6 +1988,54 @@ github_handle__push(std::ostream &out,
return true;
}
static bool
github_post_handle__push(const m::event::id &push_event_id,
const json::object &content)
{
const m::user::id::buf _webhook_user
{
string_view{webhook_user}, my_host()
};
const auto _webhook_room
{
m::room_id(string_view(webhook_room))
};
const auto repo
{
github_repopath(content)
};
github_flow_for_each(repo, [&]
(const json::object &flow)
{
const json::string name
{
flow["name"]
};
const json::string id
{
flow["id"]
};
const fmt::bsprintf<128> key
{
"▶️ %s (%s)", name, id
};
const auto annote_id
{
m::annotate(_webhook_room, _webhook_user, push_event_id, string_view(key))
};
return true;
});
return true;
}
bool
github_handle__pull_request(std::ostream &out,
const json::object &content)