public async Task CanGetACreatedTree()
    {
        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
        {
            Type = TreeType.Blob,
            Path = "README.md",
            Sha = blobResult.Sha,
            Mode = FileMode.File
        });

        var tree = await _fixture.Create(_owner, _repository.Name, newTree);

        var result = await _fixture.Get(_owner, _repository.Name, tree.Sha);

        Assert.NotNull(result);
        Assert.Equal(1, result.Tree.Count);
    }
    public async Task CanCreateAndRetrieveCommit()
    {
        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
        {
            Type = TreeType.Blob,
            Mode = FileMode.File,
            Path = "README.md",
            Sha = blobResult.Sha
        });

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

        var newCommit = new NewCommit("test-commit", treeResult.Sha, Enumerable.Empty<string>());

        var commit = await _fixture.Create(_owner, _repository.Name, newCommit);
        Assert.NotNull(commit);

        var retrieved = await _fixture.Get(_owner, _repository.Name, commit.Sha);
        Assert.NotNull(retrieved);
    }
    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;
    }
    async Task<TreeResponse> CreateTree(IEnumerable<KeyValuePair<string, string>> treeContents)
    {
        var collection = new List<NewTreeItem>();

        foreach (var c in treeContents)
        {
            var baselineBlob = new NewBlob
            {
                Content = c.Value,
                Encoding = EncodingType.Utf8
            };
            var baselineBlobResult = await _client.GitDatabase.Blob.Create(Helper.UserName, _repository.Name, baselineBlob);

            collection.Add(new NewTreeItem
            {
                Type = TreeType.Blob,
                Mode = FileMode.File,
                Path = c.Key,
                Sha = baselineBlobResult.Sha
            });
        }

        var newTree = new NewTree();
        foreach (var item in collection)
        {
            newTree.Tree.Add(item);
        }

        return await _client.GitDatabase.Tree.Create(Helper.UserName, _repository.Name, newTree);
    }
    public DeploymentStatusClientTests()
    {
        var github = Helper.GetAuthenticatedClient();

        _deploymentsClient = github.Repository.Deployment;
        _context = github.CreateRepositoryContext("public-repo").Result;

        var blob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var blobResult = github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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 = github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result;
        var newCommit = new NewCommit("test-commit", treeResult.Sha);

        var commit = github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;

        var newDeployment = new NewDeployment(commit.Sha) { AutoMerge = false };
        _deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result;
    }
    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);
    }
    private IEnumerable<Commit> CreateCommits(int commitCount)
    {
        var github = Helper.GetAuthenticatedClient();

        var list = new List<Commit>();

        for (int i = 0; i < commitCount; i++)
        {
            var blob = new NewBlob
            {
                Content = string.Format("Hello World {0}!", i),
                Encoding = EncodingType.Utf8
            };

            var blobResult = github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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 = github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result;
            var newCommit = new NewCommit("test-commit", treeResult.Sha);
            var commit = github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;
            list.Add(commit);
        }

        return list;
    }
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        /// <returns>The <see cref="TreeResponse"/> that was just created.</returns>
        public Task<TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            return ApiConnection.Post<TreeResponse>(ApiUrls.Tree(owner, name), newTree);
        }
Beispiel #9
0
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        /// <returns>The <see cref="TreeResponse"/> that was just created.</returns>
        public Task <TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            return(ApiConnection.Post <TreeResponse>(ApiUrls.Tree(owner, name), newTree));
        }
Beispiel #10
0
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        public Task <TreeResponse> Create(long repositoryId, NewTree newTree)
        {
            Ensure.ArgumentNotNull(newTree, "newTree");

            if (newTree.Tree.Any(t => StringExt.IsNullOrWhiteSpace(t.Mode)))
            {
                throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
            }

            return(ApiConnection.Post <TreeResponse>(ApiUrls.Tree(repositoryId), newTree));
        }
