Интеграция GitHub с .NET: методы и примеры кода

Вот несколько методов, связанных с использованием GitHub с.NET, а также примеры кода:

  1. Клонирование репозитория:

    using LibGit2Sharp;
    var cloneOptions = new CloneOptions();
    Repository.Clone("https://github.com/username/repository.git", "localPath", cloneOptions);
  2. Создание нового репозитория:

    using Octokit;
    var client = new GitHubClient(new ProductHeaderValue("MyApp"));
    var newRepo = new NewRepository("repository-name");
    var repository = await client.Repository.Create("username", newRepo);
  3. Содержимое репозитория списка:

    using Octokit;
    var client = new GitHubClient(new ProductHeaderValue("MyApp"));
    var contents = await client.Repository.Content.GetAllContents("username", "repository-name");
    foreach (var content in contents)
    {
       Console.WriteLine(content.Name);
    }
  4. Создание запроса на включение:

    using Octokit;
    var client = new GitHubClient(new ProductHeaderValue("MyApp"));
    var newPullRequest = new NewPullRequest("PR Title", "branch:source", "branch:target");
    var pullRequest = await client.PullRequest.Create("username", "repository-name", newPullRequest);
  5. Получение информации о репозитории:

    using Octokit;
    var client = new GitHubClient(new ProductHeaderValue("MyApp"));
    var repository = await client.Repository.Get("username", "repository-name");
    Console.WriteLine(repository.Description);