Skip to content
Open
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
88 changes: 59 additions & 29 deletions Sources/APIModels/Github.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
//
// Github.swift
// APIConnect
//
// Created by Peter Geszten-Kovacs on 2018. 12. 03..
//
import Foundation

public enum Github {
public enum Url {
public static let base = URL(string: "https://api.github.com")!
public static let organisation = "imindeu"
public static let ios = base
.appendingPathComponent(Path.repos.rawValue)
.appendingPathComponent(organisation)
.appendingPathComponent(Repository.ios.rawValue)
public static let android = base
.appendingPathComponent(Path.repos.rawValue)
.appendingPathComponent(organisation)
.appendingPathComponent(Repository.android.rawValue)
public static let search = base
.appendingPathComponent(Path.search.rawValue)

public enum Repository: String {
case ios = "4dmotion-ios"
case android = "4dmotion-android"
}
}

public enum Path: String {
case commits
case issues
case labels
case pulls
case repos
case search
case statuses
}

public struct Payload: Equatable, Codable {
public let action: Action?
public let review: Review?
Expand Down Expand Up @@ -48,39 +73,44 @@ public enum Github {
}

public struct PullRequest: Equatable, Codable {
public let url: String
public enum State: String, Codable {
case open, closed, all
}

enum CodingKeys: String, CodingKey {
case id
case issueId = "number"
case state
case title
case body
case createdAt = "created_at"
case updatedAt = "updated_at"
case mergedAt = "merged_at"
case draft
case head
case base
case labels
case url
}

public let id: Int
public let issueId: Int
public let state: State
public let title: String
public let body: String?
public let createdAt: Date
public let updatedAt: Date
public let mergedAt: Date
public let draft: Bool
public let head: Branch
public let base: Branch
public let merged: Bool

public init(url: String,
id: Int,
title: String,
body: String?,
head: Branch,
base: Branch,
merged: Bool = false) {
self.url = url
self.id = id
self.title = title
self.body = body
self.head = head
self.base = base
self.merged = merged
}
public let labels: [Label]
public let url: String
}

public struct Repository: Equatable, Codable {
public let name: String
public let url: String

public init(name: String, url: String) {
self.name = name
self.url = url
}
}

public struct User: Equatable, Codable {
Expand Down
21 changes: 17 additions & 4 deletions Sources/APIService/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import protocol APIConnect.Context
import class APIConnect.IO

import protocol Foundation.LocalizedError
import struct Foundation.CharacterSet
import class Foundation.JSONDecoder
import Foundation

import struct HTTP.HTTPBody
import struct HTTP.HTTPHeaders
Expand Down Expand Up @@ -93,7 +91,22 @@ extension IO where T == HTTPResponse {
func decode<A: Decodable>(_ type: A.Type) -> IO<A?> {
return map { response -> A? in
guard let data = response.body.data else { return nil }
return try JSONDecoder().decode(type, from: data)

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
return try decoder.decode(type, from: data)
}
}
}

extension URL {
public func appendingQueryItems(_ items: [URLQueryItem]) -> URL? {
URLComponents(string: absoluteString)
.map { components in
var components = components
components.queryItems = (components.queryItems ?? []) + items
return components
}?
.url
}
}
2 changes: 1 addition & 1 deletion Sources/App/Services/CircleCi+Services.swift
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ extension CircleCi {
}

switch type {
case let .pullRequestLabeled(label: Github.waitingForReviewLabel, head: head, base: base, platform: platform):
case let .pullRequestLabeled(label: Github.Label.waitingForReview, head: head, base: base, platform: platform):
do {
if Github.isMaster(branch: base) || Github.isRelease(branch: base) {
return try CircleCiTestJob.parse(project: project,
Expand Down
Loading