Skip to content

Commit

Permalink
Merge pull request #2 from rj76/develop
Browse files Browse the repository at this point in the history
Github actions
  • Loading branch information
rj76 committed Jan 4, 2024
2 parents e765990 + dc8bd0f commit fc708f5
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 57 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Cargo tests
on:
push:
branches:
- master
- main
- develop
pull_request:
jobs:
clippy:
Expand All @@ -11,7 +12,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
components: clippy
override: true
- name: Install dependencies
Expand Down Expand Up @@ -45,25 +46,44 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest

runs-on: ${{ matrix.os }}

env:
RUSTFLAGS: "-Dwarnings"
RUSTFLAGS: "-Dwarnings -Cinstrument-coverage -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
CARGO_INCREMENTAL: "0"
RUSTDOCFLAGS: "-Cpanic=abort"
RUSTC_BOOTSTRAP: "1"

steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: ${{matrix.rust}}
components: llvm-tools-preview

- uses: actions/cache@v2
with:
path: |
target
key: ${{ runner.os }}-cargo-${{ matrix.rust }}

- name: Build
run: cargo build

- name: Install grcov
run: cargo install grcov

- name: Run tests
run: cargo test
run: LLVM_PROFILE_FILE="fcm-rust-%p-%m.profraw" cargo test

- name: Collect results
run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./tests.lcov

- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./tests.lcov

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ authors = [
]
description = "An API to talk to FCM (Firebase Cloud Messaging) in Rust"
license = "MIT"
homepage = "https://github.com/panicbit/fcm-rust"
repository = "https://github.com/panicbit/fcm-rust"
homepage = "https://github.com/rj76/fcm-rust"
repository = "https://github.com/rj76/fcm-rust"
documentation = "https://docs.rs/fcm/"
keywords = ["fcm", "firebase", "notification"]
edition = "2018"
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# fcm
[![Cargo tests](https://github.com/rj76/fcm-rust/actions/workflows/test.yml/badge.svg)](https://github.com/panicbit/fcm-rust/actions/workflows/test.yml)
[![Coveralls](https://img.shields.io/coveralls/panicbit/fcm-rust.svg?style=flat-square)][coveralls]
[![Crates.io Version](https://img.shields.io/crates/v/fcm.svg?style=flat-square)][crates.io]
[![Crates.io Downloads](https://img.shields.io/crates/dv/fcm.svg?style=flat-square)][crates.io]
[![Crates.io License](https://img.shields.io/crates/l/fcm.svg?style=flat-square)][crates.io]

[travis]: https://travis-ci.org/panicbit/fcm-rust
[coveralls]: https://coveralls.io/github/panicbit/fcm-rust
# fcm-rust
[![Cargo tests](https://github.com/rj76/fcm-rust/actions/workflows/test.yml/badge.svg)](https://github.com/rj76/fcm-rust/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/rj76/fcm-rust/badge.svg)](https://coveralls.io/github/rj76/fcm-rust)

[//]: # ([![Crates.io Version](https://img.shields.io/crates/v/fcm.svg?style=flat-square))
[//]: # ([![Crates.io Downloads](https://img.shields.io/crates/dv/fcm.svg?style=flat-square))
[//]: # ([![Crates.io License](https://img.shields.io/crates/l/fcm.svg?style=flat-square))


## v1 API

Expand Down
10 changes: 5 additions & 5 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct AndroidConfig {

// If set to true, messages will be allowed to be delivered to the app while the device is in direct boot mode.
#[serde(skip_serializing_if = "Option::is_none")]
direct_boot_ok: Option<bool>
direct_boot_ok: Option<bool>,
}

#[derive(Serialize, Debug)]
Expand All @@ -52,7 +52,7 @@ pub struct Color {
blue: f32,

// The fraction of this color that should be applied to the pixel.
alpha: f32
alpha: f32,
}

#[derive(Serialize, Debug)]
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct AndroidNotification {
//https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidconfig
pub struct AndroidFcmOptions {
// Label associated with the message's analytics data.
analytics_label: String
analytics_label: String,
}

#[allow(dead_code)]
Expand All @@ -206,7 +206,7 @@ pub enum NotificationPriority {
PriorityLow,
PriorityDefault,
PriorityHigh,
PriorityMax
PriorityMax,
}

Check warning on line 210 in src/android/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

all variants have the same prefix: `Priority`

warning: all variants have the same prefix: `Priority` --> src/android/mod.rs:203:1 | 203 | / pub enum NotificationPriority { 204 | | PriorityUnspecified, 205 | | PriorityMin, 206 | | PriorityLow, ... | 209 | | PriorityMax, 210 | | } | |_^ | = help: remove the prefixes and use full paths to the variants instead of glob imports = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names = note: `#[warn(clippy::enum_variant_names)]` on by default

#[allow(dead_code)]
Expand All @@ -217,5 +217,5 @@ pub enum Visibility {
VisibilityUnspecified,

Check warning on line 217 in src/android/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variant name starts with the enum's name

warning: variant name starts with the enum's name --> src/android/mod.rs:217:5 | 217 | VisibilityUnspecified, | ^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names
Private,
Public,
Secret
Secret,
}
2 changes: 1 addition & 1 deletion src/apns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub struct ApnsFcmOptions {
analytics_label: String,

// Contains the URL of an image that is going to be displayed in a notification.
image: String
image: String,
}
12 changes: 4 additions & 8 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
pub(crate) mod response;

use gauth::serv_account::ServiceAccount;
use reqwest::{Body, StatusCode};
use reqwest::header::RETRY_AFTER;
use crate::client::response::{ErrorReason, FcmError, FcmResponse, RetryAfter};
use crate::Message;

use gauth::serv_account::ServiceAccount;
use reqwest::header::RETRY_AFTER;
use reqwest::{Body, StatusCode};

/// An async client for sending the notification payload.
pub struct Client {
Expand Down Expand Up @@ -115,10 +114,7 @@ impl Client {
};

// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
let url = format!(
"https://fcm.googleapis.com/v1/projects/{}/messages:send",
project_id
);
let url = format!("https://fcm.googleapis.com/v1/projects/{}/messages:send", project_id);

let request = self
.http_client
Expand Down
1 change: 0 additions & 1 deletion src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ pub enum FcmError {
ProjectIdError(String),

AuthToken(String),

}

impl Error for FcmError {}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ mod message;
pub use crate::message::*;
mod notification;
pub use crate::notification::*;
mod client;
mod android;
mod web;
mod apns;
mod client;
mod web;

pub use crate::client::*;

Expand Down
30 changes: 12 additions & 18 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Serialize, Serializer};
use serde_json::Value;
use crate::android::AndroidConfig;
use crate::apns::ApnsConfig;
use crate::Notification;
use crate::web::WebpushConfig;
use crate::Notification;
use serde::{Serialize, Serializer};
use serde_json::Value;

#[cfg(test)]
mod tests;
Expand All @@ -13,23 +13,17 @@ mod tests;
pub enum Target {
Token(String),
Topic(String),
Condition(String)
Condition(String),
}

fn output_target<S>(target: &Target, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer
where
S: Serializer,
{
match target {
Target::Token(token) => {
s.serialize_newtype_struct("token", token.as_str())
},
Target::Topic(topic) => {
s.serialize_newtype_struct("topic", topic.as_str())
},
Target::Condition(condition) => {
s.serialize_newtype_struct("condition", condition.as_str())
},
Target::Token(token) => s.serialize_newtype_struct("token", token.as_str()),
Target::Topic(topic) => s.serialize_newtype_struct("topic", topic.as_str()),
Target::Condition(condition) => s.serialize_newtype_struct("condition", condition.as_str()),
}
}

Expand Down Expand Up @@ -62,7 +56,7 @@ pub struct Message {

// Target to send a message to.
#[serde(serialize_with = "output_target")]
target: Target
target: Target,
}

#[derive(Serialize, Debug)]
Expand All @@ -88,7 +82,7 @@ pub struct FcmOptions {
pub struct MessageBuilder {
data: Option<Value>,
notification: Option<Notification>,
target: Target
target: Target,
}

impl MessageBuilder {
Expand Down Expand Up @@ -150,7 +144,7 @@ impl MessageBuilder {
webpush: None,
apns: None,
fcm_options: None,
target: self.target
target: self.target,
}
}
}
6 changes: 2 additions & 4 deletions src/message/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct CustomData {
#[test]
fn should_create_new_message() {
let target = Target::Token("token".to_string());
let msg = MessageBuilder::new(target.clone())
.finalize();
let msg = MessageBuilder::new(target.clone()).finalize();

assert_eq!(msg.target, target);
}
Expand Down Expand Up @@ -61,8 +60,7 @@ fn should_be_able_to_render_a_full_message_to_json() {
let target = Target::Token("token".to_string());
let mut builder = MessageBuilder::new(target);

builder
.notification(NotificationBuilder::new().finalize());
builder.notification(NotificationBuilder::new().finalize());

let payload = serde_json::to_string(&builder.finalize()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/notification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl NotificationBuilder {
Notification {
title: self.title,
body: self.body,
image: self.image
image: self.image,
}
}
}
2 changes: 1 addition & 1 deletion src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ pub struct WebpushFcmOptions {
link: String,

// Label associated with the message's analytics data.
analytics_label: String
analytics_label: String,
}

0 comments on commit fc708f5

Please sign in to comment.