Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This GitHub Action automatically checks for typos in the files changed in a pull

## Usage

> [!NOTE]
> If you want GitHub Actions to approve PRs, you must grant permission to it at: project settings -> Actions -> General -> Allow GitHub Actions to create and approve pull requests.

![Typocop Logo](typocop-approval.png)

1. **Using Typocop GitHub Action:**

1. Copy the `.github/workflows/typocop.yml` file into your project repository.
Expand Down Expand Up @@ -70,7 +75,7 @@ This GitHub Action automatically checks for typos in the files changed in a pull
```bash
gem install typocop # install

GITHUB_TOKEN=your_token PULL_REQUEST_ID=your_pull_request_id typocop execute # run action
GITHUB_TOKEN=your_token PULL_REQUEST_ID=the_request_id GITHUB_BASE_REF=branch_base_name typocop execute # run action
```

![Typocop demo](typocop.gif "")
Expand Down
26 changes: 14 additions & 12 deletions lib/typocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
require 'typocop/repo'
require 'typo_checker'

GITHUB_TOKEN = ENV['GITHUB_TOKEN'] || ''
PULL_ID = ENV['PULL_REQUEST_ID']
GITHUB_BASE_REF = ENV['GITHUB_BASE_REF'] || 'main'
GITHUB_TOKEN = ENV.fetch('GITHUB_TOKEN') { raise 'GITHUB_TOKEN is required' }
PULL_ID = ENV.fetch('PULL_REQUEST_ID') { raise 'PULL_REQUEST_ID is required' }
GITHUB_BASE_REF = ENV.fetch('GITHUB_BASE_REF') { raise 'GITHUB_BASE_REF is required' }
BASE_BRANCH = GITHUB_BASE_REF.start_with?('origin/') ? GITHUB_BASE_REF : "origin/#{GITHUB_BASE_REF}"

module Typocop
def self.execute(settings)
repo = Repo.new
paths = repo.patch_additions.map(&:path)

return unless paths.any?

excludes = settings.excludes
skips = settings.skips
typo_checker = TypoChecker::Checker.new(excludes, skips, stdoutput = false)
typo_checker = TypoChecker::Checker.new(paths: paths, excludes: excludes, skips: skips, stdoutput: false)
found_typos = typo_checker.scan_repo('.')

if found_typos.empty?
puts 'No typos.'
else
cops = Cops.new(found_typos)
repo = Repo.new
client = Client.new(repo)
client.execute(cops.cops)
end
puts 'No typos found' if found_typos.empty?

cops = Cops.new(found_typos)
client = Client.new(repo)
client.execute(cops.cops)
end
end
2 changes: 1 addition & 1 deletion lib/typocop/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def suggestion_comment(typos)
end

def line_content(cop)
patch = @repo.patch_additions.find { |patch| patch.path == cop.path }
patch = @repo.patch_additions.find { |p| p.path == cop.path }
patch.added_lines.find { |line| line.new_lineno == cop.line }.content
end

Expand Down
10 changes: 4 additions & 6 deletions lib/typocop/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ def initialize(setting_path)
private

def load_settings(setting_path)
begin
YAML.load_file(setting_path)
rescue StandardError => e
puts "Error loading YAML file: #{e.message}"
return {}
end
YAML.load_file(setting_path)
rescue StandardError => e
puts "Error loading YAML file: #{e.message}"
{}
end
end
end
2 changes: 1 addition & 1 deletion lib/typocop/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Typocop
VERSION = '0.1.3'
VERSION = '0.1.4'
end
3 changes: 0 additions & 3 deletions test/example.js

This file was deleted.

26 changes: 0 additions & 26 deletions test/example.py

This file was deleted.

9 changes: 0 additions & 9 deletions test/example.rb

This file was deleted.

Binary file added typocop-approval.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion typocop.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency 'octokit', '9.2.0'
s.add_dependency 'rugged', '~> 1.6.3'
s.add_dependency 'thor', '~> 1.3.2'
s.add_dependency 'typo_checker', '0.1.7'
s.add_dependency 'typo_checker'
s.executables = %w[typocop]
s.files.each do |file|
next unless file.start_with?('bin/')
Expand Down