示例#1
0
        public static async Task <Reference> CreateTheWorld(this IGitHubClient client, Repository repository)
        {
            var master = await client.Git.Reference.Get(repository.Owner.Login, repository.Name, "heads/master");

            // create new commit for master branch
            var newMasterTree = await client.CreateTree(repository, new Dictionary <string, string> {
                { "README.md", "Hello World!" }
            });

            var newMaster = await client.CreateCommit(repository, "baseline for pull request", newMasterTree.Sha, master.Object.Sha);

            // update master
            await client.Git.Reference.Update(repository.Owner.Login, repository.Name, "heads/master", new ReferenceUpdate(newMaster.Sha));

            // create new commit for feature branch
            var featureBranchTree = await client.CreateTree(repository, new Dictionary <string, string> {
                { "README.md", "I am overwriting this blob with something new" }
            });

            var featureBranchCommit = await client.CreateCommit(repository, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha);

            // create branch
            return(await client.Git.Reference.Create(repository.Owner.Login, repository.Name, new NewReference("refs/heads/my-branch", featureBranchCommit.Sha)));
        }
        public static async Task <Reference> SaveFiles(this IGitHubClient client, Repository repository, string comment, IEnumerable <KeyValuePair <string, string> > treeContents)
        {
            var master = await client.GitDatabase.Reference.Get(repository.Owner.Login, repository.Name, "heads/master");

            var baseTree = await client.GitDatabase.Tree.Get(repository.Owner.Login, repository.Name, master.Object.Sha);

            // create new commit for master branch
            var newMasterTree = await client.CreateTree(repository, baseTree.Sha, treeContents);

            var newMaster = await client.CreateCommit(repository, comment, newMasterTree.Sha, master.Object.Sha);

            // update master
            return(await client.GitDatabase.Reference.Update(repository.Owner.Login, repository.Name, "heads/master", new ReferenceUpdate(newMaster.Sha)));

            /*
             * // create new commit for feature branch
             * var featureBranchTree = await client.CreateTree(repository, new Dictionary<string, string> { { "README.md", "I am overwriting this blob with something new" } });
             * var featureBranchCommit = await client.CreateCommit(repository, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha);
             *
             * // create branch
             * return await client.GitDatabase.Reference.Create(repository.Owner.Login, repository.Name, new NewReference("refs/heads/my-branch", featureBranchCommit.Sha));
             *
             **/
        }