Azure DevOps Git API中CodeReviewThreadType有效值咨询
解决Azure DevOps Pull Request添加自定义系统消息的问题
直接给你能用的方案:用**SystemMessage** 这个CodeReviewThreadType有效值,它专门用来提交自定义的系统级提示消息,不会忽略你填写的content内容。
修正后的代码示例
REST API 请求
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads?api-version=7.1-preview.1 Content-Type: application/json { "comments": [ { "content": "Pull Request successfully linked with XY.", "parentCommentId": 0 } ], "threadType": "SystemMessage", "status": "Closed" }
C# SDK 示例
using Microsoft.TeamFoundation.SourceControl.WebApi; using Microsoft.VisualStudio.Services.WebApi; var connection = new VssConnection(new Uri("https://dev.azure.com/你的组织名"), new VssBasicCredential(string.Empty, "你的个人访问令牌")); var gitClient = connection.GetClient<GitHttpClient>(); var thread = new GitPullRequestThread { ThreadType = GitPullRequestThreadType.SystemMessage, Status = CommentThreadStatus.Closed, Comments = new List<GitPullRequestComment> { new GitPullRequestComment { Content = "Pull Request successfully linked with XY.", ParentCommentId = 0 } } }; await gitClient.CreateThreadAsync(thread, "你的项目名", "仓库ID", 你的PR编号);
效果说明
用SystemMessage提交后,消息会以系统提示的样式显示在Pull Request的「活动」标签页下,内容完全保留,不需要展开冗长的评论,正好符合你要的简洁系统通知需求。
你之前尝试的StatusUpdate、RefUpdate等类型属于Azure DevOps内部事件触发的线程,这类线程的内容是平台自动生成的,自定义内容会被强制忽略,所以必须用SystemMessage来实现自定义系统消息。
内容的提问来源于stack exchange,提问作者deerware
相关产品推荐
相关产品推荐

