public IConnectedService MapService(ConnectedService service)
        {
            var gitHubService = new GitHubConnectedService(service.Id, service.Name)
            {
                DefaultWorkRoot = service.DefaultWorkRoot,
                Owner           = service.GetPropertyValue("Owner")
            };

            var mode = service.GetPropertyValue("Mode");

            if (mode == "OAuth")
            {
                gitHubService.OAuth = new GitHubOAuthConfig(
                    service.GetPropertyValue("OAuth.ClientId"),
                    service.GetPropertyValue("OAuth.Secret"));

                gitHubService.AccessToken = service.TryGetPropertyValue <string>("AccessToken");
            }
            else
            {
                gitHubService.AccessToken = service.GetPropertyValue("PersonalAccessToken");
            }

            return(gitHubService);
        }
예제 #2
0
        public async Task <IEnumerable <GitRemoteRepository> > SearchAsync(
            Guid serviceId,
            string searchString,
            CancellationToken cancellationToken)
        {
            GitHubConnectedService service = await _clientFactory.ConnectAsync(serviceId, cancellationToken);

            GitHubClient client  = _clientFactory.CreateClient(serviceId);
            var          request = new SearchRepositoriesRequest(searchString);

            request.User = service.Owner;

            SearchRepositoryResult searchResult = await client.Search.SearchRepo(request);

            return(searchResult.Items.Select(x => ToRemoteRepository(service, x)));
        }
예제 #3
0
        public async Task <GitHubConnectedService> ConnectAsync(
            Guid id,
            CancellationToken cancellationToken)
        {
            if (!_connections.ContainsKey(id))
            {
                GitHubConnectedService service = await GetConnectedServiceAsync(
                    id,
                    cancellationToken);

                var client = new GitHubClient(new ProductHeaderValue("boost"));
                client.Credentials = new Credentials(service.AccessToken);

                _connections.Add(id, new GitHubConnectionContext(service, client));
            }

            return(_connections[id].Service);
        }