Exemplo n.º 1
0
        private string GetJson()
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = _account.BasicAuthToken();

                var url =
                    $"https://bitbucket.org/api/1.0/repositories/{_account.Account}/{_account.Repository}/branches";

                _logger.Log("GET: " + url);

                var response = client.GetAsync(url)
                               .Result
                               .Content
                               .ReadAsStringAsync()
                               .Result;

                return(response);
            }
        }
Exemplo n.º 2
0
        private IEnumerable <PullRequest> GetImpl(string url)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = _account.BasicAuthToken();

                _logger.Log("GET: " + url);

                var response = client.GetAsync(url)
                               .Result
                               .Content
                               .ReadAsStringAsync()
                               .Result;

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(response);

                var results = new List <PullRequest>();

                foreach (dynamic pr in result.values)
                {
                    results.Add(new PullRequest
                    {
                        LastUpdateDateTime = DateTime.Parse(pr.updated_on.ToString()),
                        Description        = pr.description,
                        Title  = pr.title,
                        Author = pr.author.username,
                        Branch = pr.destination.branch.name,
                        State  = pr.state
                    });
                }

                if (result.next != null)
                {
                    // throttle
                    Thread.Sleep(1000);
                    results.AddRange(GetImpl(result.next.ToString()));
                }

                return(results);
            }
        }
Exemplo n.º 3
0
        private IEnumerable <Commit> GetImpl(string branch, string url)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = _account.BasicAuthToken();

                _logger.Log("GET: " + url);

                var response = client.GetAsync(url)
                               .Result
                               .Content
                               .ReadAsStringAsync()
                               .Result;

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(response);

                var results = new List <Commit>();

                foreach (dynamic commit in result.values)
                {
                    results.Add(new Commit
                    {
                        Date    = DateTime.Parse(commit.date.ToString()),
                        Message = commit.message,
                        Author  = commit.author.user == null ? commit.author.raw : commit.author.user.username,
                        Branch  = branch,
                        Hash    = commit.hash
                    });
                }

                if (result.next != null)
                {
                    // throttle
                    Thread.Sleep(1000);
                    results.AddRange(GetImpl(branch, result.next.ToString()));
                }

                return(results);
            }
        }