async Task _createComment(string message, GitPullRequest pr, GitHttpClient gitClient, string repoId) { var comment = new Comment(); comment.Content = message; var cThread = new GitPullRequestCommentThread { Comments = new List <Comment>() }; cThread.Comments.Add(comment); await gitClient.CreateThreadAsync(cThread, repoId, pr.PullRequestId); }
/// <summary> /// Start new comment thread /// </summary> /// <param name="TeamProjectName"></param> /// <param name="RepoName"></param> /// <param name="PrId"></param> /// <param name="Title"></param> /// <param name="Status"></param> static void CreateNewCommentThread(string TeamProjectName, string RepoName, int PrId, string Title, CommentThreadStatus Status = CommentThreadStatus.Active) { GitPullRequest pr = GitClient.GetPullRequestAsync(TeamProjectName, RepoName, PrId).Result; GitPullRequestCommentThread gitThread = new GitPullRequestCommentThread(); gitThread.Status = Status; List <Microsoft.TeamFoundation.SourceControl.WebApi.Comment> comments = new List <Microsoft.TeamFoundation.SourceControl.WebApi.Comment>(); comments.Add(new Microsoft.TeamFoundation.SourceControl.WebApi.Comment { Content = Title }); gitThread.Comments = comments; var thread = GitClient.CreateThreadAsync(gitThread, TeamProjectName, RepoName, PrId).Result; }
public static async Task <IList <GitPullRequest> > TagStalePullRequests( GitHttpClient gitClient, string project, Dictionary <GitPullRequest, bool> stalePRs, string warningPrefix, int warningCount, string warningMessage, string abandonMessage) { List <GitPullRequest> pullCollection = new List <GitPullRequest>(); string commentMessage = string.Empty; foreach (KeyValuePair <GitPullRequest, bool> pr in stalePRs) { // Retrieve the tags so we can figure out what we need to remove, how many warnings have been given List <WebApiTagDefinition> allTags = await gitClient.GetPullRequestLabelsAsync(project, pr.Key.Repository.Id, pr.Key.PullRequestId); if (!pr.Value) { // PR has been updated since the last bot action, remove tags List <WebApiTagDefinition> tagsToRemove = allTags.Where(t => t.Name.StartsWith(warningPrefix)).ToList(); foreach (WebApiTagDefinition tag in tagsToRemove) { await gitClient.DeletePullRequestLabelsAsync(project, pr.Key.Repository.Id, pr.Key.PullRequestId, tag.Id.ToString()); } commentMessage = warningMessage; } else { // check how many tags are already on it, if it's more than the warning threshold, add it to the list of returned PRs int botTagCount = allTags.Where(t => t.Name.StartsWith(warningPrefix)).Count(); if (botTagCount >= warningCount) { pullCollection.Add(pr.Key); commentMessage = abandonMessage; } else { commentMessage = warningMessage; } } // Add a comment to the PR describing that it's stale Comment comment = new Comment { Content = string.Format(commentMessage, pr.Key.CreatedBy.Id) }; List <Comment> commentList = new List <Comment> { comment }; GitPullRequestCommentThread commentThread = new GitPullRequestCommentThread { Comments = commentList, Status = CommentThreadStatus.Active }; await gitClient.CreateThreadAsync(commentThread, pr.Key.Repository.Id, pr.Key.PullRequestId); // add a tag for this run WebApiCreateTagRequestData newLabel = new WebApiCreateTagRequestData { Name = string.Format("{0}: (UTC) {1}", warningPrefix, DateTime.UtcNow.ToString("g")) }; await gitClient.CreatePullRequestLabelAsync(newLabel, pr.Key.Repository.Id, pr.Key.PullRequestId); } return(pullCollection); }