public async Task OpenPullRequest(ForkData target, PullRequestRequest request, IEnumerable <string> labels) { var repos = await _client.GetGitRepositories(target.Owner); var repo = repos.Single(x => x.name == target.Name); var req = new PRRequest { title = request.Title, sourceRefName = $"refs/heads/{request.Head}", description = request.Body, targetRefName = $"refs/heads/{request.BaseRef}", completionOptions = new GitPullRequestCompletionOptions { deleteSourceBranch = request.DeleteBranchAfterMerge } }; var pullRequest = await _client.CreatePullRequest(req, target.Owner, repo.id); foreach (var label in labels) { await _client.CreatePullRequestLabel(new LabelRequest { name = label }, target.Owner, repo.id, pullRequest.PullRequestId); } }
public async Task OpenPullRequest(ForkData target, PullRequestRequest request, IEnumerable <string> labels) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (labels == null) { throw new ArgumentNullException(nameof(labels)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } var repos = await _client.GetGitRepositories(target.Owner); var repo = repos.Single(x => x.name.Equals(target.Name, StringComparison.OrdinalIgnoreCase)); var req = new PRRequest { title = request.Title, sourceRefName = $"refs/heads/{request.Head}", description = request.Body, targetRefName = $"refs/heads/{request.BaseRef}", }; var pullRequest = await _client.CreatePullRequest(req, target.Owner, repo.id); if (request.SetAutoMerge) { await _client.PatchPullRequest(new PRRequest() { autoCompleteSetBy = new Creator() { id = pullRequest.CreatedBy.id }, completionOptions = new GitPullRequestCompletionOptions { deleteSourceBranch = request.DeleteBranchAfterMerge, mergeStrategy = request.MergeStrategy.ToString(), }, }, target.Owner, repo.id, pullRequest.PullRequestId); } foreach (var label in labels) { await _client.CreatePullRequestLabel(new LabelRequest { name = label }, target.Owner, repo.id, pullRequest.PullRequestId); } }
public async Task OpenPullRequest(ForkData target, PullRequestRequest request, IEnumerable <string> labels) { var repos = await _client.GetGitRepositories(target.Owner); var repo = repos.Single(x => x.name == target.Name); var req = new PRRequest { title = request.Title, sourceRefName = $"refs/heads/{request.Head}", description = request.Body, targetRefName = $"refs/heads/{request.BaseRef}" }; await _client.CreatePullRequest(req, target.Owner, repo.id); }
public async Task <PullRequest> CreatePullRequest(PRRequest request, string projectName, string azureRepositoryId) { var response = await _client.PostAsync(BuildAzureDevOpsUri(($"{projectName}/_apis/git/repositories/{azureRepositoryId}/pullrequests")), new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { var error = await response.Content.ReadAsStringAsync(); var pullRequestErrorResource = JsonConvert.DeserializeObject <PullRequestErrorResource>(error); _logger.Error(pullRequestErrorResource.message); return(null); } var result = await response.Content.ReadAsStringAsync(); var resource = JsonConvert.DeserializeObject <PullRequest>(result); return(resource); }
public async Task <PullRequest> PatchPullRequest(PRRequest request, string projectName, string azureRepositoryId, int pullRequestId) { var autoCompleteContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); return(await PatchResource <PullRequest>($"{projectName}/_apis/git/repositories/{azureRepositoryId}/pullRequests/{pullRequestId}", autoCompleteContent)); }
public async Task <PullRequest> CreatePullRequest(PRRequest request, string projectName, string azureRepositoryId) { var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); return(await PostResource <PullRequest>($"{projectName}/_apis/git/repositories/{azureRepositoryId}/pullrequests", content)); }