mirror of
https://github.com/matrix-construct/construct
synced 2024-11-21 17:31:21 +01:00
modules/web_hook: Add post-push handler for reacting to push events.
This commit is contained in:
parent
e5ae70c521
commit
0624b69246
1 changed files with 119 additions and 27 deletions
|
@ -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 ")
|
||||
|
@ -1626,6 +1632,44 @@ try
|
|||
github_run_rerun(repopath, run_id);
|
||||
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 &)
|
||||
{
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue