public void EnsuresNonNullArguments()
            {
                Assert.Throws<ArgumentNullException>(() => new GitHubClient((IConnection)null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient((ProductHeaderValue)null));

                var productInformation = new ProductHeaderValue("UnitTest");
                var baseAddress = new Uri("http://github.com");
                var credentialStore = Substitute.For<ICredentialStore>();

                Assert.Throws<ArgumentNullException>(() => new GitHubClient(productInformation, (ICredentialStore)null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, credentialStore));
                
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(productInformation, (Uri)null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, baseAddress));

                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, (ICredentialStore)null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, (Uri)null));

                Assert.Throws<ArgumentNullException>(() => new GitHubClient(productInformation, null, null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, credentialStore, null));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, null, baseAddress));
                
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, credentialStore, baseAddress));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(productInformation, null, baseAddress));
                Assert.Throws<ArgumentNullException>(() => new GitHubClient(productInformation, credentialStore, null));
            }
Example #2
0
		public ProductInfoHeaderValue (ProductHeaderValue product)
		{
			if (product == null)
				throw new ArgumentNullException ();

			Product = product;
		}
 public static bool TryParse(string input,
     out ProductHeaderValue parsedValue)
 {
     System.Net.Http.Headers.ProductHeaderValue value;
     var result = System.Net.Http.Headers.ProductHeaderValue.TryParse(input, out value);
     parsedValue = result ? Parse(input) : null;
     return result;
 }
Example #4
0
		public ProductInfoHeaderValue (string productName, string productVersion)
		{
			Product = new ProductHeaderValue (productName, productVersion);
		}
Example #5
0
        static async Task Main(string[] args)
        {
            var token = "the token";
            var productInformation = new ProductHeaderValue("OctokitBugRepro");
            var client             = new GitHubClient(productInformation);

            client.Credentials = new Credentials(token);

            Console.WriteLine("Get teams...");
            var allTeams = await client.Organization.Team.GetAll("dotnet");

            var msTeam = allTeams.Single(t => string.Equals(t.Name, "Microsoft", StringComparison.OrdinalIgnoreCase));

            Console.WriteLine("Get members...");
            var members = await client.Organization.Team.GetAllMembers(msTeam.Id, new TeamMembersRequest(TeamRoleFilter.Member));

            var logins = new SortedSet <string>(members.Select(m => m.Login));

            Console.WriteLine(logins.Count);

            var folks = logins.Where(m => m.StartsWith("opb", StringComparison.OrdinalIgnoreCase))
                        .ToArray();

            foreach (var f in folks)
            {
                Console.WriteLine(f);
            }

            // prints:
            // 665
            // // no users
            //
            // Here is what it should display:
            // 1246 // that's the number of members according to the web UI
            // opbld10
            // opbld11
            // opbld12
            // opbld13
            // opbld14
            // opbld15
            // opbld16
            // opbld17
            // opbld18
            // opbld19
            // opbld20
            // opbld21
            // opbld22
            // opbld25
            // opbld26
            // opbld27
            // opbld28
            // opbld29
            // opbld30
            // opbld31
            // opbld32
            // opbld33
            // opbld34
            // opbld35
            // opbld36
            // opbld37
            // opbld38
            // opbld39
            // opbld40
            // opbld41
            // opbld42
            // opbld43
            // opbld44
            // opbld45
            // opbld47
            // opbld48
            // opbld49
            // opbld50
            // opbld51
            // opbld52
            // opbld53
            // opbld54
            // opbld55
            // opbld56
            // opbldsb1
            // opbldsb2
            // opbldsb3
            // opbldsb6
            // opbldsb7
            // opbldsb9
        }
 public ObservableGitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
     : this(new GitHubClient(productInformation, credentialStore, baseAddress))
 {
 }
 public ProductInfoHeaderValue(string productName, string productVersion)
 {
     Product = new ProductHeaderValue(productName, productVersion);
 }
 public GitHubGraphQLClient(ProductHeaderValue headerValue, string accessToken)
 {
     _connection = new Connection(headerValue, accessToken);
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation)
     : this(new GitHubClient(productInformation))
 {
 }
Example #10
0
 public ApiClientFactory(IKeychain keychain, IProgram program)
 {
     Keychain      = keychain;
     productHeader = program.ProductHeader;
 }
Example #11
0
 /// <summary>
 /// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress.
 /// </summary>
 /// <param name="productInformation">
 /// The name (and optionally version) of the product using this library. This is sent to the server as part of
 /// the user agent for analytics purposes.
 /// </param>
 /// <param name="baseAddress">
 /// The address to point this client to. Typically used for GitHub Enterprise 
 /// instances</param>
 public GitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
     : this(new Connection(productInformation, FixUpBaseUri(baseAddress)))
 {
 }
Example #12
0
        private static GitHubClient GetClient(ProductHeaderValue productInformation)
        {
            var client = new GitHubClient(productInformation);

            return(client);
        }
Example #13
0
        private void Form2_Load(object sender, EventArgs e)
        {
            var productiInformation = new ProductHeaderValue(client.Credentials.Login);

            GetAllRepositariesForProject();
        }
 public ApiClientFactory(ILoginCache loginCache, IProgram program, ILoggingConfiguration config)
 {
     LoginCache    = loginCache;
     productHeader = program.ProductHeader;
     config.Configure();
 }
Example #15
0
 public GitHubClient(ProductHeaderValue productHeaderValue, InMemoryCredentialStore inMemoryCredentialStore)
 {
     this.productHeaderValue      = productHeaderValue;
     this.inMemoryCredentialStore = inMemoryCredentialStore;
 }
Example #16
0
 public static bool TryParse(string input, out ProductHeaderValue parsedValue)
 {
     throw new NotImplementedException();
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
     : this(new GitHubClient(productInformation, credentialStore, baseAddress))
 {
 }
Example #18
0
 private bool TryGetClient(ProductHeaderValue productInformation, out GitHubClient client)
 {
     client = AuthenticateBasic(productInformation, _gitHubUser, _githubPassword);
     return(client != null);
 }
Example #19
0
 /// <summary>
 /// Create a new instance of the GitHub API v3 client pointing to 
 /// https://api.github.com/
 /// </summary>
 /// <param name="productInformation">
 /// The name (and optionally version) of the product using this library. This is sent to the server as part of
 /// the user agent for analytics purposes.
 /// </param>
 public GitHubClient(ProductHeaderValue productInformation)
     : this(new Connection(productInformation))
 {
 }
 /// <summary>
 /// Sets the User-Agent header of the request to the specified product.
 /// </summary>
 /// <param name="product">The Upgrade header product.</param>
 /// <returns>An <see cref="IRequest"/> object that represents the request.</returns>
 public static IRequest UserAgent(this IWith @this, ProductHeaderValue product)
 => @this.UserAgent(new ProductInfoHeaderValue(product));
 /// <summary>
 /// Sets the Upgrade header of the request to the specified value.
 /// </summary>
 /// <param name="value">The Upgrade header value.</param>
 /// <returns>An <see cref="IRequest"/> object that represents the request.</returns>
 public static IRequest Upgrade(this IWith @this, ProductHeaderValue value)
 => @this.AddHeaderValue(headers => headers.Upgrade, value);
Example #22
0
 static BaseService()
 {
     clientHandler.CookieContainer = CookiesContainer;
     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
     client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(ProductHeaderValue.Parse("Mozilla/5.0")));//  (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
 }
Example #23
0
        private GitHubClient AuthenticateBasic(ProductHeaderValue productInformation, string user, string pass)
        {
            //_log.Info("trying to get a GitHub client{productInformation}", productInformation);

            return(GetClient(productInformation, user, pass));
        }
