From bb668497682932cb1b4403cad9fef621109c09f2 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Wed, 13 Jan 2016 18:17:52 -0500 Subject: [PATCH 1/4] include GitHub Enterprise in the supported tools --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98b021e..776cd20 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Read the [LeanKit Integration Service Guide](https://support.leankit.com/entries The **LeanKit Integration Service** synchronizes items between a Target system and LeanKit. -- Supported Target systems: Visual Studio Online, Microsoft Team Foundation Server (TFS) 2010/2012/2013, JIRA 5.x+, and GitHub +- Supported Target systems: Visual Studio Online, Microsoft Team Foundation Server (TFS) 2010/2012/2013, JIRA 5.x+, and GitHub (GitHub.com and GitHub Enterprise). - Runs as a Windows service, or from command line for testing - One Target + LeanKit account per instance - Multiple Target projects / LeanKit boards per instance From 734681477b1147f0a760156da985f4533fb3c17a Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Wed, 13 Jan 2016 18:27:12 -0500 Subject: [PATCH 2/4] update copyright date. github integration is now updated as of 2016. update copyright date. --- IntegrationService.Targets.GitHub/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IntegrationService.Targets.GitHub/Properties/AssemblyInfo.cs b/IntegrationService.Targets.GitHub/Properties/AssemblyInfo.cs index 7be1bdb..50ede5d 100644 --- a/IntegrationService.Targets.GitHub/Properties/AssemblyInfo.cs +++ b/IntegrationService.Targets.GitHub/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("IntegrationService.Targets.GitHub")] -[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] From 447bbc9ef57522c87a064058ee5160e7d1f1e27a Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Wed, 13 Jan 2016 21:35:02 -0500 Subject: [PATCH 3/4] support github enterprise - switch github.com vs github enterprise based on host configuration - abstract logic into helper function - switch rest api url based on enterprise or .com - start working on whitespace/indention issues --- .../GitHubConnection.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/IntegrationService.Targets.GitHub/GitHubConnection.cs b/IntegrationService.Targets.GitHub/GitHubConnection.cs index 07feea8..87c4763 100644 --- a/IntegrationService.Targets.GitHub/GitHubConnection.cs +++ b/IntegrationService.Targets.GitHub/GitHubConnection.cs @@ -27,26 +27,40 @@ protected GitHubConnection(IRestClient restClient) { RestClient = restClient; } + + /* + fqdn: target host + protocol as defined on the config screen + returns whether or not the host was targetting github.com + */ + protected Boolean isGitHubCom(String fqdn){ + return fqdn.includes("github.com") || String.isBlank(fqdn); + } public ConnectionResult Connect(string host, string user, string password) { Host = host; - RestClient.BaseUrl = new Uri("https://api.github.com"); - RestClient.Authenticator = new HttpBasicAuthenticator(user, password); + if(isGitHubCom(host)){ + //using github.com + RestClient.BaseUrl = new Uri("https://api.github.com"); + }else{ + RestClient.BaseUrl = new Uri(host+"/api/v3"); + + } + RestClient.Authenticator = new HttpBasicAuthenticator(user, password); - try - { - //https://api.github.com/users/[username]/keys - var request = new RestRequest("/users/" + user +"/keys", Method.GET); - var githubResp = RestClient.Execute(request); - - if (githubResp.StatusCode != HttpStatusCode.OK) - { - //var serializer = new JsonSerializer(); - //var errorMessage = serializer.DeserializeFromString(githubResp.Content); - return ConnectionResult.FailedToConnect; + try + { + //https://{api_endpoint}/users/[username]/keys + var request = new RestRequest("/users/" + user +"/keys", Method.GET); + var githubResp = RestClient.Execute(request); + + if (githubResp.StatusCode != HttpStatusCode.OK) + { + //var serializer = new JsonSerializer(); + //var errorMessage = serializer.DeserializeFromString(githubResp.Content); + return ConnectionResult.FailedToConnect; + } } - } catch (Exception) { return ConnectionResult.FailedToConnect; @@ -81,7 +95,7 @@ protected class Repository protected IRestResponse ReposResponse(int pageNumber, int pageSize) { - //https://api.github.com/search/repositories?q=@hostname + //https://{api_endpoint}/search/repositories?q=@hostname var reposRequest = new RestRequest(string.Format("/search/repositories?q=@{0}&page={1}&per_page={2}", Host, pageNumber, pageSize), Method.GET); // required for GitHub Search API during the developer preview reposRequest.AddHeader("Accept", "application/vnd.github.preview"); @@ -216,4 +230,4 @@ private List GetStates() return states; } } -} \ No newline at end of file +} From e4b123b8a0bb6efd02123e7f2e349328d1392a65 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Wed, 13 Jan 2016 21:36:27 -0500 Subject: [PATCH 4/4] general cleanup of extra whitespace --- IntegrationService.Targets.GitHub/GitHubConnection.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/IntegrationService.Targets.GitHub/GitHubConnection.cs b/IntegrationService.Targets.GitHub/GitHubConnection.cs index 87c4763..370466e 100644 --- a/IntegrationService.Targets.GitHub/GitHubConnection.cs +++ b/IntegrationService.Targets.GitHub/GitHubConnection.cs @@ -40,11 +40,9 @@ public ConnectionResult Connect(string host, string user, string password) { Host = host; if(isGitHubCom(host)){ - //using github.com RestClient.BaseUrl = new Uri("https://api.github.com"); }else{ RestClient.BaseUrl = new Uri(host+"/api/v3"); - } RestClient.Authenticator = new HttpBasicAuthenticator(user, password);