-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared): Implement GitHub Spellcheck and grammar linting for Pul…
…l request. This pull request implements the GitHub Spellcheck feature to automatically check the spelling and grammar in commit messages for all Pull Requests (PRs). Changes Made: - modified the code to check the grammar errors at exact line numbers. -In docs/README.md file corrected the grammar errors. Fixes: #2327 Signed-off-by: sailajakommineni <[email protected]>
- Loading branch information
1 parent
2c1f343
commit 6e65419
Showing
11 changed files
with
270 additions
and
107 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
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,73 @@ | ||
--- | ||
name: grammer check | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
grammar_check_disabled: | ||
description: 'Disable grammar check' | ||
default: 'false' | ||
required: false | ||
push: | ||
branches: | ||
- "**" | ||
pull_request: | ||
paths: | ||
- 'docs/*.md' | ||
types: [opened, edited, updated] | ||
|
||
env: | ||
GRAMMAR_CHECK_DISABLED: ${{ github.event.inputs.grammar_check_disabled || 'false' }} | ||
|
||
jobs: | ||
check-grammar: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
# Install the dependencies for grammer check | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip setuptools | ||
pip install --user --upgrade language_tool_python | ||
# To check the grammatical mistakes of the given files and folders. | ||
- name: Run grammar check | ||
if: ${{ env.GRAMMAR_CHECK_DISABLED == 'false' }} | ||
run: | | ||
python - <<EOF | ||
import language_tool_python | ||
# Initialize LanguageTool | ||
tool = language_tool_python.LanguageTool('en-US') # You can specify the language you want to check. | ||
# Specify the directory path | ||
directory_path = 'docs' | ||
# Read the text from your file | ||
file_path = 'docs/*.md' # Update the path accordingly | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
text = file.read() | ||
# Check for grammar errors | ||
matches = tool.check(text) | ||
# Print relevant grammar errors with line numbers | ||
relevant_errors = [] | ||
if matches: | ||
for match in matches: | ||
if match.ruleId == 'MORFOLOGIK_RULE_EN_US': | ||
line_number = text.count('\n', 0, match.offset) + 1 | ||
relevant_errors.append((line_number, match.message)) | ||
if relevant_errors: | ||
for error in relevant_errors: | ||
line_number, message = error | ||
print(f"Grammar error at line {line_number}: {message}") | ||
exit(1) | ||
else: | ||
print("No grammar errors found.") | ||
exit(0) | ||
EOF |
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 |
---|---|---|
@@ -1,73 +1,38 @@ | ||
--- | ||
name: spell and grammer check | ||
name: spell check | ||
on: | ||
push: | ||
branches: | ||
- "**" | ||
pull_request_target: | ||
branches: | ||
- "**" | ||
pull_request: | ||
paths: | ||
- 'docs/*.md' | ||
types: [opened, edited, updated] | ||
|
||
env: | ||
SPELL_CHECK_DISABLED: false | ||
GRAMMAR_CHECK_DISABLED: false | ||
|
||
jobs: | ||
check-spelling-and-grammar: | ||
check-spelling: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
# Install the dependencies for grammer check and spell check. | ||
# Install the dependencies for spell check. | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip setuptools | ||
python -m pip install pyspelling | ||
sudo apt-get install hunspell hunspell-en-us aspell aspell-en | ||
pip install --user --upgrade language_tool_python | ||
- uses: actions/checkout@v2 | ||
- name: Spellcheck | ||
if: ${{ env.SPELL_CHECK_DISABLED == 'false' }} | ||
uses: rojopolis/[email protected] | ||
with: | ||
config_path: .github/.spellcheck.yaml | ||
source_files: "docs/README.md" # name of the file to check spell | ||
source_files: 'docs/*.md' # name of the file to check the spell | ||
task_name: Markdown | ||
# To check the grammatical mistakes of the given files and folders. | ||
- name: Run grammar check | ||
if: ${{ env.GRAMMAR_CHECK_DISABLED == 'false' }} | ||
run: | | ||
cat <<EOF | python - | ||
import language_tool_python | ||
# Initialize LanguageTool | ||
tool = language_tool_python.LanguageTool('en-US') # You can specify the language you want to check. | ||
# Specify the directory path | ||
directory_path = 'docs' | ||
|
||
# Read the text from your file | ||
file_path = 'docs/README.md' # Update the path accordingly | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
text = file.read() | ||
|
||
# Check for grammar errors | ||
matches = tool.check(text) | ||
|
||
# Print grammar errors with line numbers | ||
if matches: | ||
for match in matches: | ||
print(f"Grammar error at line {match.offset} - {match.message}") | ||
# Exit with a non-zero code to indicate failure | ||
exit(1) | ||
else: | ||
# No grammar errors found, print a success message | ||
print("No grammar errors found.") | ||
|
||
exit(0) | ||
EOF |
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 |
---|---|---|
@@ -1,41 +1,38 @@ | ||
# Docs | ||
## About | ||
This directory contains the files required to create open source documentation. | ||
Tools used: [Sphinx](http://www.sphinx-doc.org/) | ||
### Configuration files | ||
* **Index.rst** - This is the main document. Main function of this document is to serve as a welcome page, and to contain the root of the “table of contents tree” (or toctree).This is one of the main things that Sphinx adds to reStructuredText, a way to connect multiple files to a single hierarchy of documents | ||
* **conf.py** - The configuration directory must contain a file named conf.py. This file (containing Python code) is called the “build configuration file” and contains (almost) all configuration needed to customize Sphinx input and output behavior. | ||
* **.md files** - Create all the markdown file which are referenced in the document tree with the appropriate content. | ||
This directory contains the files required to create open-source documentation. | ||
Tools used: [Sphinx] (http://www.sphinx-doc.org/). | ||
## Configuration files | ||
* **index.rst** - This is the main document. This is one of the main things that Sphinx adds to restructured text: a way to connect multiple files to a single hierarchy of documents, including the 'table of contents tree'(or toctree). | ||
* **conf.py**: The configuration directory must contain a file named conf.py. This file (containing Python code) is called the “build configuration file” and contains (almost) all the configuration needed to customize Sphinx input and output behavior. | ||
* **.md files**: Create all the markdown files that are referenced in the document tree with the appropriate content. | ||
|
||
``` | ||
./ | ||
├── docs | ||
│ ├── source | ||
│ │ ├── index.rst | ||
│ │ ├── conf.py | ||
│ │ ├── *.md | ||
| | |── index.rst | ||
│ │ ├── conf.py | ||
│ │ ├── *.md | ||
│ ├── Makefile | ||
| ├── pip-requirements.txt | ||
| ├── pip-requirements.txt | ||
│ └── README.md | ||
├── CONTRIBUTING.md | ||
``` | ||
|
||
### Building the docs | ||
1. Install latest sphinx | ||
1. Install the latest Sphinx. | ||
``` | ||
pip install -U Sphinx | ||
``` | ||
2. Install the pre-requisites | ||
2. Install the prerequisites. | ||
``` | ||
pip install -r pip-requirements.txt | ||
``` | ||
3. Build the documents | ||
3. Build the documents. | ||
``` | ||
make html | ||
make HTML | ||
or | ||
make.bat html | ||
make.bat HTML | ||
``` | ||
4. Access the documents from **build/html/** folder. | ||
|
||
|
||
|
||
4. Access the documents from the **build/html** folder. |
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
Oops, something went wrong.