Exemple #1
0
        /// <summary>
        /// Get the item in the repository at the given path.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="path">Path of the item to query</param>
        /// <param name="filters">Filters to provide additional query information</param>
        /// <param name="includeMetadata">To include item metadata or not</param>
        /// <returns>A list of commits in the Git repository</returns>
        public async Task<IEnumerable<Item>> GetItem(Guid repositoryId, string path, ItemFilters filters = null, bool includeMetadata = false)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(path, "path");

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

            // This header instructs VSO to return metadata rather than the item contents
            request.AddHeader("Accept", "application/json");

            filters = filters ?? new ItemFilters();

            request.AddParameter("scopePath", path);

            request.AddOptionalParameter("recursionLevel",
                filters.RecursionLevel,
                () => { return filters.RecursionLevel != RecursionLevel.None; });

            if (includeMetadata)
            {
                request.AddParameter("includeContentMetadata", "true");
            }

            Sequence<Item> list = await Executor.Execute<Sequence<Item>>(request);
            return list.Value;
        }
Exemple #2
0
        /// <summary>
        /// Get the items in the repository at the given path.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="paths">Paths (and filters) of the items to query</param>
        /// <param name="includeMetadata">True to include item metadata</param>
        /// <returns>A list of commits in the Git repository</returns>
        public async Task<IEnumerable<IEnumerable<Item>>> GetItems(Guid repositoryId, IEnumerable<Tuple<string, ItemFilters>> paths, bool includeMetadata = false)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(paths, "paths");

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

            // This header instructs VSO to return metadata rather than the item contents
            request.AddHeader("Accept", "application/json");

            request.AddBody(new
            {
                itemDescriptors = paths.Select(x => new { 
                    path = x.Item1,
                    version = x.Item2.Revision != null ? x.Item2.Revision.Version : "",
                    versionType = x.Item2.Revision != null ? x.Item2.Revision.Type.ToString().ToLowerInvariant() : "",
                    versionOptions = x.Item2.RevisionOptions.ToString().ToLowerInvariant(),
                    recursionLevel = x.Item2.RecursionLevel.ToString().ToLowerInvariant(),
                }),
                includeContentMetadata = includeMetadata ? "true" : "false",
            });

            Sequence<List<Item>> list = await Executor.Execute<Sequence<List<Item>>>(request);
            return list.Value;
        }
        /// <summary>
        /// Get a list of all Team Projects within the current Project Collection.
        /// </summary>
        /// <param name="projectState">The state of the Team Project(s) to query</param>
        /// <param name="count">The maximum number of Team Projects to return</param>
        /// <param name="skip">The number of Team Projects to skip</param>
        /// <returns>The list of Team Projects that match the criteria</returns>
        public async Task<IEnumerable<Project>> GetProjects(
            ProjectState projectState = ProjectState.All,
            int count = 0,
            int skip = 0)
        {
            var request = new TfsRestRequest("/_apis/projects");

            if (projectState != ProjectState.All)
            {
                request.AddParameter("statefilter", projectState.ToString());
            }

            if (count > 0)
            {
                request.AddParameter("top", count);
            }

            if (skip > 0)
            {
                request.AddParameter("$skip", skip);
            }

            Sequence<Project> projects = await Executor.Execute<Sequence<Project>>(request);
            return (projects != null) ? projects.Value : new List<Project>();
        }
        /// <summary>
        /// Get a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <returns>The Team Room</returns>
        public async Task<TeamRoom> GetRoom(int roomId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}");
            request.AddUrlSegment("RoomId", roomId.ToString());

            return await Executor.Execute<TeamRoom>(request);
        }
        /// <summary>
        /// Get a list of Team Rooms.
        /// </summary>
        /// <returns>The list of Team Rooms</returns>
        public async Task<IEnumerable<TeamRoom>> GetRooms()
        {
            var request = new TfsRestRequest("/_apis/chat/rooms");

            Sequence<TeamRoom> list = await Executor.Execute<Sequence<TeamRoom>>(request);
            return list.Value;
        }
        /// <summary>
        /// Get a list of all Team Projects within the current Project Collection.
        /// </summary>
        /// <param name="projectState">The state of the Team Project(s) to query</param>
        /// <param name="count">The maximum number of Team Projects to return</param>
        /// <param name="skip">The number of Team Projects to skip</param>
        /// <returns>The list of Team Projects that match the criteria</returns>
        public async Task <IEnumerable <Project> > GetProjects(
            ProjectState projectState = ProjectState.All,
            int count = 0,
            int skip  = 0)
        {
            var request = new TfsRestRequest("/_apis/projects");

            if (projectState != ProjectState.All)
            {
                request.AddParameter("statefilter", projectState.ToString());
            }

            if (count > 0)
            {
                request.AddParameter("top", count);
            }

            if (skip > 0)
            {
                request.AddParameter("$skip", skip);
            }

            Sequence <Project> projects = await Executor.Execute <Sequence <Project> >(request);

            return((projects != null) ? projects.Value : new List <Project>());
        }
