Octokit.net - Cherry-pick merge commit

59 Views Asked by At

I've created a .NET equivalent of Probot where I hooked up the SmeeClient during development. I'm trying to build a Github bot which cherry-picks merge commits into release branches, depending on the labels on the pull-request.

My code for the MyWebhookProcessor essentially looks like this:

public class GithubProcessor : BaseWebhookProcessor
{
    private readonly IAuthenticatedGithubService authenticatedGithubService;
    public GithubProcessor(IAuthenticatedGithubService authenticatedGithubService, ISignatureService signatureService, IOptions<BotOptions> botOptions)
        : base(signatureService, botOptions)
    {
        this.authenticatedGithubService = authenticatedGithubService;
    }

    protected override async Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
    {
        if (pullRequestEvent is PullRequestClosedEvent ev)
        {
            var client = await authenticatedGithubService.GetAuthenticatedGithubClient(ev.Installation!.Id);
            var mergeCommit = await client.Git.Commit.Get(ev.Repository!.Id, ev.PullRequest.MergeCommitSha);

            //await client.Git.Reference.Update(0, "master", new Octokit.ReferenceUpdate())
            foreach (var label in ev.PullRequest.Labels)
            {
                var releaseBranch = await client.Repository.Branch.Get(ev.Repository!.Id, label.Name);
                if (releaseBranch != null)
                {
                    // Here we should be able to cherry-pick the mergeCommit into the releaseBranch
                }
            }
        }
    }
}

The problem is that the OctoKit doesn't seem to contain any method to cherry-pick commits. I could however create a new commit, but I haven't found how to copy changes from the mergeCommit to a new one. The project is hosted here.

Does anybody know how I can do this?

0

There are 0 best solutions below