Пример #1
0
        private async Task <Reference> PushFix(IGitHubClient client, Repository repository, Commit latest, string jenkinsFile)
        {
            var oldTree = await client.Git.Tree.Get(repository.Owner.Login, repository.Name, latest.Sha).ConfigureAwait(false);

            var newTree = new NewTree
            {
                BaseTree = oldTree.Sha
            };

            var blobReference = await CreateBlob(client, repository, jenkinsFile).ConfigureAwait(false);

            var treeItem = new NewTreeItem()
            {
                Path = JenkinsFileName,
                Mode = FileMode,
                Type = TreeType.Blob,
                Sha  = blobReference.Sha
            };

            newTree.Tree.Add(treeItem);

            var createdTree = await client.Git.Tree.Create(repository.Owner.Login, repository.Name, newTree).ConfigureAwait(false);

            var commit         = new NewCommit($"Update {LibraryName} to latest version.", createdTree.Sha, new[] { latest.Sha });
            var commitResponse = await client.Git.Commit.Create(repository.Owner.Login, repository.Name, commit).ConfigureAwait(false);

            var refUpdate = new ReferenceUpdate(commitResponse.Sha);

            return(await client.Git.Reference.Update(repository.Owner.Login, repository.Name, $"heads/{_branchName}", refUpdate).ConfigureAwait(false));
        }
Пример #2
0
        static async Task <TreeResponse> CreateTree(GitHubClient client,
                                                    string repoName,
                                                    IDictionary <string, string> treeContents,
                                                    string username)
        {
            var collection = new List <NewTreeItem>();

            foreach (var c in treeContents)
            {
                var baselineBlob = new NewBlob
                {
                    Content  = c.Value,
                    Encoding = EncodingType.Utf8
                };
                var baselineBlobResult = await client.Git.Blob.Create(username, repoName, 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.Git.Tree.Create(username, repoName, newTree));
        }
Пример #3
0
    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);
    }
Пример #4
0
        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));
        }
Пример #5
0
    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 _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 <string> CreateBranchWithBump()
        {
            var headSha = await Client.GetHeadSha();

            var tree = new NewTree {
                BaseTree = headSha
            };

            foreach (var submodule in Submodules)
            {
                tree.Tree.Add(new NewTreeItem {
                    Mode = FileMode.Submodule,
                    Sha  = submodule.HeadSha,
                    Path = submodule.Path,
                    Type = TreeType.Commit,
                });
            }

            var newTreeSha = await Client.CreateTree(tree);

            var commitSha = await Client.CreateCommit(CreateTitleText() + "\r\n\r\n" + CreateBodyText(), newTreeSha, headSha);

            if (await Client.BranchExists(AutoBumpBranchName))
            {
                await Client.DeleteBranch(AutoBumpBranchName);
            }
            await Client.CreateBranch(AutoBumpBranchName, commitSha);

            return(AutoBumpBranchName);
        }
Пример #7
0
        private async Task <NewTree> PopulateTree(Commit latestCommit, string mainFP, long targetRepo)
        {
            //This function will create a tree based off of the Main file path's folder and file structure
            //Create our variables, our NewTree is based off our last commit
            var nt = new NewTree {
                BaseTree = latestCommit.Tree.Sha
            };
            var currentDir = new DirectoryInfo(mainFP);

            //Start our Queue with our Main File Path as our initial directory
            var toCheck = new List <DirectoryInfo>()
            {
                currentDir
            };
            var toAdd = new List <FileInfo>();

            //We need to use a Queue to make sure we don't miss any files
            while (toCheck.Count > 0)
            {
                //Pop first folder
                var targetFolder = toCheck[0];
                toCheck.RemoveAt(0);

                //Check for new folders and add them to que
                foreach (var folder in targetFolder.GetDirectories())
                {
                    toCheck.Add(folder);
                }

                //Check for all files in said folders and add to our toAdd que
                foreach (var file in targetFolder.GetFiles())
                {
                    if (!file.Name.Contains("-Omit")) //this is done for files that contain sensitive info
                    {
                        toAdd.Add(file);
                    }
                }
            }

            //Once complete, make the tree by turning every file into a tree item
            foreach (var file in toAdd)
            {
                //Blob settings for TEXT based files.
                var blob = new NewBlob {
                    Encoding = EncodingType.Utf8, Content = File.ReadAllText(file.FullName)
                };
                var blobRef = await client.Git.Blob.Create(targetRepo, blob);

                //Prepare a string so we can create a proper folder system by taking the file's full path and subtracting our MainFP
                var preGitFileName = file.FullName.Replace(mainFP, "");
                var gitFileName    = preGitFileName.Replace(@"\", @"/").TrimStart('/');

                //Add our file to the tree
                nt.Tree.Add(new NewTreeItem {
                    Path = gitFileName, Mode = "100644", Type = TreeType.Blob, Sha = blobRef.Sha
                });
            }

            return(nt);
        }
        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 _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));
        }
