Module: OnlyofficeGithubHelper::FileList

Included in:
GithubClient
Defined in:
lib/onlyoffice_github_helper/github_client/file_list.rb

Overview

Module for working with file list

Instance Method Summary collapse

Instance Method Details

#file_list(repo, refs: 'master') ⇒ Array<String>

Get file list in repo

Parameters:

  • repo (String)

    to check

  • refs (String) (defaults to: 'master')

    to check

Returns:

  • (Array<String>)

    list of files



10
11
12
13
14
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 10

def file_list(repo, refs: 'master')
  Octokit.tree(repo, refs, recursive: true).tree
         .reject { |elem| elem.type == 'tree' }
         .map(&:path)
end

#file_tree(repo, refs: 'master') ⇒ Hash

Get file tree in repo

Parameters:

  • repo (String)

    to check

  • refs (String) (defaults to: 'master')

    to check

Returns:

  • (Hash)

    file tree



20
21
22
23
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 20

def file_tree(repo, refs: 'master')
  list = file_list(repo, refs: refs)
  parse_tree(list)
end

#parse_tree(list, path: '') ⇒ Hash

Parse file tree

Parameters:

  • list (Array<String>)

    of file with full path

  • path (String) (defaults to: '')

    to root

Returns:

  • (Hash)

    result of parse



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 29

def parse_tree(list, path: '')
  root_tree = { name: path }
  root_tree[:children] = []
  childs = tree_childs(list)
  childs[:dirs].each do |child_item|
    sub_files = subdir_content(list, child_item)
    root_tree[:children] << parse_tree(sub_files, path: child_item)
  end
  root_tree[:children] << childs[:files]
  root_tree[:children].flatten!
  root_tree
end