You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps如何将分支名设为Pull Request标题默认值?

在Azure DevOps中自动将分支名设为Pull Request标题默认值的方法

Azure DevOps的原生PR模板仅支持填充描述内容,无法设置标题默认值,你可以通过以下几种方式实现需求:

  • 使用Azure DevOps Marketplace扩展
    安装类似Pull Request Title Generator的扩展(在Azure DevOps组织的Marketplace中搜索即可),这类扩展可以配置规则,自动将源分支名称填充为PR标题,部分还支持解析分支命名规范(比如去除feature/、bugfix/这类前缀),无需手动输入。

  • 自定义脚本调用REST API
    编写简单的脚本(比如PowerShell或Bash),调用Azure DevOps的Pull Request创建API,自动将分支名设为标题。示例PowerShell脚本片段:

    $orgName = "你的组织名"
    $projName = "你的项目名"
    $repoId = "仓库ID"
    $sourceBranch = "refs/heads/你的分支名"
    $targetBranch = "refs/heads/main"
    $title = $sourceBranch -replace "refs/heads/", "" # 提取纯分支名
    
    $body = @{
        sourceRefName = $sourceBranch
        targetRefName = $targetBranch
        title = $title
        description = "你的PR描述"
    } | ConvertTo-Json
    
    Invoke-RestMethod -Uri "https://dev.azure.com/$orgName/$projName/_apis/git/repositories/$repoId/pullrequests?api-version=7.1-preview.1" `
        -Method Post `
        -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} `
        -Body $body `
        -ContentType "application/json"
    

    你可以把这个脚本做成快捷方式,或者集成到VS Code等IDE的命令面板中,创建PR时一键执行。

  • 网页端快速调整(手动简化)
    在Azure DevOps网页端创建PR时,选择源分支后,标题框会自动生成[源分支名] 到 [目标分支名]的默认内容,你可以快速删除后半段的到 [目标分支名]部分,这是最简便的手动替代方案,但无法完全自动化。

内容的提问来源于stack exchange,提问作者R. Maier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 14:01:42