Пример #9
0
    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);
    }
Пример #10
0
    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);
    }
Пример #11
0
        public async Task CreateCommit(long repoId, string directoryToAdd, string commitText)
        {
            var headMasterRef   = "heads/master";
            var github          = GetClient();
            var masterReference = await github.Git.Reference.Get(repoId, headMasterRef);

            var latestCommit = await GetLatestSHA(repoId, headMasterRef);

            var nt = new NewTree {
                BaseTree = latestCommit.Tree.Sha
            };

            string[] filePaths = Directory.GetFiles(string.Format(@"{0}\", directoryToAdd));

            foreach (var filePath in filePaths)
            {
                var linesOfCode = await File.ReadAllLinesAsync(filePath);

                var newTreeItem = new NewTreeItem {
                    Mode = "100644", Type = TreeType.Blob, Content = linesOfCode.ToString(), Path = filePath
                };
                nt.Tree.Add(newTreeItem);
            }

            var newTree = await github.Git.Tree.Create(repoId, nt);

            var newCommit = new NewCommit(commitText, newTree.Sha, masterReference.Object.Sha);
            var commit    = await github.Git.Commit.Create(repoId, newCommit);

            await github.Git.Reference.Update(repoId, headMasterRef, new ReferenceUpdate(commit.Sha));
        }
Пример #12
0
        private async Task <Commit> CommitToRepository(RepositorySummary repositorySummary)
        {
            var owner      = repositorySummary.Owner;
            var repository = repositorySummary.Name;
            var blob       = new NewBlob
            {
                Content  = "Hello World!",
                Encoding = EncodingType.Utf8
            };
            var blobResult = await _client.Git.Blob.Create(owner, repository, 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, repository, newTree);

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

            var commit = await _fixture.Create(owner, repository, newCommit);

            return(commit);
        }
Пример #13
0
    public async Task CanDeleteAReferenceWithRepositoryId()
    {
        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.Repository.Id, newReference);

        await _fixture.Delete(_context.Repository.Id, "heads/develop");

        var all = await _fixture.GetAll(_context.Repository.Id);

        Assert.Empty(all.Where(r => r.Ref == "heads/develop"));
    }
Пример #14
0
        public static async Task <TreeResponse> CreateTree(this IGitHubClient client, Repository repository, 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.Git.Blob.Create(repository.Owner.Login, 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.Git.Tree.Create(repository.Owner.Login, repository.Name, newTree));
        }
Пример #15
0
        public static void Start()
        {
            Console.WriteLine("Press enter to start generator");

            Console.ReadLine();

            Console.WriteLine("Starting Tree Generation");

            Tree tree = NewTree.Start();

            Console.WriteLine("Tree is generated");

            Console.WriteLine("Enter the needed number");

            int n = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine($"You entered{n}");
            //bool finding = FindANode.DFSPRE(tree, n);
            if (FindANode.DFSPRE(tree, n) == false)
            {
                Console.WriteLine("The entered node doesn't exist'");
            }
            else
            {
                Console.WriteLine("The node is find");
            }
            Console.WriteLine("Press enter to exit");
            int leaves = CountTheLeaves.Start(tree);

            Console.WriteLine($"Leaves={leaves}");
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
Пример #16
0
        public static async Task<TreeResponse> CreateTree(this IGitHubClient client, Repository repository, 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(repository.Owner.Login, 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(repository.Owner.Login, repository.Name, newTree);
        }
Пример #17
0
        public static void MakeCommit(GitHubClient client, Configuration config, int commitNumber)
        {
            string yearString = Utils.GetTodaysDate().ToString("yyyy-MM-dd");

            string    headMasterRef   = "refs/heads/master";
            Reference masterReference = client.Git.Reference.Get(config.RepoOwner, config.RepoName, headMasterRef).Result;
            Commit    latestCommit    = client.Git.Commit.Get(config.RepoOwner, config.RepoName, masterReference.Object.Sha).Result;
            var       nt = new NewTree {
                BaseTree = latestCommit.Tree.Sha
            };

            var textBlob = new NewBlob {
                Encoding = EncodingType.Utf8, Content = $"Commit number {commitNumber} today"
            };
            var textBlobRef = client.Git.Blob.Create(config.RepoOwner, config.RepoName, textBlob);

            nt.Tree.Add(new NewTreeItem {
                Path = yearString, Mode = "100644", Type = TreeType.Blob, Sha = textBlobRef.Result.Sha
            });
            var newTree = client.Git.Tree.Create(config.RepoOwner, config.RepoName, nt).Result;

            var newCommit = new NewCommit($"commit {yearString} {commitNumber}", newTree.Sha, masterReference.Object.Sha);
            var commit    = client.Git.Commit.Create(config.RepoOwner, config.RepoName, newCommit).Result;

            Reference reff = client.Git.Reference.Update(config.RepoOwner, config.RepoName, headMasterRef, new ReferenceUpdate(commit.Sha)).Result;
        }
Пример #18
0
        private 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));
        }