Exemple #7
0
        /// <summary>
        /// Get the statistics about all branches.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <returns>The branch statistics</returns>
        public async Task<IEnumerable<BranchStatistics>> GetBranchStatistics(Guid repositoryId)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/stats/branches");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());

            Sequence<BranchStatistics> list = await Executor.Execute<Sequence<BranchStatistics>>(request);
            return list.Value;
        }
        /// <summary>
        /// Get a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <returns>The Team Room</returns>
        public async Task <TeamRoom> GetRoom(int roomId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}");

            request.AddUrlSegment("RoomId", roomId.ToString());

            return(await Executor.Execute <TeamRoom>(request));
        }
        /// <summary>
        /// Get a list of Team Rooms.
        /// </summary>
        /// <returns>The list of Team Rooms</returns>
        public async Task <IEnumerable <TeamRoom> > GetRooms()
        {
            var request = new TfsRestRequest("/_apis/chat/rooms");

            Sequence <TeamRoom> list = await Executor.Execute <Sequence <TeamRoom> >(request);

            return(list.Value);
        }
        /// <summary>
        /// Get the details of a user in a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <param name="userId">The ID of the user</param>
        /// <returns>The user details</returns>
        public async Task <TeamRoomUserDetails> GetUser(int roomId, Guid userId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/users/{UserId}");

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddUrlSegment("UserId", userId.ToString());
            return(await Executor.Execute <TeamRoomUserDetails>(request));
        }
Exemple #11
0
        /// <summary>
        /// Get a pull request in a Git repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository that contains the pull request</param>
        /// <param name="id">The ID of the pull request</param>
        /// <returns>The pull request</returns>
        public async Task<PullRequest> GetPullRequest(Guid repositoryId, int id)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests/{Id}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("Id", String.Format("{0}", id));

            return await Executor.Execute<PullRequest>(request);
        }
Exemple #12
0
        /// <summary>
        /// Delete the given Git repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to delete</param>
        public async Task DeleteRepository(Guid repositoryId)
        {
            Assert.NotNull(repositoryId, "repositoryId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}", HttpMethod.Delete);
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            await Executor.Execute(request);
        }
        /// <summary>
        /// Update a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room to update</param>
        /// <param name="name">The new name of the Team Room</param>
        /// <param name="description">The new description of the Team Room</param>
        /// <returns>The updated Team Room</returns>
        public async Task<TeamRoom> UpdateRoom(int roomId, string name, string description)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}", new HttpMethod("PATCH"));
            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddBody(new { name = name, description = description });

            return await Executor.Execute<TeamRoom>(request);
        }
        /// <summary>
        /// Deletes a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room to delete</param>
        public async Task DeleteRoom(int roomId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}", HttpMethod.Delete);

            request.AddUrlSegment("RoomId", roomId.ToString());

            await Executor.Execute(request);
        }
        /// <summary>
        /// Update a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room to update</param>
        /// <param name="name">The new name of the Team Room</param>
        /// <param name="description">The new description of the Team Room</param>
        /// <returns>The updated Team Room</returns>
        public async Task <TeamRoom> UpdateRoom(int roomId, string name, string description)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}", new HttpMethod("PATCH"));

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddBody(new { name = name, description = description });

            return(await Executor.Execute <TeamRoom>(request));
        }
        /// <summary>
        /// Get the contents of a message in a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <param name="messageId">The message ID to retrieve</param>
        /// <returns>The message</returns>
        public async Task <TeamRoomMessage> GetMessage(int roomId, int messageId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/messages/{MessageId}", HttpMethod.Get);

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddUrlSegment("MessageId", messageId.ToString());

            return(await Executor.Execute <TeamRoomMessage>(request));
        }
