Merge pull request #4 from deavmi/safe_channel_associations

Safe channel associations
This commit is contained in:
Tristan B. Velloza Kildaire 2023-10-24 18:43:07 +02:00 committed by GitHub
commit ad26b04e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 2 deletions

View File

@ -81,7 +81,7 @@ void commitHandler(HTTPServerRequest request, HTTPServerResponse response)
string repositoryName = json["repository"]["full_name"].str();
/* Extract JUST the repository's name */
toChannel = associations[json["repository"]["name"].str()];
toChannel = getRespectiveChannel(json["repository"]["name"].str());
string ircMessage = bold("["~repositoryName~"]")~setForeground(SimpleColor.GREEN)~" New commit "~resetForegroundBackground()~commitMessage~" ("~commitID~") by "~italics(authorName)~" ("~authorEmail~") ["~underline(commitURL)~"]";
ircBot.channelMessage(ircMessage, toChannel); //TODO: Add IRC error handling
@ -128,7 +128,7 @@ void issueHandler(HTTPServerRequest request, HTTPServerResponse response)
string repositoryName = issueBlock["repository"]["full_name"].str();
/* Extract JUST the repository's name */
toChannel = associations[json["repository"]["name"].str()];
toChannel = getRespectiveChannel(json["repository"]["name"].str());
/* Opened a new issue */
if(cmp(issueAction, "opened") == 0)
@ -267,6 +267,30 @@ void notifySH(string message)
}
}
/**
* Given a repository's name this will look it
* up in the key-value store to find the respective
* channel that should be used to send the message to
*
* Params:
* repositoryName = the repository to lookup by
* Returns: the channel's name
* Throws:
* Exception = if the repository does not exist
* in the map
*/
private string getRespectiveChannel(string repositoryName)
{
string* channelName = repositoryName in associations;
if(channelName is null)
{
throw new Exception("No channel exists for repository '"~repositoryName~"'");
}
return *channelName;
}
void main()
{
string configFilePath;