Beispiel #11
0
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        /// <returns>The <see cref="TreeResponse"/> that was just created.</returns>
        public Task<TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            if (newTree.Tree.Any(t => String.IsNullOrWhiteSpace(t.Mode)))
            {
                throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
            }

            return ApiConnection.Post<TreeResponse>(ApiUrls.Tree(owner, name), newTree);
        }
Beispiel #12
0
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        public Task <TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            if (newTree.Tree.Any(t => StringExt.IsNullOrWhiteSpace(t.Mode)))
            {
                throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
            }

            return(ApiConnection.Post <TreeResponse>(ApiUrls.Tree(owner, name), newTree));
        }
    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;
    }
    public async Task CanCreateATree()
    {
        var blob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var createdBlob = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob);

        var newTree = new NewTree();
        newTree.Tree.Add(new NewTreeItem
        {
            Type = TreeType.Blob,
            Path = "README.md",
            Sha = createdBlob.Sha
        });

        var result = await _fixture.Create(_owner, _repository.Name, newTree);

        Assert.NotNull(result);
    }
    public async Task CanCreateATree()
    {
        var blob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var createdBlob = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);

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

        var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);

        Assert.NotNull(result);
    }
Beispiel #16
0
    public async Task CanCreateAndRetrieveCommit()
    {
        var github = Helper.GetAuthenticatedClient();
        var fixture = github.GitDatabase.Commit;

        using (var context = await github.CreateRepositoryContext("public-repo"))
        {
            var owner = context.Repository.Owner.Login;

            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8
            };
            var blobResult = await github.GitDatabase.Blob.Create(owner, context.Repository.Name, blob);

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

            var treeResult = await github.GitDatabase.Tree.Create(owner, context.Repository.Name, newTree);

            var newCommit = new NewCommit("test-commit", treeResult.Sha);

            var commit = await fixture.Create(owner, context.Repository.Name, newCommit);
            Assert.NotNull(commit);

            var retrieved = await fixture.Get(owner, context.Repository.Name, commit.Sha);
            Assert.NotNull(retrieved);
        }
    }
        private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
        {
            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8
            };
            var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);

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

            var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);

            var newCommit = new NewCommit("test-commit", treeResult.Sha);

            return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
        }
        async Task<TreeResponse> CreateTree(IDictionary<string, string> treeContents)
        {
            var collection = new List<NewTreeItem>();

            foreach (var c in treeContents)
            {
                var baselineBlob = new NewBlob
                {
                    Content = c.Value,
                    Encoding = EncodingType.Utf8
                };
                var baselineBlobResult = await _github.Git.Blob.Create(Helper.UserName, _context.RepositoryName, baselineBlob);

                collection.Add(new NewTreeItem
                {
                    Type = TreeType.Blob,
                    Mode = FileMode.File,
                    Path = c.Key,
                    Sha = baselineBlobResult.Sha
                });
            }

            var newTree = new NewTree();
            foreach (var item in collection)
            {
                newTree.Tree.Add(item);
            }

            return await _github.Git.Tree.Create(Helper.UserName, _context.RepositoryName, newTree);
        }
    async Task<Commit> CreateCommit(string repoName, string blobContent, string treePath, string reference, string commitMessage)
    {
        // Creating a blob
        var blob = new NewBlob
        {
            Content = blobContent,
            Encoding = EncodingType.Utf8
        };

        var createdBlob = await _github.Git.Blob.Create(Helper.UserName, repoName, blob);

        // Creating a tree
        var newTree = new NewTree();
        newTree.Tree.Add(new NewTreeItem
        {
            Type = TreeType.Blob,
            Mode = FileMode.File,
            Path = treePath,
            Sha = createdBlob.Sha,
        });

        var createdTree = await _github.Git.Tree.Create(Helper.UserName, repoName, newTree);
        var treeSha = createdTree.Sha;

        // Creating a commit
        var parent = await _github.Git.Reference.Get(Helper.UserName, repoName, reference);
        var commit = new NewCommit(commitMessage, treeSha, parent.Object.Sha);

        var createdCommit = await _github.Git.Commit.Create(Helper.UserName, repoName, commit);
        await _github.Git.Reference.Update(Helper.UserName, repoName, reference, new ReferenceUpdate(createdCommit.Sha));

        return createdCommit;
    }
    public async Task CanUpdateAReference()
    {
        var firstBlob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };
        var firstBlobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, firstBlob);
        var secondBlob = new NewBlob
        {
            Content = "This is a test!",
            Encoding = EncodingType.Utf8
        };
        var secondBlobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, secondBlob);

        var firstTree = new NewTree();
        firstTree.Tree.Add(new NewTreeItem
        {
            Mode = FileMode.File,
            Type = TreeType.Blob,
            Path = "README.md",
            Sha = firstBlobResult.Sha
        });

        var firstTreeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, firstTree);
        var firstCommit = new NewCommit("This is a new commit", firstTreeResult.Sha);
        var firstCommitResult = await _client.GitDatabase.Commit.Create(_owner, _repository.Name, firstCommit);

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

        var secondTree = new NewTree();
        secondTree.Tree.Add(new NewTreeItem
        {
            Mode = FileMode.File,
            Type = TreeType.Blob,
            Path = "README.md",
            Sha = secondBlobResult.Sha
        });

        var secondTreeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, secondTree);

        var secondCommit = new NewCommit("This is a new commit", secondTreeResult.Sha, firstCommitResult.Sha);
        var secondCommitResult = await _client.GitDatabase.Commit.Create(_owner, _repository.Name, secondCommit);

        var referenceUpdate = new ReferenceUpdate(secondCommitResult.Sha);

        var result = await _fixture.Update(_owner, _repository.Name, "heads/develop", referenceUpdate);

        Assert.Equal(secondCommitResult.Sha, result.Object.Sha);
    }
    async static Task<Commit> HelperCreateCommit(string owner, string repo)
    {
        var client = Helper.GetAuthenticatedClient();

        var blob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };
        var blobResult = await client.Git.Blob.Create(owner, repo, blob);

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

        var treeResult = await client.Git.Tree.Create(owner, repo, newTree);

        var newCommit = new NewCommit("test-commit", treeResult.Sha);

        return await client.Git.Commit.Create(owner, repo, newCommit);
    }
