forked from MathieuLamiot/TechTeamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from wp-media/MathieuLamiot/issue14
As a user, I want to be notified of the task I created so that I have…
- Loading branch information
Showing
14 changed files
with
262 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
This file contains an abstract class to provide basic functions for Slack factories, like handling tokens. | ||
""" | ||
|
||
from abc import ABCMeta | ||
from flask import current_app | ||
import sources.utils.Constants as cst | ||
|
||
|
||
class SlackFactoryAbstract(metaclass=ABCMeta): | ||
""" | ||
Class managing the business logic related to Github ProjectV2 items | ||
""" | ||
def __init__(self): | ||
""" | ||
The handler instanciates the objects it needed to complete the processing of the request. | ||
""" | ||
self.__slack_bot_user_token = None | ||
|
||
def _get_slack_bot_user_token(self, app_context): | ||
""" | ||
Returns the Slack Bot User token of the app. | ||
If not retrieved yet, it is retrieved from the Flask app configuration. | ||
""" | ||
if self.__slack_bot_user_token is None: | ||
app_context.push() # The factory usually runs in a dedicated thread, so Flask app context must be applied. | ||
self.__slack_bot_user_token = current_app.config[cst.APP_CONFIG_TOKEN_SLACK_BOT_USER_TOKEN] | ||
return self.__slack_bot_user_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
This module defines the factory for Slack messages (DM, public, etc.) | ||
""" | ||
import requests | ||
from sources.factories.SlackFactoryAbstract import SlackFactoryAbstract | ||
|
||
|
||
class SlackMessageFactory(SlackFactoryAbstract): | ||
""" | ||
Class managing the business logic related to Github ProjectV2 items | ||
""" | ||
def __init__(self): | ||
""" | ||
The handler instanciates the objects it needed to complete the processing of the request. | ||
""" | ||
SlackFactoryAbstract.__init__(self) | ||
self.post_message_url = 'https://slack.com/api/chat.postMessage' | ||
|
||
def post_message(self, app_context, channel, text): | ||
""" | ||
Sends a message 'text' to the 'channel' as the app. | ||
""" | ||
request_open_view_header = {"Content-type": "application/json", | ||
"Authorization": "Bearer " + self._get_slack_bot_user_token(app_context)} | ||
request_open_view_payload = {} | ||
request_open_view_payload['channel'] = channel | ||
request_open_view_payload['text'] = text | ||
requests.post(url=self.post_message_url, headers=request_open_view_header, | ||
json=request_open_view_payload, timeout=3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Defiens a dataclass for the parameters returned by Github after task creation | ||
""" | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class CreatedGithubTaskParam: | ||
""" | ||
Dataclass for all the parameters allowing to initiate a task | ||
""" | ||
item_id: str | ||
item_database_id: int | ||
project_number: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
Defiens a dataclass for the parameters to pass to GithubTaskHandler.init_github_task | ||
""" | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class InitGithubTaskParam: | ||
""" | ||
Dataclass for all the parameters allowing to initiate a task | ||
""" | ||
title: str | ||
body: str | ||
handle_immediately: bool = False | ||
assignee: str = 'no-assignee' | ||
initiator: str = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.