Skip to content

Instantly share code, notes, and snippets.

@excid3
Created December 13, 2019 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save excid3/8edf709fe357a726121e9bfaa7ef818b to your computer and use it in GitHub Desktop.
Save excid3/8edf709fe357a726121e9bfaa7ef818b to your computer and use it in GitHub Desktop.
Rubocop Linter Action
# frozen_string_literal: true
require 'json'
require 'net/http'
require 'time'
require 'yaml'
require_relative './report_adapter'
require_relative './github_check_run_service'
require_relative './github_client'
require_relative './install'
require_relative './command'
class Util
def read_json(path)
if File.exist?(path)
JSON.parse(File.read(path))
else
{}
end
end
def read_yaml(path)
YAML.safe_load(File.read(path))
rescue Errno::ENOENT
p "Warning: Missing file: #{path}"
{}
end
end
class GithubData
attr_reader :event
def initialize
@event = read_json(ENV['GITHUB_EVENT_PATH'])
end
def sha
ENV['GITHUB_SHA']
end
def token
ENV['GITHUB_TOKEN']
end
def owner
ENV['GITHUB_REPOSITORY_OWNER'] || event.dig('repository', 'owner', 'login')
end
def repo
ENV['GITHUB_REPOSITORY_NAME'] || event.dig('repository', 'name')
end
def workspace
ENV['GITHUB_WORKSPACE']
end
end
class RubocopLinterAction
def self.run
new.run
end
def run
@github_data = GithubData.new
Install.new(config).run
GithubCheckRunService.new(report, , ReportAdapter, check_name).run
end
private
def config_path
path = ENV['INPUT_CONFIG_PATH'] || ".github/config/rubocop_linter.yml"
"#{@github.workspace}/#{path}"
end
def config
@config ||= read_yaml(config_path)
end
def report
report_path ? read_json(report_path) : default_report_path
end
def default_report_path
Dir.chdir(@github.workspace) do
JSON.parse(Command.new(config).run)
end
end
def report_path
ENV['REPORT_PATH']
end
def check_name
config.fetch(:check_name, "Rubocop Action")
end
end
RubocopLinterAction.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment