Skip to content

Commit

Permalink
grouped envs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsb-23 committed Dec 1, 2024
1 parent acfb805 commit 97c5480
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ runs:
GROQ_API_KEY: ${{ inputs.GROQ_API_KEY }}
token: ${{ inputs.token }}
PR_NO: ${{ github.event.pull_request.number }}
repo: $GITHUB_REPOSITORY
run: python src/spell_check.py
14 changes: 14 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os


def get_env(x):
return os.environ[x]


GROQ_API_KEY = get_env("GROQ_API_KEY")
PAT_TOKEN = get_env("token")

REPO = get_env("GITHUB_REPOSITORY")
PR_BASE = get_env("PR_BASE")
PR_NO = get_env("PR_NO")
INPUT_FILES = [*map(str.strip, get_env("INPUT_FILES").splitlines())]
5 changes: 3 additions & 2 deletions src/groq_ai.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import json
import os
from functools import cache

from groq import NOT_GIVEN, BadRequestError, Groq

from src.config import GROQ_API_KEY

model = ["llama-3.1-8b-instant", "llama3-70b-8192"][1]


@cache
def get_groq_client():
return Groq(api_key=os.environ.get("GROQ_API_KEY"))
return Groq(api_key=GROQ_API_KEY)


def ask_groq(query_text: str, system_content: str, json_schema: dict = None) -> dict:
Expand Down
18 changes: 6 additions & 12 deletions src/spell_check.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import subprocess

import requests

from config import INPUT_FILES, PAT_TOKEN, PR_BASE, PR_NO, REPO
from groq_ai import find_typos


def process_diff(file_path, base_branch):
def process_diff(file_path, base_branch=PR_BASE):
try:
# Get diff from PR
diff_command = f"git diff -U0 origin/{base_branch}... -- {file_path}"
Expand All @@ -21,25 +21,19 @@ def process_diff(file_path, base_branch):


def post_comment(comment):
pr_no = os.environ["PR_NO"]
repo = os.environ["repo"]
url = f"https://api.github.com/repos/{repo}/issues/{pr_no}/comments"
url = f"https://api.github.com/repos/{REPO}/issues/{PR_NO}/comments"
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {os.environ['token']}",
"Authorization": f"Bearer {PAT_TOKEN}",
"X-GitHub-Api-Version": "2022-11-28",
}
resp = requests.post(url, headers=headers, json={"body": comment})
resp.raise_for_status()


def main():
# Get required inputs
pr_base = os.environ["PR_BASE"]
files = [*map(str.strip, os.environ["INPUT_FILES"].splitlines())]
print(pr_base, *files, sep="\n")

results = {file_path: process_diff(file_path, pr_base) for file_path in files if file_path}
# Process diff(s) for each file
results = {file_path: process_diff(file_path) for file_path in INPUT_FILES if file_path}

# Create markdown comment for fixes
flag = False
Expand Down

0 comments on commit 97c5480

Please sign in to comment.