Beispiel #22
0
        void SyncTree(Parts source, string destinationOwner, string destinationRepository)
        {
            if (gw.IsKnownBy<TreeResponse>(source.Sha, destinationOwner, destinationRepository))
                return;

            var treeFrom = gw.TreeFrom(source, true);

            var newTree = new NewTree();

            foreach (var i in treeFrom.Item2.Tree)
            {
                switch (i.Type)
                {
                    case TreeType.Blob:
                        SyncBlob(source.Owner, source.Repository, i.Sha, destinationOwner, destinationRepository);
                        break;

                    case TreeType.Tree:
                        SyncTree(treeFrom.Item1.Combine(TreeEntryTargetType.Tree, i.Path, i.Sha), destinationOwner, destinationRepository);
                        break;

                    default:
                        throw new NotSupportedException();
                }

                newTree.Tree.Add(new NewTreeItem
                {
                    Type = i.Type,
                    Path = i.Path,
                    Sha = i.Sha,
                    Mode = i.Mode
                });
            }

            var sha = gw.CreateTree(newTree, destinationOwner, destinationRepository);

            Debug.Assert(source.Sha == sha);
        }
Beispiel #23
0
        void RemoveTreeItemFrom(NewTree tree, string name)
        {
            var existing = tree.Tree.SingleOrDefault(ti => ti.Path == name);

            if (existing == null)
            {
                return;
            }

            tree.Tree.Remove(existing);
        }
