class Semamore

Attributes

client[R]

Public Class Methods

new(token:, client_options: {}) click to toggle source
# File lib/semamore.rb, line 6
def initialize(token:, client_options: {})
  p 'Starting semamore...'
  @client = ::SemamoreOctoClient.new(token, options: client_options)
end

Public Instance Methods

changed_files_guard(repo:, branch:, command:, pattern:) click to toggle source
# File lib/semamore.rb, line 11
def changed_files_guard(repo:, branch:, command:, pattern:)
  p "Finding changed files on #{branch} that match #{pattern}..."
  files = client.current_pr_files(repo, branch)

  if has_matching_files?(pattern, files)
    p "Found matching changed files, executing `#{command}`..."
    exec command
  else
    p "No matching changed files found, skipping `#{command}`."
    exit 0
  end
end

Private Instance Methods

has_matching_files?(pattern, files) click to toggle source
# File lib/semamore.rb, line 28
def has_matching_files?(pattern, files)
  files.any? { |file| matches_pattern?(pattern, file[:filename]) }
end
matches_pattern?(pattern, string) click to toggle source
# File lib/semamore.rb, line 32
def matches_pattern?(pattern, string)
  Regexp.new(pattern).match?(string)
end