/// <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> /// 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> /// 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> /// 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); }
/// <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> /// 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); }
/// <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> /// 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> /// Join a Team Room. You will be listed as present in the team room until /// you leave. /// </summary> /// <param name="roomId">The ID of the Team Room to join</param> /// <param name="userId">The ID of the user to join</param> public async Task JoinRoom(int roomId, Guid userId) { Assert.NotNull(userId, "userId"); var request = new TfsRestRequest("/_apis/chat/rooms/{RoomId}/users/{UserId}", HttpMethod.Put); request.AddUrlSegment("RoomId", roomId.ToString()); request.AddUrlSegment("UserId", userId.ToString()); request.AddBody(new { userId = userId }); await Executor.Execute(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)); }
/// <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)); }
/// <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; }
/// <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> /// 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); }
/// <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); }
/// <summary> /// Create a new pull request in the given repository, requesting to /// merge the given source branch into the given target branch. /// </summary> /// <param name="repositoryId">The repository</param> /// <param name="sourceRefName">Name of the source branch that contains the changes to merge</param> /// <param name="targetRefName">Name of the target branch that will be the destination of the merge</param> /// <param name="title">Title of the pull request</param> /// <param name="description">Description of the pull request</param> /// <param name="reviewers">Reviewers (optional)</param> /// <returns>The new pull request</returns> public async Task<PullRequest> CreatePullRequest(Guid repositoryId, string sourceRefName, string targetRefName, string title, string description, IEnumerable<Guid> reviewers = null) { Assert.NotNull(sourceRefName, "sourceRefName"); Assert.NotNull(targetRefName, "targetRefName"); Assert.NotNull(title, "title"); Assert.NotNull(description, "description"); if (reviewers == null) { reviewers = new Guid[0]; } var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/pullRequests", HttpMethod.Post); request.AddUrlSegment("RepositoryId", repositoryId.ToString()); request.AddBody(new { sourceRefName = sourceRefName, targetRefName = targetRefName, title = title, description = description, reviewers = reviewers.Select((id) => { return new { id = id.ToString() }; }) }); return await Executor.Execute<PullRequest>(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> /// 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); }
/// <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); }