private static async Task <Model.Repository> GetRepository(string installationid, string token, string repositoryid) { Model.Repository repository = null; string next = null; do { var url = $"https://api.github.com/user/installations/{installationid}/repositories"; if (next != null) { url += "?page=" + next; } var repositoriesRequest = new HttpRequestMessage(HttpMethod.Get, url); repositoriesRequest.Headers.Authorization = new AuthenticationHeaderValue("token", token); repositoriesRequest.AddGithubHeaders(); var repositoriesResponse = await HttpClient.SendAsync(repositoriesRequest); next = ParseNextHeader(repositoriesResponse); var repositoriesJson = await repositoriesResponse.Content.ReadAsStringAsync(); var repositoriesData = JsonConvert.DeserializeObject <Model.Repositories>(repositoriesJson); repository = repositoriesData.repositories.FirstOrDefault(x => x.id.ToString() == repositoryid); }while (repository == null && next != null); return(repository); }
private static async Task <Model.Branch> GetImgbotBranch(Model.Repository repository, string token) { Model.Branch imgbotBranch = null; try { var imgbotBranchRequest = new HttpRequestMessage(HttpMethod.Get, repository.branches_url.Replace("{/branch}", $"/{KnownGitHubs.BranchName}")); imgbotBranchRequest.Headers.Authorization = new AuthenticationHeaderValue("token", token); imgbotBranchRequest.AddGithubHeaders(); var imgbotBranchResponse = await HttpClient.SendAsync(imgbotBranchRequest); var imbotBranchJson = await imgbotBranchResponse.Content.ReadAsStringAsync(); imgbotBranch = JsonConvert.DeserializeObject <Model.Branch>(imbotBranchJson); if (imgbotBranch.name != KnownGitHubs.BranchName) { return(null); } } catch { } return(imgbotBranch); }
private static async Task <object> RepositoryResponse(Model.Repository ghRepository, CloudTable installationsTable, string installationid) { var installation = await installationsTable.ExecuteAsync( TableOperation.Retrieve <Common.TableModels.Installation>(installationid, ghRepository.name)); return(new { ghRepository.id, ghRepository.html_url, ghRepository.name, ghRepository.fork, lastchecked = (installation.Result as Common.TableModels.Installation)?.LastChecked }); }