Пример #19
0
    public DeploymentsClientTests()
    {
        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);

        _commit = github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;
    }
Пример #20
0
    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);

        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);
    }
Пример #21
0
        public static async Task <Commit> CreateCommit(this IGitDatabaseClient client, string repoOwner, string repoName, string before, string branch, string message, Dictionary <string, string> files, bool force = false)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var tree     = new NewTree
            {
                BaseTree = before
            };

            foreach (var entry in files)
            {
                using (var stream = assembly.GetManifestResourceStream($"GithubWebhookEndToEnd.Resources.{entry.Value}"))
                {
                    tree.Tree.Add(new NewTreeItem
                    {
                        Path    = entry.Key,
                        Mode    = "100644",
                        Content = await stream.ReadAsString()
                    });
                }
            }

            var response = await client.Tree.Create(repoOwner, repoName, tree);

            var commitRequest  = (before != null) ? new NewCommit(message, response.Sha, before) : new NewCommit(message, response.Sha);
            var commitResponse = await client.Commit.Create(repoOwner, repoName, commitRequest);

            await client.Reference.CreateOrUpdate(repoOwner, repoName, $"heads/{branch}", commitResponse.Sha, force);

            return(commitResponse);
        }
        public static async Task <TreeResponse> CreateTree(this IGitHubClient client, Repository repository, string treeSha, 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
                };

                //new Blob() {}

                // Try getting an exisiting blob first

                var baselineBlobResult = await client.GitDatabase.Blob.Create(repository.Owner.Login, repository.Name, baselineBlob);

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

            var newTree = new NewTree {
                Tree = collection, BaseTree = treeSha
            };

            return(await client.GitDatabase.Tree.Create(repository.Owner.Login, repository.Name, newTree));
        }
        /// <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 IObservable<TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            return _client.Create(owner, name, newTree).ToObservable();
        }
        /// <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 IObservable <TreeResponse> Create(string owner, string name, NewTree newTree)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newTree, "newTree");

            return(_client.Create(owner, name, newTree).ToObservable());
        }