Exemple #17
0
        /// <summary>
        /// Get the information about a reviewer listed for a pull request.
        /// </summary>
        /// <param name="repositoryId">The repository</param>
        /// <param name="pullRequestId">The pull request</param>
        /// <param name="reviewerId">The reviewer</param>
        /// <returns>The reviewer for the pull request</returns>
        public async Task<PullRequestReviewer> GetPullRequestReviewer(Guid repositoryId, int pullRequestId, Guid reviewerId)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests/{PullRequestId}/reviewers/{ReviewerId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PullRequestId", pullRequestId.ToString());
            request.AddUrlSegment("ReviewerId", reviewerId.ToString());

            return await Executor.Execute<PullRequestReviewer>(request);
        }
Exemple #18
0
        /// <summary>
        /// Create a new Git repository inside a Team Project.
        /// </summary>
        /// <param name="projectId">The ID of the Team Project that will contain this repository</param>
        /// <param name="name">The name of the repository to create</param>
        /// <returns>The Git repository created</returns>
        /// <exception cref="Infinity.Exceptions.TfsConflictException">If a repository by the same name already exists</exception>
        public async Task<Repository> CreateRepository(Guid projectId, string name)
        {
            Assert.NotNull(projectId, "projectId");
            Assert.NotNull(name, "name");

            var request = new TfsRestRequest("/_apis/git/repositories", HttpMethod.Post);
            request.AddBody(new { name = name, project = new { id = projectId.ToString() } });
            return await Executor.Execute<Repository>(request);
        }
Exemple #19
0
        /// <summary>
        /// Get a list of commits included in the push.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="pushId">The ID of the push to query</param>
        /// <returns>A list of commits in the push</returns>
        public async Task<IEnumerable<Commit>> GetPushCommits(Guid repositoryId, int pushId)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pushes/{PushId}/commits");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PushId", pushId.ToString());

            Sequence<Commit> list = await Executor.Execute<Sequence<Commit>>(request);
            return list.Value;
        }
Exemple #20
0
        /// <summary>
        /// Deletes a reviewer from a pull request
        /// </summary>
        /// <param name="repositoryId">The repository</param>
        /// <param name="pullRequestId">The pull request</param>
        /// <param name="reviewerId">The reviewer</param>
        /// <returns>The reviewer for the pull request</returns>
        public async Task DeletePullRequestReviewer(Guid repositoryId, int pullRequestId, Guid reviewerId)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests/{PullRequestId}/reviewers/{ReviewerId}", HttpMethod.Delete);
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PullRequestId", pullRequestId.ToString());
            request.AddUrlSegment("ReviewerId", reviewerId.ToString());

            await Executor.Execute(request);
        }
Exemple #21
0
        /// <summary>
        /// Get the information about a Git repository by its ID.
        /// </summary>
        /// <param name="id">The ID of the Git repository</param>
        /// <returns>The Git repository</returns>
        public async Task<Repository> GetRepository(Guid id)
        {
            Assert.NotNull(id, "id");

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

            return await Executor.Execute<Repository>(request);
        }
        /// <summary>
        /// Update the content of an existing Team Room message.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <param name="messageId">The ID of the message to edit</param>
        /// <param name="content">The new content of the message</param>
        /// <returns>The updated message</returns>
        public async Task <TeamRoomMessage> UpdateMessage(int roomId, int messageId, string content)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/messages/{MessageId}", new HttpMethod("PATCH"));

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddUrlSegment("MessageId", messageId.ToString());
            request.AddBody(new { content = content });

            return(await Executor.Execute <TeamRoomMessage>(request));
        }
        /// <summary>
        /// Get the list of users in a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room</param>
        /// <returns>The list of users</returns>
        public async Task <IEnumerable <TeamRoomUserDetails> > GetUsers(int roomId)
        {
            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/users");

            request.AddUrlSegment("RoomId", roomId.ToString());

            Sequence <TeamRoomUserDetails> list = await Executor.Execute <Sequence <TeamRoomUserDetails> >(request);

            return(list.Value);
        }
        /// <summary>
        /// Leave a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room to leave</param>
        /// <param name="userId">The ID of the user of the leaving user</param>
        public async Task LeaveRoom(int roomId, Guid userId)
        {
            Assert.NotNull(userId, "userId");

            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/users/{UserId}", HttpMethod.Delete);

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddUrlSegment("UserId", userId.ToString());
            await Executor.Execute(request);
        }
