public Task <string> RepoMdToHtml(GithubResponse file) { if (!file.IsMd) { return(null); } var md = file.StringValue; return(Task.FromResult(Markdown.ToHtml(md))); }
public async Task <GithubResponse <GithubCommit[]> > GetCommitsAsync(string owner, string repository) { HttpResponseMessage response = await _httpClient.GetAsync($"/repos/{owner}/{repository}/commits"); if (!response.IsSuccessStatusCode) { return(GithubResponse <GithubCommit[]> .Error($"Error occurred when getting data from github api: {response.ReasonPhrase}")); } var json = await response.Content.ReadAsStringAsync(); var mappedCommits = JsonConvert.DeserializeObject <GithubCommit[]>(json); return(GithubResponse <GithubCommit[]> .Success(mappedCommits)); }
public List <GithubRepo> GetRepositories(string term) { string jsonString = string.Empty; string url = @"https://api.github.com/search/repositories?q=" + term; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.UserAgent = "EnterTheMatrix"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); jsonString = reader.ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); GithubResponse gitResponse = js.Deserialize <GithubResponse>(jsonString); return(gitResponse.items); } }
static async Task <int> Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Input arguments for owner and repository have not been provided"); return(1); } string owner = args[0]; string repository = args[1]; IHttpClientProvider httpClientProvider = new GithubClientProvider(); HttpClient httpClient = httpClientProvider.GetClient(); IGithubService githubService = new GithubService(httpClient); GithubResponse <GithubCommit[]> commitsResponse = await githubService.GetCommitsAsync(owner, repository); if (!commitsResponse.IsSuccess) { string errorMessage = string.IsNullOrEmpty(commitsResponse.ErrorMessage) ? "Error occurred when calling github service" : commitsResponse.ErrorMessage; Console.WriteLine(errorMessage); } else { IEnumerable <IDataWriter> dataWriters = new IDataWriter[] { new ConsoleWriter(), new DatabaseWriter() }; foreach (var writer in dataWriters) { writer.WriteCommits(owner, repository, commitsResponse.Data); } } Console.WriteLine("Program has finished its execution."); return(0); }
public GithubResponse GetGithubResponseFromWebResponse(System.Net.HttpWebResponse response) { var responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd(); var responseToReturn = new GithubResponse { RateLimitLimit = int.Parse(response.Headers["X-RateLimit-Limit"]), RateLimitRemaining = int.Parse(response.Headers["X-RateLimit-Remaining"]), Response = responseString, StatusCode = (int)response.StatusCode, StatusText = response.StatusDescription }; if (!string.IsNullOrEmpty(response.Headers.Get("Link"))) { responseToReturn = ParsePagingLinks( responseToReturn, response.Headers.Get("Link")); } return responseToReturn; }
public virtual GithubResponse ParsePagingLinks(GithubResponse response, string linkHeader) { foreach (var header in linkHeader.Split(new[] { ',' })) { var splitted = header.Split(new[] { ';' }); var link = splitted[0].Trim(); var what = splitted[1].Trim(); what = what.Substring(5); what = what.Substring(0, what.Length - 1); link = link.Substring(1); link = link.Substring(0, link.Length - 1); switch (what) { case "next": response.LinkNext = link; break; case "prev": response.LinkPrevious = link; break; case "first": response.LinkFirst = link; break; default: response.LinkLast = link; break; } } return response; }
public Task <MemoryStream> RepoFileStream(GithubResponse file) { return(Task.FromResult(new MemoryStream(file.ByteArray))); }
internal UpdateResult(GithubResponse response, bool isUpdateAvailable = false) { Response = response ?? new GithubResponse(); }