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
44 changes: 28 additions & 16 deletions IntegrationService.Targets.GitHub/GitHubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,38 @@ 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)){
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<ErrorMessage>();
//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<ErrorMessage>();
//var errorMessage = serializer.DeserializeFromString(githubResp.Content);
return ConnectionResult.FailedToConnect;
}
}
}
catch (Exception)
{
return ConnectionResult.FailedToConnect;
Expand Down Expand Up @@ -81,7 +93,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");
Expand Down Expand Up @@ -216,4 +228,4 @@ private List<State> GetStates()
return states;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down