Exemple #25
0
        /// <summary>
        /// Get a list of teams for a project.
        /// </summary>
        /// <param name="projectId">The project ID to query teams for</param>
        /// <returns>The list of teams</returns>
        public async Task<IEnumerable<Team>> GetTeams(Guid projectId)
        {
            Assert.NotNull(projectId, "projectId");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}/teams");
            request.AddUrlSegment("ProjectId", projectId.ToString());

            Sequence<Team> list = await Executor.Execute<Sequence<Team>>(request);
            return list.Value;
        }
        /// <summary>
        /// Create a new Team Room.
        /// </summary>
        /// <param name="name">The name of the Team Room to create</param>
        /// <param name="description">The description of the Team Room</param>
        /// <returns>The newly created Team Room</returns>
        public async Task<TeamRoom> CreateRoom(string name, string description)
        {
            Assert.NotNull(name, "name");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/chat/rooms", HttpMethod.Post);
            request.AddBody(new { name = name, description = description });

            return await Executor.Execute<TeamRoom>(request);
        }
Exemple #27
0
        /// <summary>
        /// Rename a Git repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to rename</param>
        /// <param name="newName">The new name of the repository</param>
        /// <returns>The Git repository after update</returns>
        public async Task<Repository> RenameRepository(Guid repositoryId, string newName)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(newName, "newName");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}", new HttpMethod("PATCH"));
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddBody(new { name = newName });
            return await Executor.Execute<Repository>(request);
        }
Exemple #28
0
        /// <summary>
        /// Get a project's team.
        /// </summary>
        /// <param name="projectId">The project ID that contains the team</param>
        /// <param name="teamId">The team ID to query</param>
        /// <returns>The team</returns>
        public async Task<Team> GetTeam(Guid projectId, Guid teamId)
        {
            Assert.NotNull(projectId, "projectId");
            Assert.NotNull(teamId, "teamId");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}/teams/{TeamId}");
            request.AddUrlSegment("ProjectId", projectId.ToString());
            request.AddUrlSegment("TeamId", teamId.ToString());

            return await Executor.Execute<Team>(request);
        }
Exemple #29
0
        /// <summary>
        /// Get the information about a Git repository by its name.
        /// </summary>
        /// <param name="projectId">The ID of the Team Project that contains this repository</param>
        /// <param name="name">The name of the Git repository</param>
        /// <returns>The Git repository</returns>
        public async Task<Repository> GetRepository(Guid projectId, string name)
        {
            Assert.NotNull(projectId, "projectId");
            Assert.NotNull(name, "name");

            var request = new TfsRestRequest("/_apis/git/{ProjectId}/repositories/{Name}");
            request.AddUrlSegment("ProjectId", projectId.ToString());
            request.AddUrlSegment("Name", name);

            return await Executor.Execute<Repository>(request);
        }
        /// <summary>
        /// Create a new Team Room.
        /// </summary>
        /// <param name="name">The name of the Team Room to create</param>
        /// <param name="description">The description of the Team Room</param>
        /// <returns>The newly created Team Room</returns>
        public async Task <TeamRoom> CreateRoom(string name, string description)
        {
            Assert.NotNull(name, "name");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/chat/rooms", HttpMethod.Post);

            request.AddBody(new { name = name, description = description });

            return(await Executor.Execute <TeamRoom>(request));
        }
        /// <summary>
        /// Write a message in a Team Room.
        /// </summary>
        /// <param name="roomId">The ID of the Team Room to write to</param>
        /// <param name="content">The message to write</param>
        public async Task <TeamRoomMessage> CreateMessage(int roomId, string content)
        {
            Assert.NotNull(content, "content");

            var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/messages", HttpMethod.Post);

            request.AddUrlSegment("RoomId", roomId.ToString());
            request.AddBody(new { content = content });

            return(await Executor.Execute <TeamRoomMessage>(request));
        }
