Class: LocalClient

Inherits:
Object
  • Object
show all
Defined in:
lib/local_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LocalClient

Returns a new instance of LocalClient.



2
3
4
5
# File 'lib/local_client.rb', line 2

def initialize(path)
    @path = File.expand_path(path)
    @workflows_dir = File.join(@path, ".github", "workflows")
end

Instance Method Details

#fetch_dependabot_config(_repo) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/local_client.rb', line 23

def fetch_dependabot_config(_repo)
    path = File.join(@path, ".github", "dependabot.yml")
    path = File.join(@path, ".github", "dependabot.yaml") unless File.exist?(path)
    return nil unless File.exist?(path)
    begin
        YAML.safe_load(File.read(path))
    rescue StandardError => e
        nil
    end
end

#fetch_platform_configsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/local_client.rb', line 34

def fetch_platform_configs
    configs = []

    # GitLab CI
    %w[.gitlab-ci.yml .gitlab-ci.yaml].each do |name|
        path = File.join(@path, name)
        if File.exist?(path)
            configs << { platform: :gitlab, filename: name, content: File.read(path) }
            break
        end
    end

    # Bitbucket Pipelines
    %w[bitbucket-pipelines.yml bitbucket-pipelines.yaml].each do |name|
        path = File.join(@path, name)
        if File.exist?(path)
            configs << { platform: :bitbucket, filename: name, content: File.read(path) }
            break
        end
    end

    configs
end

#fetch_workflows(_repo = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/local_client.rb', line 7

def fetch_workflows(_repo = nil)
    workflows = []
    return workflows unless File.directory?(@workflows_dir)

    Dir[File.join(@workflows_dir, "*.{yml,yaml}")].sort.each do |f|
        content = File.read(f)
        workflows << { filename: File.basename(f), content: content }
    end

    workflows
end

#file_exists?(_repo, path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/local_client.rb', line 19

def file_exists?(_repo, path)
    File.exist?(File.join(@path, path))
end