Webhooks¶
Github¶
Handle GitHub webhooks.
-
class
app.controller.webhook.github.core.GitHubWebhookHandler(db_facade, gh_face, config)¶ Encapsulate the handlers for all GitHub webhook events.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –config (
config.Config) –
-
__init__(db_facade, gh_face, config)¶ Give handlers access to the database.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –config (
config.Config) –
-
handle(request_body, xhub_signature, payload)¶ Verify and handle the webhook event.
- Parameters
request_body (
bytes) – Byte string of the request bodyxhub_signature (
str) – Hashed signature to validatepayload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]- Returns
appropriate ResponseTuple depending on the validity and type of webhook
-
verify_hash(request_body, xhub_signature)¶ Verify if a webhook event comes from GitHub.
- Parameters
request_body (
bytes) – Byte string of the request bodyxhub_signature (
str) – Hashed signature to validate
- Returns
True if the signature is valid, False otherwise
Define the abstract base class for a GitHub event handler.
-
class
app.controller.webhook.github.events.base.GitHubEventHandler(db_facade, gh_face, conf)¶ Define the properties and methods needed for a GitHub event handler.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –conf (
config.Config) –
-
__init__(db_facade, gh_face, conf)¶ Give handler access to the database facade.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –conf (
config.Config) –
-
abstract
handle(payload)¶ Handle a GitHub event.
- Parameters
payload (
typing.Dict[str,typing.Any]) –- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
abstract property
supported_action_list¶ Provide a list of all actions this handler can handle.
- Return type
typing.List[str]
Handle GitHub membership events.
-
class
app.controller.webhook.github.events.membership.MembershipEventHandler(db_facade, gh_face, conf)¶ Encapsulate the handler methods for GitHub membership events.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –conf (
config.Config) –
-
handle(payload)¶ Handle the event where a user is added or removed from a team.
- Parameters
payload (
typing.Dict[str,typing.Any]) –- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
mem_added(github_id, selected_team, team_name, github_username)¶ Help membership function if payload action is added.
- Parameters
github_id (
str) –selected_team (
app.model.team.Team) –team_name (
str) –github_username (
str) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
mem_remove(github_id, selected_team, team_name)¶ Help membership function if payload action is removal.
- Parameters
github_id (
str) –selected_team (
app.model.team.Team) –team_name (
str) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
Handle GitHub organization events.
-
class
app.controller.webhook.github.events.organization.OrganizationEventHandler(db_facade, gh_face, conf)¶ Encapsulate the handler methods for GitHub organization events.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –conf (
config.Config) –
-
handle(payload)¶ Handle when a user is added, removed, or invited to an organization.
If the member is removed, they are removed as a user from rocket’s db if they have not been removed already.
If the member is added or invited, do nothing.
- Parameters
payload (
typing.Dict[str,typing.Any]) –- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
handle_added(github_id, github_username, organization)¶ Help organization function if payload action is added.
- Parameters
github_id (
str) –github_username (
str) –organization (
str) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
handle_invited(github_username, organization)¶ Help organization function if payload action is invited.
- Parameters
github_username (
str) –organization (
str) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
handle_remove(member_list, github_id, github_username)¶ Help organization function if payload action is remove.
- Parameters
member_list (
typing.List[app.model.user.User]) –github_id (
str) –github_username (
str) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
Handle GitHub team events.
-
class
app.controller.webhook.github.events.team.TeamEventHandler(db_facade, gh_face, conf)¶ Encapsulate the handler methods for GitHub team events.
- Parameters
db_facade (
db.facade.DBFacade) –gh_face (
interface.github.GithubInterface) –conf (
config.Config) –
-
handle(payload)¶ Handle team events of the organization.
This event is fired when a team is created, deleted, edited, or added or removed from a repository.
If a team is created, add or overwrite a team in rocket’s db.
If a team is deleted, delete the team from rocket’s db if it exists.
If a team is edited, overwrite the team’s fields or create the team if necessary.
If the team is added or removed from a repository, do nothing for now.
- Parameters
payload (
typing.Dict[str,typing.Any]) –- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
team_added_to_repository(github_id, github_team_name, payload)¶ Help team function if payload action is added_to_repository.
- Parameters
github_id (
str) –github_team_name (
str) –payload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
team_created(github_id, github_team_name, payload)¶ Help team function if payload action is created.
- Parameters
github_id (
str) –github_team_name (
str) –payload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
team_deleted(github_id, github_team_name, payload)¶ Help team function if payload action is deleted.
- Parameters
github_id (
str) –github_team_name (
str) –payload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
team_edited(github_id, github_team_name, payload)¶ Help team function if payload action is edited.
- Parameters
github_id (
str) –github_team_name (
str) –payload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
-
team_removed_from_repository(github_id, github_team_name, payload)¶ Help team function if payload action is removed_from_repository.
- Parameters
github_id (
str) –github_team_name (
str) –payload (
typing.Dict[str,typing.Any]) –
- Return type
typing.Tuple[typing.Union[typing.Dict[str,typing.List[typing.Dict[str,typing.Any]]],str,typing.Dict[str,typing.Any]],int]
Slack¶
Handle Slack events.
-
class
app.controller.webhook.slack.core.SlackEventsHandler(db_facade, bot)¶ Encapsulate the handlers for all Slack events.
- Parameters
db_facade (
db.facade.DBFacade) –bot (
interface.slack.Bot) –
-
__init__(db_facade, bot)¶ Initialize all the required interfaces.
- Parameters
db_facade (
db.facade.DBFacade) –bot (
interface.slack.Bot) –
-
handle_team_join(event_data)¶ Handle the event of a new user joining the workspace.
- Parameters
event_data (
typing.Dict[str,typing.Any]) – JSON event data