Skip to content

feat: add support for alerts #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ fi
TITLE="Firebase Python SDK for Cloud Functions"
PY_MODULES='firebase_functions
firebase_functions.core
firebase_functions.alerts_fn
firebase_functions.alerts.app_distribution_fn
firebase_functions.alerts.billing_fn
firebase_functions.alerts.crashlytics_fn
firebase_functions.alerts.performance_fn
firebase_functions.db_fn
firebase_functions.eventarc_fn
firebase_functions.https_fn
Expand Down
5 changes: 5 additions & 0 deletions samples/basic_alerts/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "python-functions-testing"
}
}
66 changes: 66 additions & 0 deletions samples/basic_alerts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
3 changes: 3 additions & 0 deletions samples/basic_alerts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Required to avoid a 'duplicate modules' mypy error
# in monorepos that have multiple main.py files.
# https://github.com/python/mypy/issues/4008
11 changes: 11 additions & 0 deletions samples/basic_alerts/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"venv"
]
}
]
}
13 changes: 13 additions & 0 deletions samples/basic_alerts/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pyenv
.python-version

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Environments
.env
.venv
venv/
venv.bak/
__pycache__
81 changes: 81 additions & 0 deletions samples/basic_alerts/functions/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Cloud function samples for Firebase Alerts."""

from firebase_functions import alerts_fn
from firebase_functions.alerts import app_distribution_fn
from firebase_functions.alerts import billing_fn
from firebase_functions.alerts import crashlytics_fn
from firebase_functions.alerts import performance_fn


@alerts_fn.on_alert_published(alert_type=alerts_fn.AlertType.BILLING_PLAN_UPDATE
)
def onalertpublished(
alert: alerts_fn.AlertEvent[alerts_fn.FirebaseAlertData[
billing_fn.PlanUpdatePayload]]
) -> None:
print(alert)


@app_distribution_fn.on_in_app_feedback_published()
def appdistributioninappfeedback(
alert: app_distribution_fn.InAppFeedbackEvent) -> None:
print(alert)


@app_distribution_fn.on_new_tester_ios_device_published()
def appdistributionnewrelease(
alert: app_distribution_fn.NewTesterDeviceEvent) -> None:
print(alert)


@billing_fn.on_plan_automated_update_published()
def billingautomatedplanupdate(
alert: billing_fn.BillingPlanAutomatedUpdateEvent) -> None:
print(alert)


@billing_fn.on_plan_update_published()
def billingplanupdate(alert: billing_fn.BillingPlanUpdateEvent) -> None:
print(alert)


@crashlytics_fn.on_new_fatal_issue_published()
def crashlyticsnewfatalissue(
alert: crashlytics_fn.CrashlyticsNewFatalIssueEvent) -> None:
print(alert)


@crashlytics_fn.on_new_nonfatal_issue_published()
def crashlyticsnewnonfatalissue(
alert: crashlytics_fn.CrashlyticsNewNonfatalIssueEvent) -> None:
print(alert)


@crashlytics_fn.on_new_anr_issue_published()
def crashlyticsnewanrissue(
alert: crashlytics_fn.CrashlyticsNewAnrIssueEvent) -> None:
print(alert)


@crashlytics_fn.on_regression_alert_published()
def crashlyticsregression(
alert: crashlytics_fn.CrashlyticsRegressionAlertEvent) -> None:
print(alert)


@crashlytics_fn.on_stability_digest_published()
def crashlyticsstabilitydigest(
alert: crashlytics_fn.CrashlyticsStabilityDigestEvent) -> None:
print(alert)


@crashlytics_fn.on_velocity_alert_published()
def crashlyticsvelocity(
alert: crashlytics_fn.CrashlyticsVelocityAlertEvent) -> None:
print(alert)


@performance_fn.on_threshold_alert_published()
def performancethreshold(
alert: performance_fn.PerformanceThresholdAlertEvent) -> None:
print(alert)
8 changes: 8 additions & 0 deletions samples/basic_alerts/functions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Not published yet,
# firebase-functions-python >= 0.0.1
# so we use a relative path during development:
./../../../
# Or switch to git ref for deployment testing:
# git+https://github.com/firebase/firebase-functions-python.git@main#egg=firebase-functions

firebase-admin >= 6.0.1
46 changes: 46 additions & 0 deletions src/firebase_functions/alerts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2022 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Cloud functions to handle events from Firebase Alerts.
Subpackages give stronger typing to specific services which
notify users via Firebase Alerts.
"""

import dataclasses as _dataclasses
import datetime as _dt
import typing as _typing

from firebase_functions.core import T


@_dataclasses.dataclass(frozen=True)
class FirebaseAlertData(_typing.Generic[T]):
"""
The CloudEvent data emitted by Firebase Alerts.
"""

create_time: _dt.datetime
"""
The time the alert was created.
"""

end_time: _dt.datetime | None
"""
The time the alert ended. This is only set for alerts that have ended.
"""

payload: T
"""
Payload of the event, which includes the details of the specific alert.
"""
Loading