Esempio n. 1
0
 protected override string GetParentPath(string path, string root)
 {
     return(GithubProvider.StaticGetParentPath(path, root));
 }
Esempio n. 2
0
        private static async Task <object> directoryDelegate(string path, object input)
        {
            var folder = PathInfo.UncheckedFolderFromPath(path);

            if (folder == null)
            {
                var repoInfo = PathInfo.UncheckedRepoFromPath(path);
                if (repoInfo == null)
                {
                    throw new NotSupportedException("The Github Provider does not support making directories in this location.");
                }
                if (await repoInfo.Exists())
                {
                    throw new Exception("The given repository already exists."); //TODO: Custom exceptions
                }
                var parentInfo = await PathInfo.FromFSPath(GithubProvider.StaticGetParentPath(path, null));

                if (parentInfo != null)
                {
                    var repo = new NewRepository(repoInfo.Name)
                    {
                        AutoInit = true
                    };
                    switch (parentInfo.Type)
                    {
                    case (PathType.User):
                    {
                        await Static.Client.Repository.Create(repo);

                        PathInfo.PathInfoCache.Remove(parentInfo.VirtualPath);
                        return(repoInfo);
                    }

                    case (PathType.Org):
                    {
                        await Static.Client.Repository.Create(repoInfo.Org, repo);

                        PathInfo.PathInfoCache.Remove(parentInfo.VirtualPath);
                        return(repoInfo);
                    }

                    default:
                        throw new Exception("Given path is neither a repository nor a folder and cannot be created.");     //TODO
                    }
                }
            }

            if (await folder.Exists())
            {
                throw new Exception("The folder being created already exists"); //TODO: Stop being lazy and write my own exceptions
            }

            try
            {
                await Static.Client.Repository.Content.CreateFile(
                    folder.Org,
                    folder.Repo,
                    Path.Combine(folder.FilePath, ".gitkeep"),
                    new CreateFileRequest("Add .gitkeep", "")
                    );
            }
            catch (Octokit.NotFoundException e)
            {
                throw new Exception("Couldn't create directory - couldn't find the repo.", e);
            }
            return(folder);
        }