onlyoffice_github_helper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9578a0eb673c72a14cfe35ddf2e2a3b2f1361fa97b25bcab3932bf08bc219998
4
+ data.tar.gz: 03deaed6e6f98757b476b67fae5171a5cb4651a9fe4be839d81f089629ce4861
5
+ SHA512:
6
+ metadata.gz: 64a9ff189f08013c7f07b57e648a4ef60e5f99b18bdd38eaa3cee7dc4d313ce94a0bc9a4b9e5aef47e8ee6eb12a72556f8128c4e1f16b3a8efe0ac60a616e41d
7
+ data.tar.gz: '0989342043c92a9e7a06f89bce992810fa55cc083b500573d4092e2cb54f970b5f94144839d7f98bc6e60c42785ead629e9466fe9137eac22186b57f21232c92'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'onlyoffice_github_helper/github_client'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit'
4
+ require 'yaml'
5
+ require_relative 'github_client/branches'
6
+ require_relative 'github_client/file_list'
7
+ require_relative 'github_client/tags'
8
+
9
+ module OnlyofficeGithubHelper
10
+ # Basic github client
11
+ class GithubClient
12
+ include Branches
13
+ include FileList
14
+ include Tags
15
+
16
+ def initialize(config_file: 'config.yml',
17
+ user: nil,
18
+ password: nil)
19
+ @user_name = user
20
+ @user_password = password
21
+ init_github_access(config_file)
22
+ Octokit.configure do |c|
23
+ c.login = @user_name
24
+ c.password = @user_password
25
+ end
26
+ Octokit.auto_paginate = true
27
+ end
28
+
29
+ private
30
+
31
+ def init_github_access(config)
32
+ return if @user_name && @user_password
33
+
34
+ @user_name = ENV['GITHUB_USER_NAME']
35
+ @user_password = ENV['GITHUB_USER_PASSWORD']
36
+ return unless File.exist?(config)
37
+
38
+ @config = YAML.load_file(config)
39
+ @user_name = @config['github_user']
40
+ @user_password = @config['github_user_password']
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeGithubHelper
4
+ # Working with branches
5
+ module Branches
6
+ def branches(repo)
7
+ Octokit.branches(repo).map(&:name)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeGithubHelper
4
+ # Module for working with file list
5
+ module FileList
6
+ def file_list(repo, refs: 'master')
7
+ Octokit.tree(repo, refs, recursive: true).tree
8
+ .reject { |elem| elem.type == 'tree' }
9
+ .map(&:path)
10
+ end
11
+
12
+ def file_tree(repo, refs: 'master')
13
+ list = file_list(repo, refs: refs)
14
+ parse_tree(list)
15
+ end
16
+
17
+ def parse_tree(list, path: '')
18
+ root_tree = { name: path }
19
+ root_tree[:children] = []
20
+ childs = tree_childs(list)
21
+ childs[:dirs].each do |child_item|
22
+ sub_files = subdir_content(list, child_item)
23
+ root_tree[:children] << parse_tree(sub_files, path: child_item)
24
+ end
25
+ root_tree[:children] << childs[:files]
26
+ root_tree[:children].flatten!
27
+ root_tree
28
+ end
29
+
30
+ private
31
+
32
+ def tree_childs(list)
33
+ childs = []
34
+ child_dirs = []
35
+ list.each do |entry|
36
+ if with_subdir?(entry)
37
+ child_dirs << subdir_name(entry)
38
+ else
39
+ childs << { name: entry }
40
+ end
41
+ end
42
+ { files: childs, dirs: child_dirs.uniq }
43
+ end
44
+
45
+ # Check if path is a string
46
+ # @param file_path [String] path
47
+ # @return [True, False]
48
+ def with_subdir?(file_path)
49
+ Pathname.new(file_path).dirname.to_s != '.'
50
+ end
51
+
52
+ def subdir_content(list, dir)
53
+ subdir_list = []
54
+ list.each do |item|
55
+ subdir_list << item.sub("#{dir}/", '') if item.start_with?("#{dir}/")
56
+ end
57
+ subdir_list
58
+ end
59
+
60
+ def subdir_name(path)
61
+ Pathname(path).each_filename.to_a[0]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeGithubHelper
4
+ # Working with tags
5
+ module Tags
6
+ def tags(repo)
7
+ Octokit.tags(repo).map(&:name)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeGithubHelper
4
+ module Name
5
+ STRING = 'onlyoffice_github_helper'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeGithubHelper
4
+ module Version
5
+ STRING = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlyoffice_github_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ONLYOFFICE
8
+ - Pavel Lobashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: octokit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '13.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '13.0'
42
+ description: Github Helper Gem for ONLYOFFICE QA
43
+ email:
44
+ - shockwavenn@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/onlyoffice_github_helper.rb
50
+ - lib/onlyoffice_github_helper/github_client.rb
51
+ - lib/onlyoffice_github_helper/github_client/branches.rb
52
+ - lib/onlyoffice_github_helper/github_client/file_list.rb
53
+ - lib/onlyoffice_github_helper/github_client/tags.rb
54
+ - lib/onlyoffice_github_helper/name.rb
55
+ - lib/onlyoffice_github_helper/version.rb
56
+ homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_github_helper
57
+ licenses:
58
+ - AGPL-3.0
59
+ metadata:
60
+ bug_tracker_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_github_helper/issues
61
+ changelog_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_github_helper/blob/master/CHANGELOG.md
62
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_github_helper
63
+ homepage_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_github_helper
64
+ source_code_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_github_helper
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2.3'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.0.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Github Helper Gem
84
+ test_files: []