I was getting the following errors while creating a pull-request using azuredevops golang API
error: TF401398: The pull request cannot be activated because the source and/or the target branch no longer exists, or the requested refs are not branches
Code :
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)