Exemple #32
0
        /// <summary>
        /// Update the project information.
        /// </summary>
        /// <param name="id">The ID of the Team Project.</param>
        /// <param name="description">The description to update in the project</param>
        /// <returns>The Team Project, after update</returns>
        public async Task <Project> UpdateProject(Guid id, string description)
        {
            Assert.NotNull(id, "id");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}", new HttpMethod("PATCH"));

            request.AddUrlSegment("ProjectId", id.ToString());
            request.AddBody(new { description = description });
            return(await Executor.Execute <Project>(request));
        }
Exemple #33
0
        /// <summary>
        /// Update the project information.
        /// </summary>
        /// <param name="name">The name of the project to update</param>
        /// <param name="description">The description to update in the project</param>
        /// <returns>The Team Project, after update</returns>
        public async Task <Project> UpdateProject(string name, string description)
        {
            Assert.NotNull(name, "name");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/projects/{Name}", new HttpMethod("PATCH"));

            request.AddUrlSegment("Name", name);
            request.AddBody(new { description = description });
            return(await Executor.Execute <Project>(request));
        }
Exemple #34
0
        /// <summary>
        /// Get the information about a Git blob by its ID.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="blobId">The object ID of the blob</param>
        /// <returns>The blob</returns>
        public async Task<Blob> GetBlob(Guid repositoryId, ObjectId blobId)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(blobId, "blobId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/blobs/{BlobId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("BlobId", blobId.ToString());

            return await Executor.Execute<Blob>(request);
        }
Exemple #35
0
        /// <summary>
        /// Get a commit in a repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="commitId">The ID of the commit</param>
        /// <param name="changeCount">The number of changes to return, or 0 for none.</param>
        /// <returns>The commit in the Git repository</returns>
        public async Task<Commit> GetCommit(Guid repositoryId, ObjectId commitId, int changeCount = 0)
        {
            Assert.NotNull("commitId", "commitId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/commits/{CommitId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("CommitId", commitId.ToString());
            request.AddOptionalParameter("changeCount", changeCount, () => { return changeCount > 0; });

            return await Executor.Execute<Commit>(request);
        }
Exemple #36
0
        /// <summary>
        /// Get the information about a Git tree by its ID.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="treeId">The object ID of the tree</param>
        /// <returns>The tree</returns>
        public async Task<Tree> GetTree(Guid repositoryId, ObjectId treeId)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(treeId, "treeId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/trees/{TreeId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("TreeId", treeId.ToString());

            return await Executor.Execute<Tree>(request);
        }
Exemple #37
0
        /// <summary>
        /// Get a project's team.
        /// </summary>
        /// <param name="projectId">The project ID that contains the team</param>
        /// <param name="teamId">The team ID to query</param>
        /// <returns>The team</returns>
        public async Task <Team> GetTeam(Guid projectId, Guid teamId)
        {
            Assert.NotNull(projectId, "projectId");
            Assert.NotNull(teamId, "teamId");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}/teams/{TeamId}");

            request.AddUrlSegment("ProjectId", projectId.ToString());
            request.AddUrlSegment("TeamId", teamId.ToString());

            return(await Executor.Execute <Team>(request));
        }
        /// <summary>
        /// Get the Team Project by ID.
        /// 
        /// Optionally queries the "capabilities" for the team project,
        /// including source control type (TFVC or Git) and process
        /// template.
        /// </summary>
        /// <param name="id">The ID of the Team Project.</param>
        /// <param name="includeCapabilities">true to include project capabilities</param>
        /// <returns>The Team Project, or <code>null</code> if none matched</returns>
        public async Task<Project> GetProject(Guid id, bool includeCapabilities = false)
        {
            Assert.NotNull(id, "id");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}");
            request.AddUrlSegment("ProjectId", id.ToString());

            if (includeCapabilities)
            {
                request.AddParameter("includecapabilities", "true");
            }

            return await Executor.Execute<Project>(request);
        }
