/// <summary> /// Finds the commits. /// </summary> /// <param name="repositoryName">Name of the repository.</param> /// <param name="branchName">Name of the branch.</param> /// <param name="tagName">Name of the tag.</param> /// <returns></returns> public List <CommitDataModel> FindCommits(string repositoryName, string branchName, string tagName) { var result = new List <CommitDataModel>(); var page = 1; var tag = FindTagByName(repositoryName, tagName); LinkedResponsePayload <List <CommitDataModel> > response = null; do { var link = string.Format("repos/{0}/{1}/commits?sha={2}&page={3}&per_page=100", client.OwnerName, repositoryName, branchName, page++); response = client.GetResponse <List <CommitDataModel> >(link); foreach (var commit in response.Data) { if (tag != null && commit.SHA == tag.SHA) { return(result); } result.Add(commit); } }while (response.NextPageAvailable); return(result); }
public void find_commits_calls_githubclient_with_multiple_pages_multiple_times() { var firstCommitsLink = string.Format("repos/{0}/{1}/commits?sha={2}&page={3}&per_page=100", ownerName, repositoryName, branchName, 1); var secondCommitsLink = string.Format("repos/{0}/{1}/commits?sha={2}&page={3}&per_page=100", ownerName, repositoryName, branchName, 2); var firstResponse = new LinkedResponsePayload<List<CommitDataModel>>() { Data = Enumerable.Repeat(new CommitDataModel { Message = "1", SHA = "1" }, 100).ToList(), NextPageAvailable = true }; var secondResponse = new LinkedResponsePayload<List<CommitDataModel>>() { Data = Enumerable.Repeat(new CommitDataModel { Message = "1", SHA = "1" }, 1).ToList(), NextPageAvailable = false }; githubRestClient.Setup(x => x.GetResponse<List<CommitDataModel>>(firstCommitsLink)) .Returns(firstResponse) .Verifiable(); githubRestClient.Setup(x => x.GetResponse<List<CommitDataModel>>(secondCommitsLink)) .Returns(secondResponse) .Verifiable(); var provider = new GitHubDataProvider(githubRestClient.Object); provider.FindCommits(repositoryName, branchName, tagName); githubRestClient.VerifyAll(); }