Example #24
0
        public static async Task SyncFromGitHub(string repoUrl, string token, DirectoryInfo releaseDirectoryInfo)
        {
            var repoUri   = new Uri(repoUrl);
            var userAgent = new ProductHeaderValue("SyncReleases", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var client = new GitHubClient(userAgent, repoUri);

            if (token != null)
            {
                client.Credentials = new Credentials(token);
            }

            var nwo      = nwoFromRepoUrl(repoUrl);
            var releases = (await client.Release.GetAll(nwo.Item1, nwo.Item2))
                           .OrderByDescending(x => x.PublishedAt)
                           .Take(5);

            await releases.ForEachAsync(async release => {
                // NB: Why do I have to double-fetch the release assets? It's already in GetAll
                var assets = await client.Release.GetAllAssets(nwo.Item1, nwo.Item2, release.Id);

                await assets
                .Where(x => x.Name.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
                .Where(x => {
                    var fi = new FileInfo(Path.Combine(releaseDirectoryInfo.FullName, x.Name));
                    return(!(fi.Exists && fi.Length == x.Size));
                })
                .ForEachAsync(async x => {
                    var target = new FileInfo(Path.Combine(releaseDirectoryInfo.FullName, x.Name));
                    if (target.Exists)
                    {
                        target.Delete();
                    }

                    await retryAsync(3, async() => {
                        var hc = new HttpClient();
                        var rq = new HttpRequestMessage(HttpMethod.Get, x.Url);
                        rq.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream"));
                        rq.Headers.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(userAgent.Name, userAgent.Version));
                        if (token != null)
                        {
                            rq.Headers.Add("Authorization", "Bearer " + token);
                        }

                        var resp = await hc.SendAsync(rq);
                        resp.EnsureSuccessStatusCode();

                        using (var from = await resp.Content.ReadAsStreamAsync())
                            using (var to = File.OpenWrite(target.FullName)) {
                                await from.CopyToAsync(to);
                            }
                    });
                });
            });

            var entries = releaseDirectoryInfo.GetFiles("*.nupkg")
                          .AsParallel()
                          .Select(x => ReleaseEntry.GenerateFromFile(x.FullName));

            ReleaseEntry.WriteReleaseFile(entries, Path.Combine(releaseDirectoryInfo.FullName, "RELEASES"));
        }
 public ObservableGitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
     : this(new GitHubClient(productInformation, baseAddress))
 {
 }
 public EnterpriseProbeTask(IProgram program, IHttpClient httpClient)
 {
     productHeader   = program.ProductHeader;
     this.httpClient = httpClient;
 }
 public ProductInfoHeaderValue(ProductHeaderValue product)
 {
     Product = product;
 }
 public SimpleApiClientFactory(IProgram program, Lazy <IEnterpriseProbeTask> enterpriseProbe, Lazy <IWikiProbe> wikiProbe)
 {
     productHeader       = program.ProductHeader;
     lazyEnterpriseProbe = enterpriseProbe;
     lazyWikiProbe       = wikiProbe;
 }
Example #29
0
 public MetricsService(Lazy <IHttpClient> httpClient, IProgram program)
 {
     this.httpClient    = httpClient;
     this.productHeader = program.ProductHeader;
 }
Example #30
0
 private static ObservableGitHubClient CreateClient(this ProductHeaderValue header) =>
 new ObservableGitHubClient(header);
Example #31
0
		public static bool TryParse (string input, out ProductHeaderValue parsedValue)
		{
			parsedValue = null;

			var lexer = new Lexer (input);
			var t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			var value = new ProductHeaderValue ();
			value.Name = lexer.GetStringValue (t);

			t = lexer.Scan ();
			if (t == Token.Type.SeparatorSlash) {
				t = lexer.Scan ();
				if (t != Token.Type.Token)
					return false;

				value.Version = lexer.GetStringValue (t);
				t = lexer.Scan ();
			}

			if (t != Token.Type.End)
				return false;

			parsedValue = value;
			return true;
		}
 /// <summary>
 /// Construct a <see cref="ServerClientFactory"/>
 /// </summary>
 /// <param name="productHeaderValue">The value of <see cref="productHeaderValue"/></param>
 public ServerClientFactory(ProductHeaderValue productHeaderValue)
 {
     this.productHeaderValue = productHeaderValue ?? throw new ArgumentNullException(nameof(productHeaderValue));
 }
Example #33
0
        private void CheckValidParse(string input, ProductHeaderValue expectedResult)
        {
            ProductHeaderValue result = ProductHeaderValue.Parse(input);

            Assert.Equal(expectedResult, result);
        }
Example #34
0
 private void CheckInvalidParse(string input)
 {
     Assert.Throws <FormatException>(() => { ProductHeaderValue.Parse(input); });
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
     : this(new GitHubClient(productInformation, baseAddress))
 {
 }
Example #36
0
 private static void CallGetProductLength(string input, int startIndex, int expectedLength,
                                          out ProductHeaderValue result)
 {
     Assert.Equal(expectedLength, ProductHeaderValue.GetProductLength(input, startIndex, out result));
 }
 public ObservableGitHubClient(ProductHeaderValue productInformation)
     : this(new GitHubClient(productInformation))
 {
 }
 public ApiConnection(string productName, string productVersion)
 {
     _throttler          = new Throttler(20, TimeSpan.FromMinutes(1));
     _productInformation = new ProductHeaderValue(productName, productVersion);
 }
Example #39
0
 /// <summary>
 /// Create a new instance of the GitHub API v3 client pointing to 
 /// https://api.github.com/
 /// </summary>
 /// <param name="productInformation">
 /// The name (and optionally version) of the product using this library. This is sent to the server as part of
 /// the user agent for analytics purposes.
 /// </param>
 /// <param name="credentialStore">Provides credentials to the client when making requests.</param>
 public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore)
     : this(new Connection(productInformation, credentialStore))
 {
 }
Example #40
0
 private GitHubClient AuthenticateToken(ProductHeaderValue productionInformation, string token)
 {
     //_log.Info("trying to get a GitHub client {productInformation} with token {token}", productInformation, token);
     return(GetClient(productionInformation, token));
 }
Example #41
0
 /// <summary>
 /// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress.
 /// </summary>
 /// <param name="productInformation">
 /// The name (and optionally version) of the product using this library. This is sent to the server as part of
 /// the user agent for analytics purposes.
 /// </param>
 /// <param name="credentialStore">Provides credentials to the client when making requests.</param>
 /// <param name="baseAddress">
 /// The address to point this client to. Typically used for GitHub Enterprise 
 /// instances</param>
 public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
     : this(new Connection(productInformation, FixUpBaseUri(baseAddress), credentialStore))
 {
 }
        /**************************************************************************/

        // TODO: Implement this:

        /*
         * public async Task<MacroscopeHttpTwoClientResponse> Post ()
         * {
         *
         * ConfigureProxy();
         *
         * MacroscopeHttpTwoClientResponse ClientResponse = null;
         * return ( ClientResponse );
         * }
         */

        /**************************************************************************/

        // https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

        private void ConfigureDefaultRequestHeaders(HttpRequestMessage Request)
        {
            try
            {
                Request.Headers.Host = Request.RequestUri.Host;
            }
            catch (Exception ex)
            {
                this.DebugMsg(string.Format("Get: {0}", ex.Message));
            }

            try
            {
                ProductHeaderValue     ProductHeaderValueUserAgent     = new ProductHeaderValue(this.UserAgentName(), this.UserAgentVersion());
                ProductInfoHeaderValue ProductInfoHeaderValueUserAgent = new ProductInfoHeaderValue(ProductHeaderValueUserAgent);
                Request.Headers.UserAgent.Clear();
                Request.Headers.UserAgent.Add(ProductInfoHeaderValueUserAgent);
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                if (Request.Headers.Accept != null)
                {
                    Request.Headers.Accept.Clear();
                    Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 1));
                }
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                if (Request.Headers.AcceptCharset != null)
                {
                    Request.Headers.AcceptCharset.Clear();
                    Request.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8", 1));
                    Request.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("us-ascii", 0.9));
                }
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                if (Request.Headers.AcceptEncoding != null)
                {
                    Request.Headers.AcceptEncoding.Clear();
                    Request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip", 1));
                    Request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate", 0.9));
                }
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
                throw;
            }

            try
            {
                // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
                if (Request.Headers.CacheControl != null)
                {
                    Request.Headers.CacheControl.MaxAge          = new TimeSpan(0, 0, 0);
                    Request.Headers.CacheControl.NoCache         = true;
                    Request.Headers.CacheControl.MustRevalidate  = true;
                    Request.Headers.CacheControl.ProxyRevalidate = true;
                }
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                if (Request.Headers.AcceptLanguage != null)
                {
                    Request.Headers.AcceptLanguage.Clear();
                    Request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue("*", 1));
                }
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/DNT
                Request.Headers.Add("DNT", "1");
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }

            try
            {
                // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests
                Request.Headers.Add("Upgrade-Insecure-Requests", "1");
            }
            catch (Exception ex)
            {
                this.DebugMsg(ex.Message);
            }
        }