Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire acad105e21 App
- Fixed logging ref
2023-07-06 19:56:10 +02:00
Tristan B. Velloza Kildaire 56a2f6f91d App
- Handle tags by doing nothing for now - better than crashing
2023-07-06 19:55:43 +02:00
1 changed files with 32 additions and 16 deletions

View File

@ -57,26 +57,42 @@ void commitHandler(HTTPServerRequest request, HTTPServerResponse response)
JSONValue json = parseJSON(request.json().toString());
writeln(json.toPrettyString());
/* Extract the commit */
JSONValue commitBlock = json["commits"].array()[0];
string commitMessage = strip(commitBlock["message"].str());
string commitURL = commitBlock["url"].str();
string commitID = commitBlock["id"].str();
/* Extract the commits (if any) */
JSONValue[] commits = json["commits"].array();
JSONValue authorBlock = commitBlock["author"];
string authorName = authorBlock["name"].str();
string authorEmail = authorBlock["email"].str();
/**
* A tag push will have no commits,
* for now ignore those. Only react
* if we have at least one commit and
* then react to the first one listed.
*/
if(commits.length > 0)
{
/* Extract the commit */
JSONValue commitBlock = json["commits"].array()[0];
string commitMessage = strip(commitBlock["message"].str());
string commitURL = commitBlock["url"].str();
string commitID = commitBlock["id"].str();
string repositoryName = json["repository"]["full_name"].str();
/* Extract JUST the repository's name */
toChannel = associations[json["repository"]["name"].str()];
JSONValue authorBlock = commitBlock["author"];
string authorName = authorBlock["name"].str();
string authorEmail = authorBlock["email"].str();
string repositoryName = json["repository"]["full_name"].str();
string ircMessage = bold("["~repositoryName~"]")~" New commit "~commitMessage~" ("~commitID~") by "~italics(authorName)~" ("~authorEmail~") ["~underline(commitURL)~"]";
ircBot.channelMessage(ircMessage, toChannel); //TODO: Add IRC error handling
/* Extract JUST the repository's name */
toChannel = associations[json["repository"]["name"].str()];
string ircMessage = bold("["~repositoryName~"]")~" New commit "~commitMessage~" ("~commitID~") by "~italics(authorName)~" ("~authorEmail~") ["~underline(commitURL)~"]";
ircBot.channelMessage(ircMessage, toChannel); //TODO: Add IRC error handling
/* Send message to NTFY server */
notifySH(ircMessage);
/* Send message to NTFY server */
notifySH(ircMessage);
}
else
{
logger.warn("Ignoring /commit triggered but with empty commits");
}
}
catch(Exception e)
{