libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.13k stars 879 forks source link

Create a Pull Request (git pull) by adding one or more reviewers option? #1991

Open ajaykumar-hcl opened 1 year ago

ajaykumar-hcl commented 1 year ago

I am using .NET 5.0 Using libgit2sharp 0.26.0, I've written code to clone , create a new branch, change some files, commit and push branch to bitbucket. Now I need to create a pull-request and add a reviewer to it. However, my Google searches don't turn up any relevant info. Does libgit2sharp support creating PRs by adding reviewer? Any help

using (var repo = new Repository(LocalRepoUrl)) { Signature Signature = new Signature(Username, Email, new DateTimeOffset(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, TimeSpan.FromHours(2))); FetchOptions fetchOptions = new FetchOptions(); fetchOptions.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = Username, Password = Password };

            MergeOptions mergeOptions = new MergeOptions();
            mergeOptions.IgnoreWhitespaceChange = true;
            mergeOptions.FailOnConflict = true;
            mergeOptions.CommitOnSuccess = true;
            mergeOptions.FastForwardStrategy = FastForwardStrategy.Default;

            PullOptions pullOptions = new PullOptions();
            pullOptions.FetchOptions = fetchOptions;
            pullOptions.MergeOptions = mergeOptions;
            // how to add reviewer
            var mergeResult = Commands.Pull(repo, Signature, pullOptions); // no pull request generated

 Please correct me if I am wrong and suggest me with the correct code.
YuKitsune commented 1 year ago

git pull is not the same as creating a pull request. (Docs) "Pull requests" are no native to git, they are a concept provided by each individual git provider. GitHub and Bitbucket call them pull requests, GitLab calls them merge requests. You'll need to use the git providers own API if you want to create a pull request. Here's what I found for Bitbucket: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-post