mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
modules/webhook: Use boolean return value from handlers to ignore event.
This commit is contained in:
parent
5238e919fa
commit
02e9651ab4
1 changed files with 85 additions and 71 deletions
|
@ -109,43 +109,43 @@ github_find_issue_number(const json::object &content);
|
||||||
static std::pair<string_view, string_view>
|
static std::pair<string_view, string_view>
|
||||||
github_find_party(const json::object &content);
|
github_find_party(const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__push(std::ostream &,
|
github_handle__push(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__pull_request(std::ostream &,
|
github_handle__pull_request(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__issue_comment(std::ostream &,
|
github_handle__issue_comment(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__issues(std::ostream &,
|
github_handle__issues(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__watch(std::ostream &,
|
github_handle__watch(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__star(std::ostream &,
|
github_handle__star(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__label(std::ostream &,
|
github_handle__label(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__organization(std::ostream &,
|
github_handle__organization(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__status(std::ostream &,
|
github_handle__status(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
static std::ostream &
|
static bool
|
||||||
github_handle__ping(std::ostream &,
|
github_handle__ping(std::ostream &,
|
||||||
const json::object &content);
|
const json::object &content);
|
||||||
|
|
||||||
|
@ -158,6 +158,12 @@ void
|
||||||
github_handle(client &client,
|
github_handle(client &client,
|
||||||
const resource::request &request)
|
const resource::request &request)
|
||||||
{
|
{
|
||||||
|
if(!string_view(webhook_room))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!string_view(webhook_user))
|
||||||
|
return;
|
||||||
|
|
||||||
const http::headers &headers
|
const http::headers &headers
|
||||||
{
|
{
|
||||||
request.head.headers
|
request.head.headers
|
||||||
|
@ -184,18 +190,6 @@ github_handle(client &client,
|
||||||
headers.at("X-GitHub-Delivery")
|
headers.at("X-GitHub-Delivery")
|
||||||
};
|
};
|
||||||
|
|
||||||
if(type == "status")
|
|
||||||
{
|
|
||||||
if(unquote(request["state"]) == "pending")
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!webhook_status_verbose) switch(hash(unquote(request["state"])))
|
|
||||||
{
|
|
||||||
case "failure"_: break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const unique_buffer<mutable_buffer> buf
|
const unique_buffer<mutable_buffer> buf
|
||||||
{
|
{
|
||||||
48_KiB
|
48_KiB
|
||||||
|
@ -206,28 +200,33 @@ github_handle(client &client,
|
||||||
|
|
||||||
github_heading(out, type, request.content);
|
github_heading(out, type, request.content);
|
||||||
|
|
||||||
if(type == "ping")
|
const bool ok
|
||||||
github_handle__ping(out, request.content);
|
{
|
||||||
else if(type == "push")
|
type == "ping"?
|
||||||
github_handle__push(out, request.content);
|
github_handle__ping(out, request.content):
|
||||||
else if(type == "pull_request")
|
type == "push"?
|
||||||
github_handle__pull_request(out, request.content);
|
github_handle__push(out, request.content):
|
||||||
else if(type == "issues")
|
type == "pull_request"?
|
||||||
github_handle__issues(out, request.content);
|
github_handle__pull_request(out, request.content):
|
||||||
else if(type == "issue_comment")
|
type == "issues"?
|
||||||
github_handle__issue_comment(out, request.content);
|
github_handle__issues(out, request.content):
|
||||||
else if(type == "watch")
|
type == "issue_comment"?
|
||||||
github_handle__watch(out, request.content);
|
github_handle__issue_comment(out, request.content):
|
||||||
else if(type == "star")
|
type == "watch"?
|
||||||
github_handle__star(out, request.content);
|
github_handle__watch(out, request.content):
|
||||||
else if(type == "label")
|
type == "star"?
|
||||||
github_handle__label(out, request.content);
|
github_handle__star(out, request.content):
|
||||||
else if(type == "organization")
|
type == "label"?
|
||||||
github_handle__organization(out, request.content);
|
github_handle__label(out, request.content):
|
||||||
else if(type == "status")
|
type == "organization"?
|
||||||
github_handle__status(out, request.content);
|
github_handle__organization(out, request.content):
|
||||||
|
type == "status"?
|
||||||
|
github_handle__status(out, request.content):
|
||||||
|
|
||||||
if(!string_view(webhook_room))
|
true // unhandled will just show heading
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!ok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto room_id
|
const auto room_id
|
||||||
|
@ -235,9 +234,6 @@ github_handle(client &client,
|
||||||
m::room_id(string_view(webhook_room))
|
m::room_id(string_view(webhook_room))
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!string_view(webhook_user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
const m::user::id::buf user_id
|
const m::user::id::buf user_id
|
||||||
{
|
{
|
||||||
string_view(webhook_user), my_host()
|
string_view(webhook_user), my_host()
|
||||||
|
@ -330,7 +326,7 @@ github_heading(std::ostream &out,
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__push(std::ostream &out,
|
github_handle__push(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -351,7 +347,7 @@ github_handle__push(std::ostream &out,
|
||||||
out << " " << unquote(content["ref"]);
|
out << " " << unquote(content["ref"]);
|
||||||
|
|
||||||
out << " deleted</font>";
|
out << " deleted</font>";
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(content["ref"])
|
if(content["ref"])
|
||||||
|
@ -407,10 +403,10 @@ github_handle__push(std::ostream &out,
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "</code></pre>";
|
out << "</code></pre>";
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::ostream &
|
bool
|
||||||
github_handle__pull_request(std::ostream &out,
|
github_handle__pull_request(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -600,10 +596,10 @@ github_handle__pull_request(std::ostream &out,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::ostream &
|
bool
|
||||||
github_handle__issues(std::ostream &out,
|
github_handle__issues(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -745,10 +741,10 @@ github_handle__issues(std::ostream &out,
|
||||||
out << "</ul>";
|
out << "</ul>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::ostream &
|
bool
|
||||||
github_handle__issue_comment(std::ostream &out,
|
github_handle__issue_comment(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -815,10 +811,10 @@ github_handle__issue_comment(std::ostream &out,
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__label(std::ostream &out,
|
github_handle__label(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -903,10 +899,10 @@ github_handle__label(std::ostream &out,
|
||||||
out << "</ul>";
|
out << "</ul>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__organization(std::ostream &out,
|
github_handle__organization(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -944,10 +940,10 @@ github_handle__organization(std::ostream &out,
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__status(std::ostream &out,
|
github_handle__status(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -956,6 +952,18 @@ github_handle__status(std::ostream &out,
|
||||||
content["state"]
|
content["state"]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(state == "pending")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!webhook_status_verbose) switch(hash(state))
|
||||||
|
{
|
||||||
|
case "failure"_:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const json::string &description
|
const json::string &description
|
||||||
{
|
{
|
||||||
content["description"]
|
content["description"]
|
||||||
|
@ -997,34 +1005,40 @@ github_handle__status(std::ostream &out,
|
||||||
<< "</font>"
|
<< "</font>"
|
||||||
;
|
;
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__watch(std::ostream &out,
|
github_handle__watch(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
const string_view action
|
const json::string &action
|
||||||
{
|
{
|
||||||
unquote(content["action"])
|
content["action"]
|
||||||
};
|
};
|
||||||
|
|
||||||
return out;
|
if(action != "started")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__star(std::ostream &out,
|
github_handle__star(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
const string_view action
|
const json::string &action
|
||||||
{
|
{
|
||||||
unquote(content["action"])
|
content["action"]
|
||||||
};
|
};
|
||||||
|
|
||||||
return out;
|
if(action != "created")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &
|
bool
|
||||||
github_handle__ping(std::ostream &out,
|
github_handle__ping(std::ostream &out,
|
||||||
const json::object &content)
|
const json::object &content)
|
||||||
{
|
{
|
||||||
|
@ -1032,7 +1046,7 @@ github_handle__ping(std::ostream &out,
|
||||||
<< unquote(content["zen"])
|
<< unquote(content["zen"])
|
||||||
<< "</code></pre>";
|
<< "</code></pre>";
|
||||||
|
|
||||||
return out;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Researched from yestifico bot
|
/// Researched from yestifico bot
|
||||||
|
|
Loading…
Reference in a new issue