/// <summary> /// Creates a pull request for the specified repository. /// </summary> /// <remarks>http://developer.github.com/v3/pulls/#create-a-pull-request</remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="newPullRequest">A <see cref="NewPullRequest"/> instance describing the new PullRequest to create</param> /// <returns>A created <see cref="PullRequest"/> result</returns> public IObservable<PullRequest> Create(string owner, string name, NewPullRequest newPullRequest) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(newPullRequest, "newPullRequest"); return _client.Create(owner, name, newPullRequest).ToObservable(); }
public void PostsToCorrectUrl() { var newPullRequest = new NewPullRequest("some title", "branch:name", "branch:name"); var connection = Substitute.For<IApiConnection>(); var client = new PullRequestsClient(connection); client.Create("fake", "repo", newPullRequest); connection.Received().Post<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls"), newPullRequest); }
private async Task SubmitPRForNewChangesAsync(NewChanges newChanges, string branch, string prBranch) { using (var repository = new Repository(newChanges.TargetRepository.Path)) { s_logger.Debug($"Pushing {branch} to {newChanges.TargetRepository} to update {prBranch}"); var origin = repository.Network.Remotes["origin"]; repository.Network.Push(origin, new[] { "refs/heads/" + branch }, new PushOptions { CredentialsProvider = (url, usernameFromUrl, types) => new UsernamePasswordCredentials { Username = newChanges.TargetRepository.Configuration.UserName, Password = newChanges.TargetRepository.Configuration.Password, } }); } var targetRepo = newChanges.TargetRepository; var newPr = new NewPullRequest($"Mirror changes from { targetRepo.UpstreamOwner }/{string.Join(",", newChanges.changes.Keys)}", $"{ targetRepo.Owner}:{branch}", prBranch) { Body = $"This PR contains mirrored changes from { targetRepo.UpstreamOwner }/{string.Join(",", newChanges.changes.Keys)}\n\n\n**Please REBASE this PR when merging**" }; s_logger.Debug($"Creating pull request in {newChanges.TargetRepository.UpstreamOwner}"); var pr = await Client.PullRequest.Create(targetRepo.UpstreamOwner, targetRepo.Name, newPr); s_logger.Debug($"Adding the commits"); var commits = await Client.Repository.PullRequest.Commits(targetRepo.UpstreamOwner, targetRepo.Name, pr.Number); s_logger.Debug($"Getting Assignees"); var additionalAssignees = await Task.WhenAll(commits.Select(c => GetAuthorAsync(targetRepo, c.Sha)).Distinct()); try { var update = new PullRequestUpdate() { Body = pr.Body + "\n\n cc " + string.Join(" ", additionalAssignees.Select(a => "@" + a).Distinct()) }; await Client.PullRequest.Update(targetRepo.UpstreamOwner, targetRepo.Name, pr.Number, update); } catch (Exception) { } targetRepo.PendingPRs[prBranch] = new PullRequestInfo { Number = pr.Number, }; s_logger.Info($"Pull request #{pr.Number} created for {prBranch}"); UpdateEntities(_listCommits, pr.Url.ToString()); s_logger.Info($"Commit Entries modififed to show mirrored in the azure table"); ConfigFile.Save(targetRepo.Configuration); }
public async Task UpdatesMaster() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _repository.Name, newPullRequest); var merge = new MergePullRequest("thing the thing"); var result = await _fixture.Merge(Helper.UserName, _repository.Name, pullRequest.Number, merge); var master = await _client.GitDatabase.Reference.Get(Helper.UserName, _repository.Name, "heads/master"); Assert.Equal(result.Sha, master.Object.Sha); }
public async Task CanBeMergedWithShaSpecified() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var merge = new MergePullRequest { CommitMessage = "thing the thing", Sha = pullRequest.Head.Sha }; var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge); Assert.True(result.Merged); }
public async Task CanBeMerged() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _repository.Name, newPullRequest); var merge = new MergePullRequest { Message = "thing the thing" }; var result = await _fixture.Merge(Helper.UserName, _repository.Name, pullRequest.Number, merge); Assert.True(result.Merged); }
private Task CreatePullRequest( Repository repo, Branch defaultBranch, Reference prBranch, Comment comment, ContentRequest fileRequest) { var pullRequest = new NewPullRequest(fileRequest.Message, prBranch.Ref, defaultBranch.Name) { Body = $"avatar: <img src=\"{comment.avatar}\" />{NewLine}{NewLine}{comment.message}" }; return(_githubRepoClient.PullRequest.Create(repo.Id, pullRequest)); }
public async Task IgnoresOpenPullRequest() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var openPullRequests = new PullRequestRequest { State = ItemStateFilter.Closed }; var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, openPullRequests); Assert.Empty(pullRequests); }
public async Task CanGetOpenPullRequest() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var openPullRequests = new PullRequestRequest { State = ItemStateFilter.Open }; var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, openPullRequests); Assert.Equal(1, pullRequests.Count); Assert.Equal(result.Title, pullRequests[0].Title); }
public static async Task OpenAsync(PullRequestParameters parameters) { var inMemoryCredentialStore = new InMemoryCredentialStore(new Credentials(KnownGitHubs.Username, parameters.Password)); var githubClient = new GitHubClient(new ProductHeaderValue("ImgBot"), inMemoryCredentialStore); var repo = await githubClient.Repository.Get(parameters.RepoOwner, parameters.RepoName); var pr = new NewPullRequest(KnownGitHubs.CommitMessageTitle, KnownGitHubs.BranchName, repo.DefaultBranch) { Body = "Beep boop. Optimizing your images is my life. https://imgbot.net/ for more information." }; await githubClient.PullRequest.Create(parameters.RepoOwner, parameters.RepoName, pr); }
public async Task CanUpdate() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var updatePullRequest = new PullRequestUpdate { Title = "updated title", Body = "Hello New Body" }; var result = await _fixture.Update(Helper.UserName, _context.RepositoryName, pullRequest.Number, updatePullRequest); Assert.Equal(updatePullRequest.Title, result.Title); Assert.Equal(updatePullRequest.Body, result.Body); }
public async Task UpdatesMaster() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var merge = new MergePullRequest { CommitMessage = "thing the thing" }; var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge); var master = await _github.Git.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/master"); Assert.Equal(result.Sha, master.Object.Sha); }
public async Task CanClose() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var updatePullRequest = new PullRequestUpdate { State = ItemState.Closed }; var result = await _fixture.Update(Helper.UserName, _context.RepositoryName, pullRequest.Number, updatePullRequest); Assert.Equal(ItemState.Closed, result.State); Assert.Equal(pullRequest.Title, result.Title); Assert.Equal(pullRequest.Body, result.Body); }
public async Task CannotBeMergedDueMismatchConflict() { await CreateTheWorld(); var fakeSha = new string('f', 40); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var merge = new MergePullRequest { Sha = fakeSha }; var ex = await Assert.ThrowsAsync <PullRequestMismatchException>(() => _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge)); Assert.True(ex.Message.StartsWith("Head branch was modified")); }
public async Task <Pr> OpenAsync(GitHubClientParameters parameters, Settings settings = null) { var inMemoryCredentialStore = new InMemoryCredentialStore(new Credentials(KnownGitHubs.Username, parameters.Password)); var githubClient = new GitHubClient(new ProductHeaderValue("ImgBot"), inMemoryCredentialStore); var repo = await githubClient.Repository.Get(parameters.RepoOwner, parameters.RepoName); var branch = await githubClient.Repository.Branch.Get(parameters.RepoOwner, parameters.RepoName, KnownGitHubs.BranchName); var commit = await githubClient.Repository.Commit.Get(parameters.RepoOwner, parameters.RepoName, branch.Commit.Sha); if (branch == null) { return(null); } var baseBranch = repo.DefaultBranch; if (settings != null && !string.IsNullOrEmpty(settings.DefaultBranchOverride)) { baseBranch = settings.DefaultBranchOverride; } var stats = Stats.ParseStats(commit.Commit.Message); var pr = new NewPullRequest(KnownGitHubs.CommitMessageTitle, KnownGitHubs.BranchName, baseBranch) { Body = PullRequestBody.Generate(stats), }; var result = await githubClient.PullRequest.Create(parameters.RepoOwner, parameters.RepoName, pr); if (stats == null) { return(null); } return(new Pr(parameters.RepoOwner) { RepoName = parameters.RepoName, Id = result.Id, NumImages = stats.Length == 1 ? 1 : stats.Length - 1, Number = result.Number, SizeBefore = ImageStat.ToDouble(stats[0].Before), SizeAfter = ImageStat.ToDouble(stats[0].After), PercentReduced = stats[0].Percent, }); }
public async Task CanGetDraftForRepository() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a draft pull request", branchName, "master") { Draft = true }; var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName); Assert.Equal(1, pullRequests.Count); Assert.Equal(result.Title, pullRequests[0].Title); Assert.Equal(result.Draft, pullRequests[0].Draft); Assert.True(pullRequests[0].Id > 0); }
public async Task CanBeMergedWithRebaseMethod() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("squash commit pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var merge = new MergePullRequest { CommitMessage = "fake commit message", CommitTitle = "fake title", MergeMethod = PullRequestMergeMethod.Rebase }; var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge); var commit = await _github.Repository.Commit.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha); Assert.True(result.Merged); Assert.Equal("this is a 2nd commit to merge into the pull request", commit.Commit.Message); }
public PullRequest CreatePullRequest(BranchName sourceBranch, BranchName destinationBranch, string title, string body) { _logger.LogDebug("Creating pull request from {sourceBranchName} to {destinationBranchName}", sourceBranch, destinationBranch); var client = CreateGitHubClient(); var newPullRequestModel = new NewPullRequest(title, sourceBranch.GitRef, destinationBranch.GitRef) { Body = body }; _logger.LogTrace("Creating pull request {@requestModel}", newPullRequestModel); var pullRequest = client.PullRequest.Create(_repositoryOwner, _repositoryName, newPullRequestModel).Result; _logger.LogTrace("Created pull request {pullRequestNumber} from {sourceBranchName} to {destinationBranchName}", pullRequest.Number, sourceBranch, destinationBranch); return(pullRequest); }
public async Task ReturnsCorrectCountOfPullRequestsWithoutStart() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var options = new ApiOptions { PageSize = 3, PageCount = 1 }; var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, options); Assert.Equal(1, pullRequests.Count); Assert.Equal(result.Title, pullRequests[0].Title); }
/// <inheritdoc/> protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken)) { if (Owner != null && Name != null && NewPullRequest != null) { var ownerValue = Owner.GetValue(dc.State); var nameValue = Name.GetValue(dc.State); var newPullRequestValue = NewPullRequest.GetValue(dc.State); return(await gitHubClient.PullRequest.Create(ownerValue, nameValue, newPullRequestValue).ConfigureAwait(false)); } if (RepositoryId != null && NewPullRequest != null) { var repositoryIdValue = RepositoryId.GetValue(dc.State); var newPullRequestValue = NewPullRequest.GetValue(dc.State); return(await gitHubClient.PullRequest.Create((Int64)repositoryIdValue, newPullRequestValue).ConfigureAwait(false)); } throw new ArgumentNullException("Required [newPullRequest] arguments missing for GitHubClient.PullRequest.Create"); }
public async Task CanSpecifyDirectionOfSort() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var newPullRequest2 = new NewPullRequest("another pull request", otherBranchName, "master"); var anotherPullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest2); var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, new PullRequestRequest { SortDirection = SortDirection.Ascending }); Assert.Equal(pullRequest.Title, pullRequests[0].Title); var pullRequestsDescending = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, new PullRequestRequest()); Assert.Equal(anotherPullRequest.Title, pullRequestsDescending[0].Title); }
static async Task <int> CreateTheWorld(IGitHubClient github, RepositoryContext context, bool createReviewRequests = true) { var master = await github.Git.Reference.Get(context.RepositoryOwner, context.RepositoryName, "heads/master"); // create new commit for master branch var newMasterTree = await CreateTree(github, context, new Dictionary <string, string> { { "README.md", "Hello World!" } }); var newMaster = await CreateCommit(github, context, "baseline for pull request", newMasterTree.Sha, master.Object.Sha); // update master await github.Git.Reference.Update(context.RepositoryOwner, context.RepositoryName, "heads/master", new ReferenceUpdate(newMaster.Sha)); // create new commit for feature branch var featureBranchTree = await CreateTree(github, context, new Dictionary <string, string> { { "README.md", "I am overwriting this blob with something new" } }); var featureBranchCommit = await CreateCommit(github, context, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha); var featureBranchTree2 = await CreateTree(github, context, new Dictionary <string, string> { { "README.md", "I am overwriting this blob with something new a 2nd time" } }); var featureBranchCommit2 = await CreateCommit(github, context, "this is a 2nd commit to merge into the pull request", featureBranchTree2.Sha, featureBranchCommit.Sha); // create branch await github.Git.Reference.Create(context.RepositoryOwner, context.RepositoryName, new NewReference("refs/heads/my-branch", featureBranchCommit2.Sha)); // create a pull request var pullRequest = new NewPullRequest("Nice title for the pull request", "my-branch", "master"); var createdPullRequest = await github.PullRequest.Create(context.RepositoryOwner, context.RepositoryName, pullRequest); // Create review requests (optional) if (createReviewRequests) { var reviewRequest = new PullRequestReviewRequest(_collaboratorLogins); await github.PullRequest.ReviewRequest.Create(context.RepositoryOwner, context.RepositoryName, createdPullRequest.Number, reviewRequest); } return(createdPullRequest.Number); }
public async Task CanFindClosedPullRequest() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); var updatePullRequest = new PullRequestUpdate { State = ItemState.Closed }; await _fixture.Update(Helper.UserName, _context.RepositoryName, pullRequest.Number, updatePullRequest); var closedPullRequests = new PullRequestRequest { State = ItemStateFilter.Closed }; var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName, closedPullRequests); Assert.Equal(1, pullRequests.Count); }
public static BuildTargetResult CreatePR(BuildTargetContext c) { string remoteBranchName = c.GetRemoteBranchName(); NewPullRequest prInfo = new NewPullRequest( PullRequestTitle, s_config.GitHubOriginOwner + ":" + remoteBranchName, s_config.GitHubUpstreamBranch); GitHubClient gitHub = new GitHubClient(new ProductHeaderValue("dotnetDependencyUpdater")); gitHub.Credentials = new Credentials(s_config.Password); PullRequest createdPR = gitHub.PullRequest.Create(s_config.GitHubUpstreamOwner, s_config.GitHubProject, prInfo).Result; c.Info($"Created Pull Request: {createdPR.HtmlUrl}"); return(c.Success()); }
private async Task <PullRequest> CreatePullRequest(string owner, string name, Repository repository, Reference reference) { var branch = reference.Ref.Replace("refs/heads/", ""); var headRef = repository.Fork ? $"{repository.Owner.Login}:{branch}" : branch; var newPullRequest = new NewPullRequest("Update paket to address TLS deprecation", headRef, repository.DefaultBranch); newPullRequest.Body = @":wave: GitHub disabled TLS 1.0 and TLS 1.1 on February 22nd, which affected Paket and needs to be updated to 5.142 or later. You can read more about this on the [GitHub Engineering blog](https://githubengineering.com/crypto-removal-notice/). The update to Paket is explained here: https://github.com/fsprojects/Paket/pull/3066 The work to update Paket in the wild is occurring here: https://github.com/fsprojects/Paket/issues/3068"; var pullRequest = await Wrap.RateLimiting(client, c => c.PullRequest.Create(owner, name, newPullRequest)); return(pullRequest); }
public void CreatePullRequest(string pullRequestTitle) { // we will need to use octokit for this Console.WriteLine($"Sending pull request for {_changesBranch.FriendlyName} -> {_baseBranch.FriendlyName}"); var githubCredentials = new Octokit.Credentials(_credentials.Username, _credentials.Password); var client = new GitHubClient(new ProductHeaderValue("MassPullRequest")) { Credentials = githubCredentials }; // octokit can only get a repo by owner + name, so we need to chop up the url var urlParts = _repositoryUrl.AbsolutePath.Split("/").Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); var repoName = urlParts.Last(); var owner = urlParts[urlParts.Count - 2]; var pr = new NewPullRequest(pullRequestTitle, _changesBranch.FriendlyName, _baseBranch.FriendlyName); client.PullRequest.Create(owner, repoName, pr).Wait(); }
public async Task CanGetWithLabelsForRepositoryWithRepositoryId() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var result = await _fixture.Create(_context.Repository.Id, newPullRequest); // Add a label var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(labelName); await _github.Issue.Update(_context.Repository.Id, result.Number, issueUpdate); // Retrieve the Pull Requests var pullRequests = await _fixture.GetAllForRepository(_context.Repository.Id); Assert.Equal(1, pullRequests.Count); Assert.Equal(result.Title, pullRequests[0].Title); Assert.Equal(Helper.UserName, pullRequests[0].Assignee.Login); Assert.Equal(1, pullRequests[0].Labels.Count); Assert.Contains(pullRequests[0].Labels, x => x.Name == labelName); }
public override async Task ExecuteAsync(string action, dynamic data) { if (action != "create" || data.ref_type != "branch") { return; } // Please see the 'push' event on github for the data that you can expect here: // https://developer.github.com/v3/activity/events/types/#pushevent long repositoryId = data.repository.id; string branchName = data.@ref; string author = data.sender.login; string masterBranch = data.master_branch; var pullRequestData = new NewPullRequest($"Merge changes from {branchName}", branchName, masterBranch) { Body = $"Please merge changes from the branch {branchName}" }; await Github.PullRequest.Create(repositoryId, pullRequestData); }
public static async Task OpenAsync(PullRequestParameters parameters) { var inMemoryCredentialStore = new InMemoryCredentialStore(new Credentials(KnownGitHubs.Username, parameters.Password)); var githubClient = new GitHubClient(new ProductHeaderValue("ImgBot"), inMemoryCredentialStore); var repo = await githubClient.Repository.Get(parameters.RepoOwner, parameters.RepoName); var branch = await githubClient.Repository.Branch.Get(parameters.RepoOwner, parameters.RepoName, KnownGitHubs.BranchName); var commit = await githubClient.Repository.Commit.Get(parameters.RepoOwner, parameters.RepoName, branch.Commit.Sha); if (branch != null) { var pr = new NewPullRequest(KnownGitHubs.CommitMessageTitle, KnownGitHubs.BranchName, repo.DefaultBranch) { Body = PullRequestBody.Generate(commit.Commit.Message), }; await githubClient.PullRequest.Create(parameters.RepoOwner, parameters.RepoName, pr); } }
public async Task CanGetWithAssigneesForRepository() { await CreateTheWorld(); var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); // Add an assignee var issueUpdate = new IssueUpdate(); issueUpdate.AddAssignee(Helper.UserName); await _github.Issue.Update(Helper.UserName, _context.RepositoryName, result.Number, issueUpdate); // Retrieve the Pull Requests var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName); Assert.Equal(1, pullRequests.Count); Assert.Equal(result.Title, pullRequests[0].Title); Assert.Equal(Helper.UserName, pullRequests[0].Assignee.Login); Assert.Equal(1, pullRequests[0].Assignees.Count); Assert.True(pullRequests[0].Assignees.Any(x => x.Login == Helper.UserName)); }
private static async Task <PullRequest> CreatePullRequestFromFork(string forkname, string branch) { var basic = new Credentials(_token); var client = new GitHubClient(new ProductHeaderValue("dotnet-thanks")); client.Credentials = basic; NewPullRequest newPr = new NewPullRequest("Update thanks data file", $"spboyer:{branch}", "master"); try { var pullRequest = await client.PullRequest.Create("dotnet", "website-resources", newPr); return(pullRequest); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(null); }
private void CreatePullRequest(Repository repo, GitHubClient gitHubClient, Remote origin, string branch) { // Oktokit is async-heavy, but we don't want to make ICommand asynchronous just for that. CreatePullRequestAsync().GetAwaiter().GetResult(); async Task CreatePullRequestAsync() { string user = origin.Url.Substring("https://github.com/".Length).Split('/').First(); string head = $"{user}:{branch}"; var commitMessage = repo.Commits.First().Message; var commitMessageLines = commitMessage.Replace("\r", "").Split('\n').ToList(); var pullRequestLines = UnwrapLines(commitMessageLines); var request = new NewPullRequest(pullRequestLines.First(), head, "main") { Body = string.Join('\n', pullRequestLines.Skip(1)) }; var pullRequest = await gitHubClient.PullRequest.Create(RepositoryOwner, RepositoryName, request); // Note: using a collection initializer looks reasonable, but fails with an NRE, because the Labels // property is lazily initialized :( var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(AutoreleasePendingLabel); issueUpdate.AddLabel(AutomergeExactLabel); string assignee = Environment.GetEnvironmentVariable(AssigneeEnvironmentVariable); if (!string.IsNullOrEmpty(assignee)) { issueUpdate.AddAssignee(assignee); } await gitHubClient.Issue.Update(RepositoryOwner, RepositoryName, pullRequest.Number, issueUpdate); // The PR link is useful to be able to click on, and occasionally the release branch is useful. Console.WriteLine($"Created branch {branch} and PR {pullRequest.HtmlUrl}"); } }
public void CreatesFromClientRepositoryPullRequest() { var newPullRequest = new NewPullRequest("some title", "branch:name", "branch:name"); var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservablePullRequestsClient(gitHubClient); client.Create("fake", "repo", newPullRequest); gitHubClient.Repository.PullRequest.Received().Create("fake", "repo", newPullRequest); }
public async Task PostsToCorrectUrlWithRepositoryId() { var newPullRequest = new NewPullRequest("some title", "branch:name", "branch:name"); var connection = Substitute.For<IApiConnection>(); var client = new PullRequestsClient(connection); await client.Create(1, newPullRequest); connection.Received().Post<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"), newPullRequest); }
/// <summary> /// Creates a pull request for the specified repository. /// </summary> /// <remarks>http://developer.github.com/v3/pulls/#create-a-pull-request</remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="newPullRequest">A <see cref="NewPullRequest"/> instance describing the new PullRequest to create</param> public IObservable<PullRequest> Create(long repositoryId, NewPullRequest newPullRequest) { Ensure.ArgumentNotNull(newPullRequest, "newPullRequest"); return _client.Create(repositoryId, newPullRequest).ToObservable(); }