-
Notifications
You must be signed in to change notification settings - Fork 66
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
Enterprise GitHub using Personal Tokens #251
Changes from 3 commits
ae175e9
bef29bb
fa8bc25
ab06ee3
d3e308a
066ecb7
935956b
bd5fcbd
39f9b63
fa03602
8470747
70ace29
6db5f12
4fc6295
b29ea8f
0ca86a0
56e17bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,56 +12,72 @@ import Keys | |
import ReactiveCocoa | ||
import Result | ||
|
||
public enum GitService: String { | ||
case GitHub = "github" | ||
case BitBucket = "bitbucket" | ||
public enum GitService { | ||
case GitHub | ||
case EnterpriseGitHub(host: String) | ||
case BitBucket | ||
// case GitLab = "gitlab" | ||
|
||
|
||
public func type() -> String { | ||
switch self { | ||
case .GitHub: return "github" | ||
case .EnterpriseGitHub: return "enterprisegithub" | ||
case .BitBucket: return "bitbucket" | ||
} | ||
} | ||
|
||
public func prettyName() -> String { | ||
switch self { | ||
case .GitHub: return "GitHub" | ||
case .EnterpriseGitHub: return "EnterpriseGitHub" | ||
case .BitBucket: return "BitBucket" | ||
} | ||
} | ||
|
||
public func logoName() -> String { | ||
switch self { | ||
case .GitHub: return "github" | ||
case .EnterpriseGitHub: return "enterprisegithub" | ||
case .BitBucket: return "bitbucket" | ||
} | ||
} | ||
|
||
public func hostname() -> String { | ||
switch self { | ||
case .GitHub: return "github.com" | ||
case .EnterpriseGitHub(let host): return host | ||
case .BitBucket: return "bitbucket.org" | ||
} | ||
} | ||
|
||
public func authorizeUrl() -> String { | ||
switch self { | ||
case .GitHub: return "https://github.com/login/oauth/authorize" | ||
case .EnterpriseGitHub: return "https://\(hostname())/login/oauth/authorize" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have an assert here as well, since we don't support GitHub Enterprise OAuth yet. |
||
case .BitBucket: return "https://bitbucket.org/site/oauth2/authorize" | ||
} | ||
} | ||
|
||
public func accessTokenUrl() -> String { | ||
switch self { | ||
case .GitHub: return "https://github.com/login/oauth/access_token" | ||
case .EnterpriseGitHub: assert(false) | ||
case .BitBucket: return "https://bitbucket.org/site/oauth2/access_token" | ||
} | ||
} | ||
|
||
public func serviceKey() -> String { | ||
switch self { | ||
case .GitHub: return BuildasaurKeys().gitHubAPIClientId() | ||
case .EnterpriseGitHub: assert(false) | ||
case .BitBucket: return BuildasaurKeys().bitBucketAPIClientId() | ||
} | ||
} | ||
|
||
public func serviceSecret() -> String { | ||
switch self { | ||
case .GitHub: return BuildasaurKeys().gitHubAPIClientSecret() | ||
case .EnterpriseGitHub: assert(false) | ||
case .BitBucket: return BuildasaurKeys().bitBucketAPIClientSecret() | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// EnterpriseGitHubSourceTests.swift | ||
// Buildasaur | ||
// | ||
// Created by Rachel Caileff on 3/8/16. | ||
// Copyright © 2016 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import XCTest | ||
@testable import BuildaGitServer | ||
import BuildaUtils | ||
|
||
class EnterpriseGitHubSourceTests: XCTestCase { | ||
|
||
var github: GitHubServer! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
self.github = GitServerFactory.server(.EnterpriseGitHub(host: "git.mycompany.com"), auth: nil) as! GitHubServer // TODO: fill in accessible enterprise github host | ||
} | ||
|
||
override func tearDown() { | ||
|
||
self.github = nil | ||
|
||
super.tearDown() | ||
} | ||
|
||
func tryEndpoint(method: HTTP.Method, endpoint: GitHubEndpoints.Endpoint, params: [String: String]?, completion: (body: AnyObject!, error: NSError!) -> ()) { | ||
|
||
let expect = expectationWithDescription("Waiting for url request") | ||
|
||
let request = try! self.github.endpoints.createRequest(method, endpoint: endpoint, params: params) | ||
|
||
self.github.http.sendRequest(request, completion: { (response, body, error) -> () in | ||
|
||
completion(body: body, error: error) | ||
expect.fulfill() | ||
}) | ||
|
||
waitForExpectationsWithTimeout(10, handler: nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this going to fail outside of your network? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests are commented out. The helper functions shouldn't be a problem. |
||
} | ||
|
||
// func testGetPullRequests() { | ||
// | ||
// let params = [ | ||
// "repo": "my/repo" // TODO: fill in accessible enterprise github repo | ||
// ] | ||
// | ||
// self.tryEndpoint(.GET, endpoint: .PullRequests, params: params) { (body, error) -> () in | ||
// | ||
// XCTAssertNotNil(body, "Body must be non-nil") | ||
// if let body = body as? NSArray { | ||
// let prs: [GitHubPullRequest] = GitHubArray(body) | ||
// XCTAssertGreaterThan(prs.count, 0, "We need > 0 items to test parsing") | ||
// Log.verbose("Parsed PRs: \(prs)") | ||
// } else { | ||
// XCTFail("Body nil") | ||
// } | ||
// } | ||
// } | ||
// | ||
// func testGetBranches() { | ||
// | ||
// let params = [ | ||
// "repo": "my/repo" // TODO: fill in accessible enterprise github repo | ||
// ] | ||
// | ||
// self.tryEndpoint(.GET, endpoint: .Branches, params: params) { (body, error) -> () in | ||
// | ||
// XCTAssertNotNil(body, "Body must be non-nil") | ||
// if let body = body as? NSArray { | ||
// let branches: [GitHubBranch] = GitHubArray(body) | ||
// XCTAssertGreaterThan(branches.count, 0, "We need > 0 items to test parsing") | ||
// Log.verbose("Parsed branches: \(branches)") | ||
// } else { | ||
// XCTFail("Body nil") | ||
// } | ||
// } | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10089" systemVersion="15E33e" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10109" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<deployment identifier="macosx"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10089"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10109"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please revert these changes, since you didn't change anything I'd prefer to not have a diff here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/> | ||
<capability name="stacking Non-gravity area distributions on NSStackView" minToolsVersion="7.0" minSystemVersion="10.11"/> | ||
</dependencies> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this will be tricky when someone tries to add a service not on any supported server. Could you instead try to synchronously ping the server and detect whether it really is a GitHub Enterprise server? We'll need this anyway to support more self-hosted servers like BitBucket Server - we'll need to ping the parsed host and detect which type it is. So using the
default
branch of the switch is here might cause issues with error reporting (we'll let users add even completely unsupported servers, which I'd like to avoid).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a check for this now. I don't know if it's robust enough for you, but it was the best I could come up with.