Skip to content
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

Use vapor/ci linting #22

Merged
merged 1 commit into from
Oct 5, 2024
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
11 changes: 2 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ on:
push: { branches: [ main ] }

jobs:
lint:
runs-on: ubuntu-latest
container: swift:jammy
steps:
- name: Check out SendGridKit
uses: actions/checkout@v4
- name: Run format lint check
run: swift format lint --strict --recursive --parallel .

unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
with_linting: true
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
70 changes: 0 additions & 70 deletions .swift-format

This file was deleted.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "SendGridKit", targets: ["SendGridKit"])
],
dependencies: [
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0")
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0")
],
targets: [
.target(
Expand Down
11 changes: 3 additions & 8 deletions Sources/SendGridKit/SendGridClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ public struct SendGridClient: Sendable {
public init(httpClient: HTTPClient, apiKey: String, forEU: Bool = false) {
self.httpClient = httpClient
self.apiKey = apiKey
self.apiURL =
forEU
? "https://api.eu.sendgrid.com/v3/mail/send" : "https://api.sendgrid.com/v3/mail/send"
self.apiURL = forEU ? "https://api.eu.sendgrid.com/v3/mail/send" : "https://api.sendgrid.com/v3/mail/send"
}

public func send<DynamicTemplateData: Codable & Sendable>(
email: SendGridEmail<DynamicTemplateData>
) async throws {
public func send<DynamicTemplateData: Codable & Sendable>(email: SendGridEmail<DynamicTemplateData>) async throws {
var headers = HTTPHeaders()
headers.add(name: "Authorization", value: "Bearer \(apiKey)")
headers.add(name: "Content-Type", value: "application/json")
Expand All @@ -53,7 +49,6 @@ public struct SendGridClient: Sendable {
if (200...299).contains(response.status.code) { return }

// `JSONDecoder` will handle empty body by throwing decoding error
throw try await decoder.decode(
SendGridError.self, from: response.body.collect(upTo: 1024 * 1024))
throw try await decoder.decode(SendGridError.self, from: response.body.collect(upTo: 1024 * 1024))
}
}
9 changes: 5 additions & 4 deletions Tests/SendGridKitTests/SendGridTestsKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ struct SendGridKitTests {
let integer: Int
let double: Double
}
let dynamicTemplateData = DynamicTemplateData(
text: "Hello, World!", integer: 42, double: 3.14)
let dynamicTemplateData = DynamicTemplateData(text: "Hello, World!", integer: 42, double: 3.14)

// TODO: Replace the addresses with real email addresses
let personalization = Personalization(
to: [EmailAddress("TO-ADDRESS")], subject: "Test Email",
dynamicTemplateData: dynamicTemplateData)
dynamicTemplateData: dynamicTemplateData
)
let email = SendGridEmail(
personalizations: [personalization], from: EmailAddress("FROM-ADDRESS"),
content: [EmailContent("Hello, World!")])
content: [EmailContent("Hello, World!")]
)

try await withKnownIssue {
try await client.send(email: email)
Expand Down