public async Task CanCreateAReference()
    {
        var blob = new NewBlob
        {
            Content  = "Hello World!",
            Encoding = EncodingType.Utf8
        };
        var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob);

        var newTree = new NewTree();

        newTree.Tree.Add(new NewTreeItem
        {
            Mode = FileMode.File,
            Type = TreeType.Blob,
            Path = "README.md",
            Sha  = blobResult.Sha
        });

        var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree);

        var newCommit = new NewCommit("This is a new commit", treeResult.Sha);

        var commitResult = await _client.GitDatabase.Commit.Create(_owner, _repository.Name, newCommit);

        var newReference = new NewReference("heads/develop", commitResult.Sha);
        var result       = await _fixture.Create(_owner, _repository.Name, newReference);

        Assert.Equal(commitResult.Sha, result.Object.Sha);
    }
示例#2
0
        /// <summary>
        /// Creates a reference for a given repository
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/refs/#create-a-reference
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="reference">The reference to create</param>
        /// <returns></returns>
        public IObservable <Reference> Create(string owner, string name, NewReference reference)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
            Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
            Ensure.ArgumentNotNull(reference, nameof(reference));

            return(_reference.Create(owner, name, reference).ToObservable());
        }
示例#3
0
 public static async Task <Reference> CreateOrUpdate(this IReferencesClient client, string repoOwner, string repoName, string refName, string sha, bool force = false)
 {
     try
     {
         return(await client.Update(repoOwner, repoName, refName, new ReferenceUpdate(sha, force)));
     }
     catch (Exception)
     {
         return(await client.Create(repoOwner, repoName, new NewReference(refName, sha)));
     }
 }
        /// <summary>
        /// Creates a branch, based off the branch specified.
        /// </summary>
        /// <param name="referencesClient">The <see cref="IReferencesClient" /> this method extends</param>
        /// <param name="owner">The owner of the repository.</param>
        /// <param name="name">The name of the repository.</param>
        /// <param name="branchName">The new branch name</param>
        /// <param name="baseReference">The <see cref="Reference" /> to base the branch from</param>
        public static async Task <Reference> CreateBranch(this IReferencesClient referencesClient, string owner, string name, string branchName, Reference baseReference)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(branchName, "branchName");
            Ensure.ArgumentNotNull(baseReference, "baseReference");

            if (branchName.StartsWith("refs/heads"))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName");
            }

            return(await referencesClient.Create(owner, name, new NewReference("refs/heads/" + branchName, baseReference.Object.Sha)));
        }