【问题标题】:TF401398: The pull request cannot be activated because the source and/or the target branch no longer exists, or the requested refs are not branchesTF401398: 无法激活拉取请求,因为源和/或目标分支不再存在,或者请求的引用不是分支
【发布时间】:2021-11-04 21:25:58
【问题描述】:

我在使用 azuredevops golang API 创建拉取请求时遇到以下错误

错误: TF401398: 无法激活拉取请求,因为源和/或目标分支不再存在,或者请求的引用不是分支

代码:

    connection := azuredevops.NewPatConnection("organizationUrl", "PAToken")
    ctx := context.Background()
    client, _ := azuregit.NewClient(ctx, connection)
    pr := azuregit.CreatePullRequestArgs{}
    repoId := git.repository.Name
    proname := "MVC Test -Demo"
    pr.Project = &proname
    pr.RepositoryId = &repoId
    sourceBranch:= "feature-test"
    targetBranch:= "main"
    pr.GitPullRequestToCreate = &azuregit.GitPullRequest{
        TargetRefName: &targetBranch,
        SourceRefName: &sourceBranch,
        Description:   &git.configuration.PrRequestMessage,
        Title:         &git.configuration.PrRequestTitle,
    }
    _, err := client.CreatePullRequest(ctx, pr)

【问题讨论】:

    标签: go azure-devops-rest-api azure-repos


    【解决方案1】:

    通过在分支前添加 refs/heads/ 前缀解决了这个问题

            sourceBranch:= "refs/heads/feature-test"
            targetBranch:= "refs/heads/main"
            pr.GitPullRequestToCreate = &azuregit.GitPullRequest{
                TargetRefName: &targetBranch,
                SourceRefName: &sourceBranch,
                Description:   &git.configuration.PrRequestMessage,
                Title:         &git.configuration.PrRequestTitle,
            }
            _, err := client.CreatePullRequest(ctx, pr)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多