レポートの修正
This commit is contained in:
parent
f2961daec1
commit
3ed1efbbe0
2
.github/workflows/pyruff.yml
vendored
2
.github/workflows/pyruff.yml
vendored
@ -42,7 +42,7 @@ jobs:
|
||||
- name: Generate Linter Report
|
||||
id: generateLinterReport
|
||||
run: |
|
||||
python scripts/generate_linter_from_json.py
|
||||
python scripts/generate_linter.py
|
||||
|
||||
|
||||
- name: pull_request message with Ruff Lint results
|
||||
|
||||
15
lint-result.md
Normal file
15
lint-result.md
Normal file
@ -0,0 +1,15 @@
|
||||
## Linter(リンタ)レビュー
|
||||
|
||||
以下の指摘事項があります。コードを見直してください。
|
||||
|
||||
総数:6個
|
||||
|
||||
### 指摘事項一覧
|
||||
|コード|重要性|項目|ファイル名|行数|
|
||||
|---|---|---|---|---|
|
||||
|W291|🟢低|行末に不要な空白があります。|examples/example.py|14行目27列 〜 14行目28列|
|
||||
|W291|🟢低|行末に不要な空白があります。|scripts/generate_coverage.py|5行目23列 〜 5行目24列|
|
||||
|E501|🟢低|行が長すぎます。79文字以内にしてください。|scripts/generate_coverage.py|38行目89列 〜 38行目107列|
|
||||
|W291|🟢低|行末に不要な空白があります。|scripts/generate_linter_from_json.py|4行目23列 〜 4行目24列|
|
||||
|W291|🟢低|行末に不要な空白があります。|scripts/generate_linter_from_json.py|25行目31列 〜 25行目39列|
|
||||
|W292|🟢低|ファイルの最後に改行がありません。|scripts/generate_linter_from_json.py|53行目42列 〜 53行目42列|
|
||||
90
scripts/generate_linter.py
Normal file
90
scripts/generate_linter.py
Normal file
@ -0,0 +1,90 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_NAME = Path(".").resolve().name
|
||||
print(f"Project Name: {PROJECT_NAME}")
|
||||
|
||||
|
||||
CODE_MAP = {
|
||||
"W291": {"message": "行末に不要な空白があります。", "severity": "🟢低"},
|
||||
"W292": {"message": "ファイルの最後に改行がありません。", "severity": "🟢低"} ,
|
||||
"E501": {
|
||||
"message": "行が長すぎます。79文字以内にしてください。",
|
||||
"severity": "🟢低",
|
||||
},
|
||||
}
|
||||
|
||||
def get_relative_path(absolute_path: str) -> str:
|
||||
"""
|
||||
絶対パスからプロジェクトルートからの相対パスを取得
|
||||
"""
|
||||
try:
|
||||
index = absolute_path.index(PROJECT_NAME)
|
||||
return absolute_path[index + len(PROJECT_NAME) + 1 :]
|
||||
except ValueError:
|
||||
return absolute_path
|
||||
|
||||
|
||||
class GenerateLinter:
|
||||
def __init__(self, json_file="ruff-report.json", output_file="lint-result.json"):
|
||||
"""
|
||||
初期化
|
||||
"""
|
||||
self.json_file = json_file
|
||||
self.output_file = output_file
|
||||
|
||||
def _genarate_lint_report(self, data: list) -> str:
|
||||
_str = ""
|
||||
if not data:
|
||||
_str += "## Linter(リンタ)指摘事項なし\n\n"
|
||||
_str += "素晴らしいコードです!🎉\n"
|
||||
return _str
|
||||
|
||||
_str += "## Linter(リンタ)レビュー\n\n"
|
||||
_str += "以下の指摘事項があります。コードを見直してください。\n\n"
|
||||
|
||||
_str += f"総数:{len(data)}個\n"
|
||||
|
||||
_str += "### 指摘事項一覧\n"
|
||||
_str += "|コード|重要性|項目|ファイル名|行数|\n"
|
||||
_str += "|---|---|---|---|---|\n"
|
||||
for issue in data:
|
||||
code = issue.get("code", "-")
|
||||
severity = (
|
||||
CODE_MAP.get(code, {}).get("severity", "❓不明")
|
||||
if code != "-"
|
||||
else "-"
|
||||
)
|
||||
message = CODE_MAP.get(code, {}).get("message", issue.get("message", "-"))
|
||||
filename = get_relative_path(issue.get("filename", "-"))
|
||||
line = ""
|
||||
if issue.get("location") and issue["location"].get("row"):
|
||||
line = f"{issue['location']['row']}行目"
|
||||
if issue["location"].get("column"):
|
||||
line += f"{issue['location']['column']}列"
|
||||
|
||||
if issue.get("end_location"):
|
||||
if issue["end_location"].get("row"):
|
||||
line += f" 〜 {issue['end_location']['row']}行目"
|
||||
if issue["end_location"].get("column"):
|
||||
line += f"{issue['end_location']['column']}列"
|
||||
|
||||
_str += f"|{code}|{severity}|{message}|{filename}|{line}|\n"
|
||||
return _str
|
||||
|
||||
def generate_lint_report_json(self):
|
||||
with open(self.json_file, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
with open(self.output_file, "w") as f:
|
||||
report_body = self._genarate_lint_report(data)
|
||||
f.write(report_body)
|
||||
# report = {"body": self._genarate_lint_report(data)}
|
||||
# json.dump(report, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print(f"Linter report generated: {self.output_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generator = GenerateLinter()
|
||||
generator.generate_lint_report_json()
|
||||
@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/genarater_linter.sh
|
||||
|
||||
set -u # 未定義変数の利用で落とす(-e は付けない)
|
||||
|
||||
RUFF_STATUS=0
|
||||
OUTPUT_MD=${1:-lint-result.md}
|
||||
|
||||
{
|
||||
echo "## 🧹 Ruff Lint Result"
|
||||
echo
|
||||
echo "### Command"
|
||||
echo '```bash'
|
||||
echo '$ ruff check .'
|
||||
echo '```'
|
||||
echo
|
||||
echo "### Output"
|
||||
echo '```text'
|
||||
# ruff がエラーになってもスクリプト自体は落とさず、ステータスだけ拾う
|
||||
ruff check . || RUFF_STATUS=$?
|
||||
echo '```'
|
||||
echo
|
||||
echo "### Summary"
|
||||
echo
|
||||
echo "| Tool | Status |"
|
||||
echo "|------|--------|"
|
||||
if [ "$RUFF_STATUS" -eq 0 ]; then
|
||||
echo "| ruff | ✅ OK |"
|
||||
else
|
||||
echo "| ruff | ❌ Error (exit $RUFF_STATUS) |"
|
||||
fi
|
||||
} | tee "$OUTPUT_MD"
|
||||
|
||||
# GitHub Actions から呼ばれた場合は、出力変数としてステータスを渡す
|
||||
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
||||
echo "ruff_status=$RUFF_STATUS" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# ここでは常に 0 で終了(失敗にするかどうかはワークフロー側で制御)
|
||||
exit 0
|
||||
@ -1,49 +0,0 @@
|
||||
import json
|
||||
|
||||
class GenerateLinter:
|
||||
def __init__(self,
|
||||
json_file="ruff-report.json",
|
||||
output_file="lint-result.json"):
|
||||
"""
|
||||
初期化
|
||||
"""
|
||||
self.json_file = json_file
|
||||
self.output_file = output_file
|
||||
|
||||
def _genarate_lint_report(self, data: list) -> str:
|
||||
_str = ""
|
||||
if not data:
|
||||
_str += "## Linter(リンタ)指摘事項なし\n\n"
|
||||
_str += "素晴らしいコードです!🎉\n"
|
||||
return _str
|
||||
|
||||
_str += "## Linter(リンタ)レビュー\n\n"
|
||||
_str += "以下の指摘事項があります。コードを見直してください。\n\n"
|
||||
|
||||
_str += "### 指摘事項一覧\n"
|
||||
_str += "|コード|重要性|ファイル名|行数|課題内容\n"
|
||||
_str += "|---|---|---|---|---|\n"
|
||||
for issue in data:
|
||||
code = issue.get("code", "-")
|
||||
severity = issue.get("severity", "-")
|
||||
filename = issue.get("filename", "-")
|
||||
line = issue.get("location", {}).get("line", "-")
|
||||
message = issue.get("message", "-")
|
||||
_str += f"|{code}|{severity}|{filename}|{line}|{message}|\n"
|
||||
return _str
|
||||
|
||||
def generate_lint_report_json(self):
|
||||
|
||||
with open(self.json_file, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
with open(self.output_file, "w") as f:
|
||||
report = {"body": self._genarate_lint_report(data)}
|
||||
json.dump(report, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print(f"Linter report generated: {self.output_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generator = GenerateLinter()
|
||||
generator.generate_lint_report_json()
|
||||
Loading…
x
Reference in New Issue
Block a user