private static async Task <GitPullRequest> CreatePlaceholderBranchAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var gitClient = ProjectCollection.GetClient <GitHttpClient>(); var repository = await gitClient.GetRepositoryAsync(project : Options.TFSProjectName, repositoryId : "VS", cancellationToken : cancellationToken); var refs = await gitClient.GetRefsAsync( repository.Id, filter : $"heads/{Options.VisualStudioBranchName}", cancellationToken : cancellationToken); GitRef sourceBranch = refs.Single(r => r.Name == $"refs/heads/{Options.VisualStudioBranchName}"); var branchName = GetNewBranchName(); _ = await gitClient.CreatePushAsync(new GitPush() { RefUpdates = new[] { new GitRefUpdate() { Name = $"refs/heads/{branchName}", OldObjectId = sourceBranch.ObjectId, } }, Commits = new[] { new GitCommitRef() { Comment = $"PLACEHOLDER INSERTION FOR {Options.InsertionName}", Changes = new GitChange[] { new GitChange() { ChangeType = VersionControlChangeType.Delete, Item = new GitItem() { Path = "/Init.ps1" } }, } }, }, }, repository.Id, cancellationToken : cancellationToken); return(await CreatePullRequestAsync( branchName, $"PLACEHOLDER INSERTION FOR {Options.InsertionName}", "Not Specified", Options.TitlePrefix, reviewerId : MLInfraSwatUserId.ToString(), cancellationToken)); }
private static GitPullRequest CreatePullRequest(string sourceBranch, string targetBranch, string description, string buildToInsert, string titlePrefix) { Console.WriteLine($"Creating pull request sourceBranch:{sourceBranch} targetBranch:{targetBranch} description:{description}"); var prefix = string.IsNullOrEmpty(titlePrefix) ? string.Empty : titlePrefix + " "; return(new GitPullRequest { Title = $"{prefix}{Options.InsertionName} '{Options.BranchName}/{buildToInsert}' Insertion into {Options.VisualStudioBranchName}", Description = description, SourceRefName = sourceBranch, TargetRefName = targetBranch, IsDraft = Options.CreateDraftPr, Reviewers = new[] { new IdentityRefWithVote { Id = MLInfraSwatUserId.ToString() } } }); }