-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from czechboy0/develop_1.0
Developing 1.0 - Iris
- Loading branch information
Showing
120 changed files
with
5,042 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// Authentication.swift | ||
// Buildasaur | ||
// | ||
// Created by Honza Dvorsky on 1/26/16. | ||
// Copyright © 2016 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import BuildaUtils | ||
|
||
public struct ProjectAuthenticator { | ||
|
||
public enum AuthType: String { | ||
case PersonalToken | ||
case OAuthToken | ||
} | ||
|
||
public let service: GitService | ||
public let username: String | ||
public let type: AuthType | ||
public let secret: String | ||
|
||
public init(service: GitService, username: String, type: AuthType, secret: String) { | ||
self.service = service | ||
self.username = username | ||
self.type = type | ||
self.secret = secret | ||
} | ||
} | ||
|
||
public protocol KeychainStringSerializable { | ||
static func fromString(value: String) throws -> Self | ||
func toString() -> String | ||
} | ||
|
||
extension ProjectAuthenticator: KeychainStringSerializable { | ||
|
||
public static func fromString(value: String) throws -> ProjectAuthenticator { | ||
|
||
let comps = value.componentsSeparatedByString(":") | ||
guard comps.count >= 4 else { throw Error.withInfo("Corrupted keychain string") } | ||
guard let service = GitService(rawValue: comps[0]) else { | ||
throw Error.withInfo("Unsupported service: \(comps[0])") | ||
} | ||
guard let type = ProjectAuthenticator.AuthType(rawValue: comps[2]) else { | ||
throw Error.withInfo("Unsupported auth type: \(comps[2])") | ||
} | ||
//join the rest back in case we have ":" in the token | ||
let remaining = comps.dropFirst(3).joinWithSeparator(":") | ||
let auth = ProjectAuthenticator(service: service, username: comps[1], type: type, secret: remaining) | ||
return auth | ||
} | ||
|
||
public func toString() -> String { | ||
|
||
return [ | ||
self.service.rawValue, | ||
self.username, | ||
self.type.rawValue, | ||
self.secret | ||
].joinWithSeparator(":") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// BaseTypes.swift | ||
// Buildasaur | ||
// | ||
// Created by Honza Dvorsky on 10/16/15. | ||
// Copyright © 2015 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import ReactiveCocoa | ||
|
||
public protocol BuildStatusCreator { | ||
func createStatusFromState(state: BuildState, description: String?, targetUrl: String?) -> StatusType | ||
} | ||
|
||
public protocol SourceServerType: BuildStatusCreator { | ||
|
||
func getBranchesOfRepo(repo: String, completion: (branches: [BranchType]?, error: ErrorType?) -> ()) | ||
func getOpenPullRequests(repo: String, completion: (prs: [PullRequestType]?, error: ErrorType?) -> ()) | ||
func getPullRequest(pullRequestNumber: Int, repo: String, completion: (pr: PullRequestType?, error: ErrorType?) -> ()) | ||
func getRepo(repo: String, completion: (repo: RepoType?, error: ErrorType?) -> ()) | ||
func getStatusOfCommit(commit: String, repo: String, completion: (status: StatusType?, error: ErrorType?) -> ()) | ||
func postStatusOfCommit(commit: String, status: StatusType, repo: String, completion: (status: StatusType?, error: ErrorType?) -> ()) | ||
func postCommentOnIssue(comment: String, issueNumber: Int, repo: String, completion: (comment: CommentType?, error: ErrorType?) -> ()) | ||
func getCommentsOfIssue(issueNumber: Int, repo: String, completion: (comments: [CommentType]?, error: ErrorType?) -> ()) | ||
|
||
func authChangedSignal() -> Signal<ProjectAuthenticator?, NoError> | ||
} | ||
|
||
public class SourceServerFactory { | ||
|
||
public init() { } | ||
|
||
public func createServer(service: GitService, auth: ProjectAuthenticator?) -> SourceServerType { | ||
|
||
if let auth = auth { | ||
precondition(service == auth.service) | ||
} | ||
|
||
return GitServerFactory.server(service, auth: auth) | ||
} | ||
} | ||
|
||
public struct RepoPermissions { | ||
public let read: Bool | ||
public let write: Bool | ||
public init(read: Bool, write: Bool) { | ||
self.read = read | ||
self.write = write | ||
} | ||
} | ||
|
||
public protocol RateLimitType { | ||
|
||
var report: String { get } | ||
} | ||
|
||
public protocol RepoType { | ||
|
||
var permissions: RepoPermissions { get } | ||
var originUrlSSH: String { get } | ||
var latestRateLimitInfo: RateLimitType? { get } | ||
} | ||
|
||
public protocol BranchType { | ||
|
||
var name: String { get } | ||
var commitSHA: String { get } | ||
} | ||
|
||
public protocol IssueType { | ||
|
||
var number: Int { get } | ||
} | ||
|
||
public protocol PullRequestType: IssueType { | ||
|
||
var headName: String { get } | ||
var headCommitSHA: String { get } | ||
var headRepo: RepoType { get } | ||
|
||
var baseName: String { get } | ||
|
||
var title: String { get } | ||
} | ||
|
||
public enum BuildState { | ||
case NoState | ||
case Pending | ||
case Success | ||
case Error | ||
case Failure | ||
} | ||
|
||
public protocol StatusType { | ||
|
||
var state: BuildState { get } | ||
var description: String? { get } | ||
var targetUrl: String? { get } | ||
} | ||
|
||
extension StatusType { | ||
|
||
public func isEqual(rhs: StatusType) -> Bool { | ||
let lhs = self | ||
return lhs.state == rhs.state && lhs.description == rhs.description | ||
} | ||
} | ||
|
||
public protocol CommentType { | ||
|
||
var body: String { get } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// GitServerFactory.swift | ||
// Buildasaur | ||
// | ||
// Created by Honza Dvorsky on 13/12/2014. | ||
// Copyright (c) 2014 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import BuildaUtils | ||
|
||
class GitServerFactory { | ||
|
||
class func server(service: GitService, auth: ProjectAuthenticator?, http: HTTP? = nil) -> SourceServerType { | ||
|
||
let server: SourceServerType | ||
|
||
switch service { | ||
case .GitHub: | ||
let baseURL = "https://api.github.com" | ||
let endpoints = GitHubEndpoints(baseURL: baseURL, auth: auth) | ||
server = GitHubServer(endpoints: endpoints, http: http) | ||
case .BitBucket: | ||
let baseURL = "https://api.bitbucket.org" | ||
let endpoints = BitBucketEndpoints(baseURL: baseURL, auth: auth) | ||
server = BitBucketServer(endpoints: endpoints, http: http) | ||
} | ||
|
||
return server | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// BitBucketComment.swift | ||
// Buildasaur | ||
// | ||
// Created by Honza Dvorsky on 1/27/16. | ||
// Copyright © 2016 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class BitBucketComment: BitBucketEntity, CommentType { | ||
|
||
let body: String | ||
|
||
required init(json: NSDictionary) { | ||
|
||
self.body = json | ||
.optionalDictionaryForKey("content")? | ||
.stringForKey("raw") ?? json.stringForKey("content") | ||
|
||
super.init(json: json) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.