Skip to content

coenttb/swift-github

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

swift-github

CI Development Status

Type-safe GitHub API client for Swift with dependency injection and modular architecture.

Overview

swift-github provides a high-level interface to GitHub's REST API built on swift-dependencies for testability and maintainability.

Features

  • 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

Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/coenttb/swift-github", from: "0.1.0")
]

Quick Start

Traffic Analytics

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"
)

Testing with Mocks

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)
    }
}

Architecture

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.

Related Packages

Requirements

  • Swift 6.0+
  • macOS 14+ / iOS 17+

License

This package is licensed under the AGPL 3.0 License. See LICENSE.md for details.

For commercial licensing options, please contact the maintainer.