本文整理汇总了C#中Octokit.NewRepository类的典型用法代码示例。如果您正苦于以下问题:C# NewRepository类的具体用法?C# NewRepository怎么用?C# NewRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NewRepository类属于Octokit命名空间,在下文中一共展示了NewRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeploymentsClientTests
public DeploymentsClientTests()
{
var gitHubClient = Helper.GetAuthenticatedClient();
_deploymentsClient = gitHubClient.Repository.Deployment;
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
{
AutoInit = true
};
_repository = gitHubClient.Repository.Create(newRepository).Result;
_repositoryOwner = _repository.Owner.Login;
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result;
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = "README.md",
Sha = blobResult.Sha
});
var treeResult = gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result;
var newCommit = new NewCommit("test-commit", treeResult.Sha);
_commit = gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result;
}
示例2: CreateAsync
public async Task<string> CreateAsync(string name)
{
var newRepo = new NewRepository(name) { AutoInit = true };
var repository = await Client.Repository.Create(newRepo).ConfigureAwait(false);
var newLabels =
Configuration.repository.labels.Select(label => new NewLabel(label.name, label.color)).ToList();
foreach (var newLabel in newLabels)
{
await Client.Issue.Labels.Create(repository.Owner.Login, repository.Name, newLabel).ConfigureAwait(false);
}
foreach (var branch in Configuration.repository.branches)
{
var master =
await
Client.GitDatabase.Reference.Get(repository.Owner.Login, repository.Name, "heads/master")
.ConfigureAwait(false);
var reference = new NewReference($"refs/heads/{branch.Name}", master.Object.Sha);
var createdReference = await
Client.GitDatabase.Reference.Create(repository.Owner.Login, repository.Name, reference)
.ConfigureAwait(false);
if (branch.IsDefault)
{
var repositoryUpdate = new RepositoryUpdate();
repositoryUpdate.Name = repository.Name;
repositoryUpdate.DefaultBranch = branch.Name;
await Client.Repository.Edit(repository.Owner.Login, repository.Name, repositoryUpdate).ConfigureAwait(false);
}
}
return repository.HtmlUrl;
}
示例3: Create
async Task<Repository> Create(Uri url, string organizationLogin, NewRepository newRepository)
{
try
{
return await ApiConnection.Post<Repository>(url, newRepository);
}
catch (ApiValidationException e)
{
string errorMessage = e.ApiError.FirstErrorMessageSafe();
if (String.Equals(
"name already exists on this account",
errorMessage,
StringComparison.OrdinalIgnoreCase))
{
var baseAddress = Connection.BaseAddress.Host != GitHubClient.GitHubApiUrl.Host
? Connection.BaseAddress
: new Uri("https://github.com/");
throw new RepositoryExistsException(
organizationLogin,
newRepository.Name,
baseAddress, e);
}
if (String.Equals(
"name can't be private. You are over your quota.",
errorMessage,
StringComparison.OrdinalIgnoreCase))
{
throw new PrivateRepositoryQuotaExceededException(e);
}
throw;
}
}
示例4: Create
/// <summary>
/// Creates a new repository for the current user.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#create">API documentation</a> for more information.
/// </remarks>
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="Repository"/> instance for the created repository.</returns>
public Task<Repository> Create(NewRepository newRepository)
{
Ensure.ArgumentNotNull(newRepository, "newRepository");
if (string.IsNullOrEmpty(newRepository.Name))
throw new ArgumentException("The new repository's name must not be null.");
return ApiConnection.Post<Repository>(ApiUrls.Repositories(), newRepository);
}
示例5: CreateRepository
public IObservable<Repository> CreateRepository(NewRepository repository, string login, bool isUser)
{
Guard.ArgumentNotEmptyString(login, "login");
var client = gitHubClient.Repository;
return (isUser ? client.Create(repository) : client.Create(login, repository));
}
示例6: Create
/// <summary>
/// Creates a new repository in the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#create">API documentation</a> for more information.
/// </remarks>
/// <param name="organizationLogin">Login of the organization in which to create the repository</param>
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="Repository"/> instance for the created repository</returns>
public Task<Repository> Create(string organizationLogin, NewRepository newRepository)
{
Ensure.ArgumentNotNull(organizationLogin, "organizationLogin");
Ensure.ArgumentNotNull(newRepository, "newRepository");
if (string.IsNullOrEmpty(newRepository.Name))
throw new ArgumentException("The new repository's name must not be null.");
return Create(ApiUrls.OrganizationRepositories(organizationLogin), organizationLogin, newRepository);
}
示例7: TheNewRepositoryDescription
public void TheNewRepositoryDescription()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var newRepository = new NewRepository { Name = "aName" };
client.Create(newRepository);
connection.Received().Post<Repository>(Args.Uri, newRepository);
}
示例8: CreateRepository
public IObservable<Unit> CreateRepository(
NewRepository newRepository,
IAccount account,
string directory,
IApiClient apiClient)
{
Guard.ArgumentNotEmptyString(directory, nameof(directory));
return apiClient.CreateRepository(newRepository, account.Login, account.IsUser)
.Select(repository => cloneService.CloneRepository(repository.CloneUrl, repository.Name, directory))
.SelectUnit();
}
示例9: CanQueueAllCodeRepository
public async Task CanQueueAllCodeRepository()
{
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"));
using (var context = await _github.CreateRepositoryContext(newRepository))
{
var response = await
_github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName, context.RepositoryName);
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
}
示例10: CreateRepository
void CreateRepository(string name)
{
var nrep = new NewRepository("test");
//nrep.AutoInit = true;
try
{
//client.Repository.Create(nrep).Wait();
//var rep = await client.Repository.Create(nrep);
}
catch (Exception e)
{
;
}
}
示例11: CreatesARepositoryWithoutDownloads
public async Task CreatesARepositoryWithoutDownloads()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("repo-without-downloads");
var newRepository = new NewRepository(repoName) { HasDownloads = false };
using (var context = await github.CreateRepositoryContext(newRepository))
{
var createdRepository = context.Repository;
Assert.False(createdRepository.HasDownloads);
var repository = await github.Repository.Get(Helper.UserName, repoName);
Assert.False(repository.HasDownloads);
}
}
示例12: CreatesRepositoryAndPushesLocalToIt
public async Task CreatesRepositoryAndPushesLocalToIt()
{
var solution = Substitute.For<IVsSolution>();
var gitClient = Substitute.For<IGitClient>();
var service = new RepositoryPublishService(gitClient, Substitutes.IVSGitServices);
var newRepository = new Octokit.NewRepository("test");
var account = Substitute.For<IAccount>();
account.Login.Returns("monalisa");
account.IsUser.Returns(true);
var gitHubRepository = CreateRepository(account.Login, newRepository.Name);
var apiClient = Substitute.For<IApiClient>();
apiClient.CreateRepository(newRepository, "monalisa", true).Returns(Observable.Return(gitHubRepository));
var repository = await service.PublishRepository(newRepository, account, apiClient);
Assert.Equal("https://github.com/monalisa/test", repository.CloneUrl);
}
示例13: DeploymentStatusClientTests
public DeploymentStatusClientTests()
{
_gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_deploymentsClient = _gitHubClient.Repository.Deployment;
var newRepository = new NewRepository
{
Name = Helper.MakeNameWithTimestamp("public-repo"),
AutoInit = true
};
_repository = _gitHubClient.Repository.Create(newRepository).Result;
_repositoryOwner = _repository.Owner.Login;
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = _gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result;
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = "README.md",
Sha = blobResult.Sha
});
var treeResult = _gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result;
var newCommit = new NewCommit("test-commit", treeResult.Sha);
_commit = _gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result;
var newDeployment = new NewDeployment { Ref = _commit.Sha };
_deployment = _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment).Result;
}
示例14: CreatesRepositoryOnlineViaApiAndThenClonesIt
public void CreatesRepositoryOnlineViaApiAndThenClonesIt()
{
var provider = Substitutes.ServiceProvider;
var newRepository = new NewRepository("octokit.net");
var repository = new TestRepository("octokit.net", "https://github.com/octokit/octokit.net");
var account = Substitute.For<IAccount>();
account.Login.Returns("octokit");
account.IsUser.Returns(false);
var apiClient = Substitute.For<IApiClient>();
apiClient.CreateRepository(newRepository, "octokit", false)
.Returns(Observable.Return(repository));
var cloneService = provider.GetRepositoryCloneService();
cloneService.CloneRepository("https://github.com/octokit/octokit.net", "octokit.net", @"c:\dev")
.Returns(Observable.Return(Unit.Default));
var creator = provider.GetRepositoryCreationService();
creator.CreateRepository(newRepository, account, @"c:\dev", apiClient).Subscribe();
apiClient.Received().CreateRepository(newRepository, "octokit", false);
}
示例15: ThrowsRepositoryExistsExceptionWhenRepositoryExistsForCurrentUser
public async Task ThrowsRepositoryExistsExceptionWhenRepositoryExistsForCurrentUser()
{
var newRepository = new NewRepository { Name = "aName" };
var response = Substitute.For<IResponse>();
response.StatusCode.Returns((HttpStatusCode)422);
response.Body.Returns(@"{""message"":""Validation Failed"",""documentation_url"":"
+ @"""http://developer.github.com/v3/repos/#create"",""errors"":[{""resource"":""Repository"","
+ @"""code"":""custom"",""field"":""name"",""message"":""name already exists on this account""}]}");
var credentials = new Credentials("haacked", "pwd");
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
connection.Connection.Credentials.Returns(credentials);
connection.Post<Repository>(Args.Uri, newRepository)
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);
var exception = await AssertEx.Throws<RepositoryExistsException>(
async () => await client.Create(newRepository));
Assert.False(exception.OwnerIsOrganization);
Assert.Null(exception.Owner);
Assert.Equal("aName", exception.RepositoryName);
Assert.Null(exception.ExistingRepositoryWebUrl);
}