コード例 #1
0
        private async Task <int?> GetProjectIdInternal(string httpUrlToRepo)
        {
            var page    = 1;
            var url     = $"{_settings.Url}/v4/projects";
            var headers = new { PRIVATE_TOKEN = _settings.Token };

            while (true)
            {
                var data     = new { page, per_page = 100, simple = true };
                var projects = await FlurlHelper.GetJsonAsync <IEnumerable <Project> >(url, data, headers);

                if (!projects.Any())
                {
                    return(null);
                }

                var project = projects.FirstOrDefault(f => f.http_url_to_repo.StartsWith(httpUrlToRepo, StringComparison.CurrentCultureIgnoreCase));
                if (project != null)
                {
                    return(project.id);
                }

                page++;
            }
        }
コード例 #2
0
        private async Task <Project> GetProject(int?projectId)
        {
            if (!projectId.HasValue)
            {
                return(null);
            }

            var url     = $"{_settings.Url}/v4/projects/{projectId}";
            var headers = new { PRIVATE_TOKEN = _settings.Token };
            var data    = new { simple = true };

            try
            {
                return(await FlurlHelper.GetJsonAsync <Project>(url, data, headers));
            }
            catch
            {
                Console.WriteLine($"{url} not found");
            }

            return(null);
        }