Exemple #39
0
        /// <summary>
        /// Download a blob's contents.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="blobId">The object ID of the blob</param>
        /// <param name="format">The format to download as</param>
        /// <param name="outputStream">The stream to write the response content to asynchronously</param>
        public async Task DownloadBlob(Guid repositoryId, ObjectId blobId, BlobFormat format, Stream outputStream)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(blobId, "blobId");
            Assert.NotNull(outputStream, "outputStream");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/blobs/{BlobId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("BlobId", blobId.ToString());

            if (format == BlobFormat.Zip)
            {
                request.AddUrlSegment("$format", "zip");
                request.AddHeader("Accept", "application/zip");
            }
            else
            {
                request.AddUrlSegment("$format", "octetstream");
                request.AddHeader("Accept", "application/octet-stream");
            }

            await Executor.Execute(request, outputStream);
        }
Exemple #40
0
        /// <summary>
        /// Get a push in a Git repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="id">The ID of the push</param>
        /// <param name="includeRefUpdates">Whether to include information about references that were updated</param>
        /// <returns>A list of pushes in the Git repository</returns>
        public async Task<PushDetails> GetPush(Guid repositoryId, int id, bool includeRefUpdates = false)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pushes/{PushId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PushId", id.ToString());

            if (includeRefUpdates)
            {
                request.AddParameter("includeRefUpdates", "true");
            }

            return await Executor.Execute<PushDetails>(request);
        }
Exemple #41
0
        /// <summary>
        /// Get the references (branches, tags, notes) in the given repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the Git repository</param>
        /// <param name="filter">The string prefix to match, excepting the <code>refs/</code> prefix.  For example, <code>heads/</code> will return branches.</param>
        /// <returns>The list of references.</returns>
        public async Task<IEnumerable<Reference>> GetReferences(Guid repositoryId, string filter = null)
        {
            Assert.NotNull(repositoryId, "repositoryId");

            if (filter != null)
            {
                Assert.IsTrue(filter.StartsWith("refs/"), "filter.StartsWith(refs/)");
                filter = filter.Substring(4);
            }

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/refs{Filter}", HttpMethod.Get);
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("Filter", filter != null ? filter : "");

            Sequence<Reference> references = await Executor.Execute<Sequence<Reference>>(request);
            return (references != null) ? references.Value : new List<Reference>();
        }
Exemple #42
0
        /// <summary>
        /// Get a list of all Git repositories managed in a TFS Team Project.
        /// </summary>
        /// <param name="projectId">The ID of the Team Project to query</param>
        /// <returns>A list of repositories in the Project Collection</returns>
        public async Task<IEnumerable<Repository>> GetRepositories(Guid? projectId = null)
        {
            TfsRestRequest request;

            if (projectId != null)
            {
                request = new TfsRestRequest("/_apis/git/{ProjectId}/repositories");
                request.AddUrlSegment("ProjectId", projectId.ToString());
            }
            else
            {
                request = new TfsRestRequest("/_apis/git/repositories");
            }

            Sequence<Repository> list = await Executor.Execute<Sequence<Repository>>(request);
            return list.Value;
        }
        /// <summary>
        /// Get the Team Project by name.
        /// 
        /// Optionally queries the "capabilities" for the team project,
        /// including source control type (TFVC or Git) and process
        /// template.
        /// </summary>
        /// <param name="name">The name of the Team Project.</param>
        /// <param name="includeCapabilities">true to include project capabilities</param>
        /// <returns>The Team Project, or <code>null</code> if none matched</returns>
        public async Task<Project> GetProject(string name, bool includeCapabilities = false)
        {
            Assert.NotNull(name, "name");

            var request = new TfsRestRequest("/_apis/projects/{Name}");
            request.AddUrlSegment("Name", name);

            if (includeCapabilities)
            {
                request.AddParameter("includecapabilities", "true");
            }

            return await Executor.Execute<Project>(request);
        }
