private async System.Threading.Tasks.Task <object> AktualizacjaDanychAsync() { var commity = @params.Session.GetGitHubExtension().Commity; try { var github = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("sonetaGitHubConnector")); var branches = await github.Repository.Branch.GetAll(@params.pWlasciciel, @params.pNazwa); //var commits = await github.Repository.Commit.GetAll("Pavlino", "enovaGitHubAnalyser"); List <Octokit.GitHubCommit> commits = new List <Octokit.GitHubCommit>(); foreach (var branch in branches) { var commitRequest = new Octokit.CommitRequest(); commitRequest.Sha = branch.Name; var branchCommits = await github.Repository.Commit.GetAll(@params.pWlasciciel, @params.pNazwa, commitRequest); commits.AddRange(branchCommits); } if (commits.Count > 0) { using (var t = @params.Session.Logout(true)) { List <string> shas = new List <string>(); foreach (Octokit.GitHubCommit c in commits) { if (!shas.Contains(c.Sha)) { shas.Add(c.Sha); if (!commity.CommitExists(c.Sha)) { Commit commit = new Commit { SHA = c.Sha, Autor = c.Commit.Author.Name, Data = c.Commit.Author.Date.UtcDateTime }; @params.Session.AddRow(commit); } } } commity.RemoveInvalidCommits(shas); t.Commit(); } } return("Operacja zakończona pomyślnie"); } catch (Exception e) { return("Błąd poczdas operacji: " + e.Message); } }
public async Task<IList<GitHubHostedDocument>> ExtractCommitDocuments(string organization, string repository) { if (string.IsNullOrWhiteSpace(organization)) throw new ArgumentNullException(nameof(organization), "must be specified"); if (string.IsNullOrWhiteSpace(repository)) throw new ArgumentNullException(nameof(repository), "must be specified"); var client = GetClient(); var documents = new List<GitHubHostedDocument>(); Octokit.CommitRequest request = new Octokit.CommitRequest(); request.Since = this.Settings.Since; request.Sha = "master"; // get all the latest commits for the master branch var commits = await client.Repository.Commits.GetAll(organization, repository, request); // recover the data of the branch looking for the master var repo = await client.Repository.GetBranch(organization, repository, "master"); var head = repo.Commit.Sha; foreach (var currentCommit in commits) { //var compareResult = await client.Repository.Commits.Compare(organization, repository, currentCommit.Sha, head); //head = currentCommit.Sha; var myCommit = await client.Repository.Commits.Get(organization, repository, currentCommit.Sha); if (myCommit.Files != null) { Console.WriteLine(myCommit.Files.Count.ToString()); foreach (var file in myCommit.Files) { if (file.Filename.ToLower().EndsWith(".rst", StringComparison.Ordinal)) { var fileData = new GitHubHostedDocument(); fileData.Commit = currentCommit.Sha; fileData.FileName = file.Filename; fileData.Status = file.Status; fileData.TsCommit = currentCommit.Commit.Committer.Date; fileData.Organization = organization; fileData.Repository = repository; documents.Add(fileData); } } } } return documents; }