Type-safe GitHub API client for Swift with dependency injection and modular architecture.
swift-github provides a high-level interface to GitHub's REST API built on swift-dependencies for testability and maintainability.
- Type-safe API clients for traffic analytics, repositories, and stargazers
- Dependency injection via swift-dependencies for testable code
- Modular design with separate packages for different API domains
- Async/await support for modern Swift concurrency
- OAuth authentication support
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/coenttb/swift-github", from: "0.1.0")
]import GitHub
import Dependencies
@Dependency(\.github) var github
let views = try await github.client.traffic.views(
owner: "coenttb",
repo: "swift-github",
per: .day
)
let clones = try await github.client.traffic.clones(
owner: "coenttb",
repo: "swift-github",
per: nil
)
let paths = try await github.client.traffic.paths(
owner: "coenttb",
repo: "swift-github"
)
let referrers = try await github.client.traffic.referrers(
owner: "coenttb",
repo: "swift-github"
)import Testing
import GitHub
import Dependencies
@Test
func testTrafficAnalytics() async throws {
await withDependencies {
$0.github.client.traffic.views = { _, _, _ in
.init(count: 100, uniques: 50, views: [])
}
} operation: {
@Dependency(\.github) var github
let result = try await github.client.traffic.views("owner", "repo", .day)
#expect(result.count == 100)
#expect(result.uniques == 50)
}
}The package is organized into focused modules:
- GitHub: Main module combining all GitHub API functionality
- GitHub Traffic: Traffic analytics and metrics
- GitHub Repositories: Repository operations and metadata
- GitHub Shared: Common types and utilities shared across modules
Each module provides a dependency-injectable client for testability.
- swift-github-live: A Swift package with live implementations for the GitHub API.
- swift-github-types: Type definitions for GitHub API responses and requests.
- pointfreeco/swift-dependencies: A dependency management library for controlling dependencies in Swift.
- Swift 6.0+
- macOS 14+ / iOS 17+
This package is licensed under the AGPL 3.0 License. See LICENSE.md for details.
For commercial licensing options, please contact the maintainer.