Exemple #44
0
        /// <summary>
        /// Updates the reviewer's vote for a pull request.
        /// </summary>
        /// <param name="repositoryId">The repository</param>
        /// <param name="pullRequestId">The pull request</param>
        /// <param name="reviewerId">The reviewer</param>
        /// <param name="vote">The vote for the reviewer</param>
        /// <returns>The reviewer for the pull request</returns>
        public async Task<PullRequestReviewer> UpdatePullRequestReviewer(Guid repositoryId, int pullRequestId, Guid reviewerId, PullRequestVote vote)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests/{PullRequestId}/reviewers/{ReviewerId}", HttpMethod.Put);
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PullRequestId", pullRequestId.ToString());
            request.AddUrlSegment("ReviewerId", reviewerId.ToString());
            request.AddBody(new
            {
                vote = (int)vote
            });

            return await Executor.Execute<PullRequestReviewer>(request);
        }
        /// <summary>
        /// Update the project information.
        /// </summary>
        /// <param name="name">The name of the project to update</param>
        /// <param name="description">The description to update in the project</param>
        /// <returns>The Team Project, after update</returns>
        public async Task<Project> UpdateProject(string name, string description)
        {
            Assert.NotNull(name, "name");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/projects/{Name}", new HttpMethod("PATCH"));
            request.AddUrlSegment("Name", name);
            request.AddBody(new { description = description });
            return await Executor.Execute<Project>(request);
        }
        /// <summary>
        /// Update the project information.
        /// </summary>
        /// <param name="id">The ID of the Team Project.</param>
        /// <param name="description">The description to update in the project</param>
        /// <returns>The Team Project, after update</returns>
        public async Task<Project> UpdateProject(Guid id, string description)
        {
            Assert.NotNull(id, "id");
            Assert.NotNull(description, "description");

            var request = new TfsRestRequest("/_apis/projects/{ProjectId}", new HttpMethod("PATCH"));
            request.AddUrlSegment("ProjectId", id.ToString());
            request.AddBody(new { description = description });
            return await Executor.Execute<Project>(request);
        }
Exemple #47
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);
        }
Exemple #48
0
        /// <summary>
        /// Download the contents of a tree as a zip file.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="treeId">The object ID of the tree</param>
        /// <param name="outputStream">The stream to write to asynchronously</param>
        public async Task DownloadTree(Guid repositoryId, ObjectId treeId, Stream outputStream)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(treeId, "treeId");
            Assert.NotNull(outputStream, "outputStream");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/trees/{TreeId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("TreeId", treeId.ToString());
            request.AddUrlSegment("$format", "zip");
            request.AddHeader("Accept", "application/zip");

            await Executor.Execute(request, outputStream);
        }
Exemple #49
0
        /// <summary>
        /// Get a list of pushes in a Git repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository to query</param>
        /// <param name="filters">Optional push filters</param>
        /// <returns>A list of pushes in the Git repository</returns>
        public async Task<IEnumerable<PushDetails>> GetPushes(Guid repositoryId, PushFilters filters = null)
        {
            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pushes");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());

            filters = filters ?? new PushFilters();

            request.AddOptionalParameter("fromDate", filters.FromDate);
            request.AddOptionalParameter("toDate", filters.ToDate);
            request.AddOptionalParameter("pusherId", filters.Pusher);
            request.AddOptionalParameter("$skip", filters.Skip, () => { return filters.Skip > 0; });
            request.AddOptionalParameter("$top", filters.Count, () => { return filters.Count > 0; });

            Sequence<PushDetails> list = await Executor.Execute<Sequence<PushDetails>>(request);
            return list.Value;
        }
Exemple #50
0
        /// <summary>
        /// Updates the pull request data, abandoning or completing it.
        /// </summary>
        /// <param name="repositoryId">The repository</param>
        /// <param name="pullRequestId">The pull request to update</param>
        /// <param name="status">The new status</param>
        /// <param name="lastMergeSourceCommitId">The last merge source commit ID (to confirm)</param>
        /// <returns>The updated pull request</returns>
        public async Task<PullRequest> UpdatePullRequest(Guid repositoryId, int pullRequestId, PullRequestStatus status, string lastMergeSourceCommitId)
        {
            Assert.NotNull(lastMergeSourceCommitId, "lastMergeSourceCommitId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests/{PullRequestId}", new HttpMethod("PATCH"));
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("PullRequestId", pullRequestId.ToString());
            request.AddBody(new
            {
                status = status.ToString().ToLower(),
                lastMergeSourceCommit = new { commitId = lastMergeSourceCommitId }
            });

            return await Executor.Execute<PullRequest>(request);
        }