Beispiel #24
0
        string BuildTargetTree(TargetTree tt)
        {
            var treeFrom = gw.TreeFrom(tt.Current, false);

            NewTree newTree;
            if (treeFrom != null)
            {
                var destinationParentTree = treeFrom.Item2;
                newTree = BuildNewTreeFrom(destinationParentTree);
            }
            else
            {
                newTree = new NewTree();
            }

            foreach (var st in tt.SubTreesToUpdate.Values)
            {
                RemoveTreeItemFrom(newTree, st.Current.Name);
                var sha = BuildTargetTree(st);
                newTree.Tree.Add(new NewTreeItem { Mode = "040000", Path = st.Current.Name, Sha = sha, Type = TreeType.Tree });
            }

            foreach (var l in tt.LeavesToCreate.Values)
            {
                var destination = l.Item1;
                var source = l.Item2;

                RemoveTreeItemFrom(newTree, destination.Name);

                SyncLeaf(source, destination);

                switch (source.Type)
                {
                    case TreeEntryTargetType.Blob:
                        var sourceBlobItem = gw.BlobFrom(source, true).Item2;
                        newTree.Tree.Add(new NewTreeItem { Mode = sourceBlobItem.Mode, Path = destination.Name, Sha = source.Sha, Type = TreeType.Blob });
                        break;

                    case TreeEntryTargetType.Tree:
                        newTree.Tree.Add(new NewTreeItem { Mode = "040000", Path = destination.Name, Sha = source.Sha, Type = TreeType.Tree });
                        break;

                    default:
                        throw new NotSupportedException();
                }
            }

            return gw.CreateTree(newTree, tt.Current.Owner, tt.Current.Repository);
        }
Beispiel #25
0
        /// <summary>
        /// Creates a new Tree in the specified repo
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/trees/#create-a-tree
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newTree">The value of the new tree</param>
        public Task<TreeResponse> Create(int repositoryId, NewTree newTree)
        {
            Ensure.ArgumentNotNull(newTree, "newTree");

            if (newTree.Tree.Any(t => string.IsNullOrWhiteSpace(t.Mode)))
            {
                throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
            }

            return ApiConnection.Post<TreeResponse>(ApiUrls.Tree(repositoryId), newTree);
        }
    public async Task CanDeleteAReference()
    {
        var blob = new NewBlob
        {
            Content = "Hello World!",
            Encoding = EncodingType.Utf8
        };
        var blobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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 _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);

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

        var commitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);

        var newReference = new NewReference("heads/develop", commitResult.Sha);

        await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newReference);
        await _fixture.Delete(_context.RepositoryOwner, _context.RepositoryName, "heads/develop");

        var all = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);

        Assert.Empty(all.Where(r => r.Ref == "heads/develop"));
    }
Beispiel #27
0
        static NewTree BuildNewTreeFrom(TreeResponse destinationParentTree)
        {
            var newTree = new NewTree();

            foreach (var treeItem in destinationParentTree.Tree)
            {
                var newTreeItem = new NewTreeItem
                                  {
                                      Mode = treeItem.Mode,
                                      Path = treeItem.Path,
                                      Sha = treeItem.Sha,
                                      Type = treeItem.Type
                                  };

                newTree.Tree.Add(newTreeItem);
            }

            return newTree;
        }
Beispiel #28
0
        /// <summary>
        /// Create a git tree
        /// </summary>
        /// <param name="treeContents">A dictionary of the changed files</param>
        /// <param name="client">The GitHub client</param>
        /// <param name="owner">The owner of the repo to commit to</param>
        /// <param name="name">The name of the repo to commit to</param>
        /// <returns></returns>
        async Task<TreeResponse> CreateTree(IDictionary<string, string> treeContents, GitHubClient client, string owner, string name)
        {
            var newTree = new NewTree();
            foreach (var c in treeContents)
            {
                var baselineBlob = new NewBlob
                {
                    Content = c.Value,
                    Encoding = EncodingType.Utf8
                };
                var baselineBlobResult = await client.GitDatabase.Blob.Create(owner, name, baselineBlob);

                newTree.Tree.Add(new NewTreeItem
                {
                    Type = TreeType.Blob,
                    Mode = FileMode.File,
                    Path = c.Key,
                    Sha = baselineBlobResult.Sha
                });
            }

            return await client.GitDatabase.Tree.Create(owner, name, newTree);
        }