Пример #25
0
        private NewTree ConstructTree(Folder folderInfo)
        {
            var tree = new NewTree();

            this.ConstructTreeInternal(folderInfo, tree, string.Empty);

            return(tree);
        }
Пример #26
0
    public void OnNewTree(GameObject tree)
    {
        var newTree = new TreeEventArgs {
            Tree = tree
        };

        NewTree?.Invoke(this, newTree);
    }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var newTree      = new NewTree();
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableTreesClient(gitHubClient);

                client.Create(1, newTree);

                gitHubClient.Git.Tree.Received().Create(1, newTree);
            }
Пример #28
0
            public void PostsToCorrectUrl()
            {
                var newTree = new NewTree();
                var connection = Substitute.For<IApiConnection>();
                var client = new TreesClient(connection);

                client.Create("fake", "repo", newTree);

                connection.Received().Post<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees"), newTree);
            }
            public void CreatesFromClientIssueIssue()
            {
                var newTree = new NewTree();
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableTreesClient(gitHubClient);

                client.Create("fake", "repo", newTree);

                gitHubClient.Git.Tree.Received().Create("fake", "repo", newTree);
            }
Пример #30
0
            public void PostsToCorrectUrl()
            {
                var newTree    = new NewTree();
                var connection = Substitute.For <IApiConnection>();
                var client     = new TreesClient(connection);

                client.Create("fake", "repo", newTree);

                connection.Received().Post <TreeResponse>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/git/trees"), newTree);
            }
            public void CreatesFromClientIssueIssue()
            {
                var newTree      = new NewTree();
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableTreesClient(gitHubClient);

                client.Create("fake", "repo", newTree);

                gitHubClient.GitDatabase.Tree.Received().Create("fake", "repo", newTree);
            }
Пример #32
0
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var newTree    = new NewTree();
                var connection = Substitute.For <IApiConnection>();
                var client     = new TreesClient(connection);

                client.Create(1, newTree);

                connection.Received().Post <TreeResponse>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/git/trees"), newTree);
            }
Пример #33
0
    public async Task <string> CreateTree(NewTree newTree, string owner, string repo)
    {
        var createdTree = await client.Git.Tree.Create(owner, repo, newTree);

        log($"API Query - Create tree '{createdTree.Sha.Substring(0, 7)}' in '{owner}/{repo}'.");

        AddToKnown <TreeResponse>(createdTree.Sha, owner, repo);

        return(createdTree.Sha);
    }
Пример #34
0
    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);
    }
Пример #35
0
            public async Task EnsureExceptionIsThrownWhenModeIsNotProvided()
            {
                var newTree = new NewTree();
                newTree.Tree.Add(new NewTreeItem { Path = "README.md", Type = TreeType.Blob, Sha = "2e1a73d60f004fd842d4bad28aa42392d4f35d28" });

                var connection = Substitute.For<IApiConnection>();
                var client = new TreesClient(connection);

                await AssertEx.Throws<ArgumentException>(
                    async () => await client.Create("fake", "repo", newTree));
            }
        private async Task<Commit> CommitToRepository(RepositorySummary repositorySummary)
        {
            var owner = repositorySummary.Owner;
            var repository = repositorySummary.Name;
            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8
            };
            var blobResult = await _client.Git.Blob.Create(owner, repository, 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, repository, newTree);

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

            var commit = await _fixture.Create(owner, repository, newCommit);
            return commit;
        }
Пример #37
0
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var newTree = new NewTree();
                var connection = Substitute.For<IApiConnection>();
                var client = new TreesClient(connection);

                client.Create(1, newTree);

                connection.Received().Post<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/trees"), newTree);
            }
        /// <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 IObservable<TreeResponse> Create(long repositoryId, NewTree newTree)
        {
            Ensure.ArgumentNotNull(newTree, "newTree");

            return _client.Create(repositoryId, newTree).ToObservable();
        }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var newTree = new NewTree();
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableTreesClient(gitHubClient);

                client.Create(1, newTree);

                gitHubClient.Git.Tree.Received().Create(1, newTree);
            }