Ejemplo n.º 1
0
        public async Task <IEnumerable <RepoFile> > GetRepoFilesListPath(
            [FromRoute] string owner, [FromRoute] string repoName, [FromRoute] string path
            )
        {
            var client = await _authorizeClient.Authorize();

            var result = (await client.Repository.Content.GetAllContents(owner, repoName, path))
                         .Where(s => new [] { ".md", ".txt" }
                                .Any(e => e == Path.GetExtension(s.Name)))
                         .OrderBy(o => o.Name)
                         .Select(r => new RepoFile(r.Name));

            return(result);
        }
Ejemplo n.º 2
0
        public async Task CreateFile(
            [FromRoute] string owner,
            [FromRoute] string repoName,
            [FromRoute] string message,
            [FromRoute] string path,
            [FromBody] string content
            )
        {
            var client = await _authorizeClient.Authorize();

            var repository = await client.Repository.Get(owner, repoName);

            var defaultBranchName = repository.DefaultBranch;
            var converter         = new Converter();
            var createdContent    = converter.Convert(content);

            var createFile = client.Repository.Content.CreateFile(
                owner,
                repoName,
                path,
                new CreateFileRequest(
                    message,
                    createdContent,
                    defaultBranchName,
                    true
                    )
                );
        }
Ejemplo n.º 3
0
        public async Task DeleteFile(
            [FromRoute] string owner,
            [FromRoute] string repoName,
            [FromRoute] string message,
            [FromRoute] string path

            )
        {
            var client = await _authorizeClient.Authorize();

            var repository = await client.Repository.Get(owner, repoName);

            var existingFile = (await client.Repository.Content.GetAllContentsByRef(
                                    owner,
                                    repository.Name,
                                    path,
                                    repository.DefaultBranch))
                               .FirstOrDefault();

            await client.Repository.Content.DeleteFile(
                owner,
                repoName,
                path,
                new DeleteFileRequest(
                    message,
                    existingFile.Sha));
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <RepoFile> > GetFileContent(
            [FromRoute] string owner, [FromRoute] string repoName, [FromRoute] string path
            )
        {
            var client = await _authorizeClient.Authorize();

            var result = (await client.Repository.Content.GetAllContentsByRef(owner, repoName, path, "master"))
                         .Select(r => new RepoFile(r.Content, r.Name));

            return(result);
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <ReposInfo> > GetRepo(
            [FromRoute] string owner = ""
            )
        {
            var client = await _authorizeClient.Authorize();

            var repos = (await client.Repository.GetAllForUser(owner))
                        .Where(r => r.Name == r.Name)
                        .OrderByDescending(r => r.StargazersCount)
                        .Select(r => new ReposInfo(r.Name, r.FullName, r.Description, r.StargazersCount))
                        .Take(10);

            return(repos);
        }
Ejemplo n.º 6
0
        public async Task <RepoReadme> GetReadme(
            [FromRoute] string owner, [FromRoute] string repoName
            )
        {
            var client = await _authorizeClient.Authorize();

            var readme = await client.Repository.Content.GetReadme(owner, repoName);

            var gitReadme = new RepoReadme {
                Content = readme.Content,
                Name    = readme.Name,
            };

            return(gitReadme);
        }
Ejemplo n.º 7
0
        public async Task UpdateFile(
            [FromRoute] string owner,
            [FromRoute] string repoName,
            [FromRoute] string message,
            [FromRoute] string path,
            [FromBody] string content
            )
        {
            var client = await _authorizeClient.Authorize();

            var repository = await client.Repository.Get(owner, repoName);

            var repositoryId      = repository.Id;
            var defaultBranchName = repository.DefaultBranch;
            var existingFile      = (await client.Repository.Content.GetAllContentsByRef(
                                         owner,
                                         repository.Name,
                                         path,
                                         repository.DefaultBranch))
                                    .FirstOrDefault();

            if (existingFile == null)
            {
                throw new ArgumentException("Parameter cannot be null");
            }

            var converter      = new Converter();
            var updatedContent = converter.Convert(content);

            var updateFile = await client.Repository.Content.UpdateFile(
                owner,
                repoName,
                path,
                new UpdateFileRequest(
                    message,
                    updatedContent,
                    existingFile.Sha,
                    defaultBranchName
                    )
                );
        }