-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from datpmt/test-rb
Test rb
- Loading branch information
Showing
21 changed files
with
514 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Check Typos in Pull Request | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
typocop: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.14.0-alpha.1' | ||
|
||
- name: Install typos | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip install typos | ||
- name: Run Typocop Action | ||
uses: ./ | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
pull_request_id: ${{ github.event.pull_request.number }} | ||
github_base_ref: ${{ github.base_ref }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
typocop-*.gem |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Gemfile | ||
source 'https://rubygems.org' | ||
|
||
gem 'cli' | ||
gem 'octokit', '>= 9.2.0' | ||
gem 'rugged', '1.6.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.8.7) | ||
public_suffix (>= 2.0.2, < 7.0) | ||
cli (1.4.0) | ||
faraday (2.12.1) | ||
faraday-net_http (>= 2.0, < 3.5) | ||
json | ||
logger | ||
faraday-net_http (3.4.0) | ||
net-http (>= 0.5.0) | ||
json (2.9.0) | ||
logger (1.6.2) | ||
net-http (0.6.0) | ||
uri | ||
octokit (9.2.0) | ||
faraday (>= 1, < 3) | ||
sawyer (~> 0.9) | ||
public_suffix (6.0.1) | ||
rugged (1.6.3) | ||
sawyer (0.9.2) | ||
addressable (>= 2.3.5) | ||
faraday (>= 0.17.3, < 3) | ||
uri (1.0.2) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
x86_64-darwin-22 | ||
|
||
DEPENDENCIES | ||
cli | ||
octokit (>= 9.2.0) | ||
rugged (= 1.6.3) | ||
|
||
BUNDLED WITH | ||
2.3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: 'typocop' | ||
description: 'Github action comments on PRs with typos or approvals' | ||
author: "Datpmt <[email protected]>" | ||
repository: "https://github.com/datpmt/typocop" | ||
branding: | ||
icon: 'check-circle' | ||
color: 'green' | ||
|
||
inputs: | ||
github_token: | ||
description: 'GitHub Token' | ||
required: true | ||
pull_request_id: | ||
description: 'Pull Request ID' | ||
required: true | ||
github_base_ref: | ||
description: 'GitHub Base Reference' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.1' | ||
|
||
- name: Install dependencies | ||
run: | | ||
gem install typocop | ||
shell: bash | ||
|
||
- name: Run Typocop | ||
run: | | ||
typocop execute | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github_token }} | ||
PULL_REQUEST_ID: ${{ inputs.pull_request_id }} | ||
GITHUB_BASE_REF: ${{ inputs.github_base_ref }} | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require 'typocop/cli' | ||
Typocop::CLI.start(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'rugged' | ||
# require 'pry' | ||
require 'octokit' | ||
|
||
require 'typocop/cli' | ||
require 'typocop/client' | ||
require 'typocop/comment' | ||
require 'typocop/cop' | ||
require 'typocop/cops' | ||
require 'typocop/patch' | ||
require 'typocop/repo' | ||
|
||
GITHUB_TOKEN = ENV['GITHUB_TOKEN'] || '' | ||
PULL_ID = ENV['PULL_REQUEST_ID'] | ||
GITHUB_BASE_REF = ENV['GITHUB_BASE_REF'] || 'main' | ||
BASE_BRANCH = GITHUB_BASE_REF.start_with?('origin/') ? GITHUB_BASE_REF : "origin/#{GITHUB_BASE_REF}" | ||
|
||
module Typocop | ||
def self.execute | ||
typo_outputs = `typos --format brief` | ||
typo_outputs = typo_outputs.split("\n") | ||
|
||
if typo_outputs.empty? | ||
puts 'No typo output.' | ||
else | ||
result = typo_outputs.each_with_object({}) do |output, hash| | ||
path, line, _column, typo_detail = output.split(':') | ||
typo_match = /`(.*?)` -> `(.*?)`/.match(typo_detail) | ||
incorrect_word, correct_word = typo_match ? typo_match.captures : [] | ||
|
||
path = path.start_with?('./') ? path[2..] : path | ||
line = line.to_i | ||
|
||
hash[path] ||= {} | ||
|
||
hash[path][:typos] ||= [] | ||
|
||
existing_entry = hash[path][:typos].find { |typo| typo[:line] == line } | ||
|
||
if existing_entry | ||
existing_entry[:typos] << { incorrect_word: incorrect_word, correct_word: correct_word } | ||
else | ||
hash[path][:typos] << { line: line, typos: [{ incorrect_word: incorrect_word, correct_word: correct_word }] } | ||
end | ||
end | ||
|
||
result = result.map do |path, data| | ||
data[:typos].map do |entry| | ||
{ path: path, line: entry[:line], typos: entry[:typos] } | ||
end | ||
end.flatten | ||
|
||
cops = Cops.new(result) | ||
cops_data = cops.cops | ||
repo = Repo.new | ||
client = Client.new(repo) | ||
client.execute(cops_data) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'thor' | ||
|
||
module Typocop | ||
class CLI < Thor | ||
require 'typocop' | ||
desc 'execute', 'Run typocop' | ||
def execute | ||
Typocop.execute | ||
end | ||
end | ||
end |
Oops, something went wrong.