示例#1
0
        /// <summary>
        /// Get the statistics about a branch.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="branch">The name of the branch to return statistics for</param>
        /// <param name="baseRevision">The revision to compare this branch to</param>
        /// <returns>The branch statistics</returns>
        public async Task<BranchStatistics> GetBranchStatistics(Guid repositoryId, string branch, Revision baseRevision = null)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(branch, "branch");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/stats/branches/{Branch}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("Branch", branch);

            if (baseRevision != null)
            {
                request.AddBody(new {
                    baseVersionType = baseRevision.Type,
                    baseVersion = baseRevision.Version
                });
            }

            return await Executor.Execute<BranchStatistics>(request);
        }
示例#2
0
        /// <summary>
        /// Get a list of commits leading to a revision, optionally beginning
        /// from a prior revision.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="targetRevision">The revision to query from</param>
        /// <param name="baseRevision">The revision to begin querying</param>
        /// <returns>A list of commits in the Git repository</returns>
        public async Task<IEnumerable<Commit>> GetCommits(Guid repositoryId, Revision targetRevision, Revision baseRevision = null)
        {
            Assert.NotNull("targetRevision", "targetRevision");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/commitsBatch", HttpMethod.Post);
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());

            if (baseRevision != null)
            {
                request.AddBody(new {
                    itemVersion = targetRevision.GetProperties(),
                    compareVersion = baseRevision.GetProperties()
                });
            }
            else
            {
                request.AddBody(new { itemVersion = targetRevision.GetProperties() });
            }

            Sequence<Commit> list = await Executor.Execute<Sequence<Commit>>(request);
            return list.Value;
        }