Skip to content

Commit

Permalink
Issue eli64s#8 java support for README setup guide.
Browse files Browse the repository at this point in the history
  • Loading branch information
eli64s committed May 18, 2023
1 parent 285bbbd commit 9ddd273
Show file tree
Hide file tree
Showing 10 changed files with 720 additions and 20 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,37 @@ README-AI is a powerful, user-friendly tool that automatically generates high-qu
<td>1️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_1.md">README_1_PY.md</a></td>
<td><a href="https://github.com/eli64s/readme-ai">readme-ai</a></td>
<td><p>15459624</p>
<td><p>15,459,624</p>
</tr>
<tr>
<td>2️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_2.md">README_2_PY.md</a></td>
<td><a href="https://github.com/GokuMohandas/mlops-course">mlops-course</a></td>
<td><p>8698890</p>
<td><p>8,698,890</p>
</tr>
<tr>
<td>3️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_JS.md">README_3_JS.md</a></td>
<td><a href="https://github.com/philnash/react-web-audio">react-web-audio</a></td>
<td><p>533233</p>
<td><p>533,233</p>
</tr>
<tr>
<td>4️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_RUST.md">README_4_RUST.md</a></td>
<td><a href="https://github.com/MihaiBogdanEugen/contacts-cli">rust-contacts-cli</a></td>
<td><p>79104</p>
<td><p>79,104</p>
</tr>
<tr>
<td>5️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_3.md">README_5_FastAPI.md</a></td>
<td><a href="https://github.com/nofoobar/JobBoard-Fastapi">job-board-fastapi</a></td>
<td><p>75391521</p>
<td><p>75,391,521</p>
</tr>
<tr>
<td>6️⃣</td>
<td><a href="https://github.com/eli64s/README-AI/blob/main/docs/README_EX_3.md">README_6_JAVA.md</a></td>
<td><a href="https://github.com/avjinder/Minimal-Todo">java-minimal-todo</a></td>
<td><p>18,240,095</p>
</tr>
</table>
</div>
Expand Down
7 changes: 7 additions & 0 deletions conf/badges.json
Original file line number Diff line number Diff line change
Expand Up @@ -7344,6 +7344,13 @@
"color": "white",
"svg": "M11.591 19.649h.771v-3.786h-.77zm-6.874-5.03l-.238-.733 3.6-1.17.238.735-3.6 1.17m4.645-5.762L7.138 5.796l.624-.453 2.224 3.062-.624.454m5.315.028l-.624-.454 2.225-3.062.624.453-2.225 3.063m4.592 5.78l-3.6-1.17.238-.734 3.6 1.17-.238.733M12 .001C5.383.001 0 5.384 0 11.998 0 18.617 5.383 24 12 24s12-5.382 12-12c0-6.617-5.383-12-12-12zm0 2.43c5.284 0 9.569 4.283 9.569 9.567 0 5.287-4.285 9.573-9.569 9.573-5.286 0-9.57-4.286-9.57-9.573 0-5.284 4.285-9.567 9.57-9.567m1.552 7.96l.575 1.768.747.242 4.736-1.538-.86-2.645-4.736 1.539-.462.635m.337 2.5l-1.504 1.093v.785l2.927 4.03 2.25-1.636-2.927-4.029-.746-.243m-2.275 1.093l-1.504-1.093-.747.243-2.927 4.029 2.25 1.635 2.928-4.029v-.785M9.873 12.16l.574-1.767-.462-.635-4.736-1.54-.86 2.646 4.737 1.54.747-.244m1.198-2.22h1.859l.462-.636v-4.98H10.61v4.98l.461.636"
},
{
"name": "Java",
"hex": "",
"src": "https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white",
"color": "",
"svg": ""
},
{
"name": "JavaScript",
"hex": "F7DF1E",
Expand Down
2 changes: 1 addition & 1 deletion conf/conf.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenAI API language model parameters
[api]
api_key = ""
prompt_intro = """Generate a short summary that describes the capabilities of the GitHub project {}."""
prompt_intro = """Generate a 2-3 sentence summary that describes the capabilities of the GitHub project {}."""
prompt_slogan = """Generate a slogan for the GitHub project {}."""

# Repository (local and remote)
Expand Down
2 changes: 1 addition & 1 deletion conf/ignore_files.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ignore = [
".ini",
".yml",
".yaml",
".xml",
#".xml",
".properties",
".secret",
".key",
Expand Down
2 changes: 1 addition & 1 deletion conf/setup_guide.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Forth = ["gforth main.fs"]
Go = ["go build -o myapp", "./myapp"]
Groovy = ["grape install", "groovy main.groovy"]
Haskell = ["ghc -o myapp main.hs", "./myapp"]
Java = ["mvn clean install", "java -jar target/myapp.jar"]
Java = ["mvn clean install || gradle build", "java -jar target/myapp.jar"]
JavaScript = ["npm install", "npm start"]
Julia = ["julia --project -e 'import Pkg; Pkg.instantiate()'", "julia main.jl"]
Kotlin = ["gradle build", "java -jar build/libs/myapp.jar"]
Expand Down
654 changes: 654 additions & 0 deletions docs/README_EX_6_JAVA.md

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def create_setup_guide(conf: object, conf_helper: object, df: pd.DataFrame):
conf : object
Configuration object containing GitHub and markdown configurations.
conf_helper : object
Configuration helper object containing file extensions and setup guides.
Configuration helper object containing file extensions and setup guide.
df : pd.DataFrame
DataFrame containing parsed information from project files.
Expand All @@ -159,7 +159,9 @@ def create_setup_guide(conf: object, conf_helper: object, df: pd.DataFrame):
path = conf.github.path

df["Language"] = df["Module"].apply(
lambda x: Path(x).suffix[1:] if Path(x).suffix[1:] not in ignore_files else None
lambda x: Path(x).suffix[1:]
if Path(x).suffix[1:] not in ignore_files and Path(x).suffix != ".xml"
else None
)
top_language = df["Language"].value_counts().idxmax()

Expand All @@ -169,14 +171,14 @@ def create_setup_guide(conf: object, conf_helper: object, df: pd.DataFrame):

LOGGER.info(f"Top project language: {top_language}")
LOGGER.info(f"Top project language name: {language_name}")
LOGGER.info(f"{language_name} installation and setup: {language_setup}")
LOGGER.info(f"{language_name} installation & setup: {language_setup}")

if language_setup:
install_guide = language_setup[0]
run_guide = language_setup[1]

except KeyError as ke:
LOGGER.warning(f"KeyError: {ke}. Using default install and run guides.")
LOGGER.warning(f"KeyError: {ke}. Using default install and run guide.")

md_setup_guide = conf.md.setup.format(
name, path, name, install_guide, name, run_guide
Expand All @@ -187,7 +189,8 @@ def create_setup_guide(conf: object, conf_helper: object, df: pd.DataFrame):

def create_directory_tree(url: str) -> str:
"""
Creates a directory tree structure of the project based on its repository URL.
Creates a directory tree structure for the README.md
file based on the provided repository path or URL.
Parameters
----------
Expand Down
8 changes: 4 additions & 4 deletions src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import spacy

from logger import Logger
from preprocess import format_sentence
from preprocess import reformat_sentence

ENGINE_ID = "text-davinci-003"
ENGINE = f"https://api.openai.com/v1/engines/{ENGINE_ID}/completions"
Expand Down Expand Up @@ -123,7 +123,7 @@ async def fetch_summary(file_path: str, prompt: str) -> Tuple[str, str]:
json={
"prompt": prompt,
"temperature": 0,
"max_tokens": 50,
"max_tokens": 69,
"top_p": 1,
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
Expand All @@ -144,7 +144,7 @@ async def fetch_summary(file_path: str, prompt: str) -> Tuple[str, str]:
file_summary = data["choices"][0]["text"]
summary = re.sub(r"^[^a-zA-Z]*", "", file_summary)
summary_spacy = spacy_text_processor(summary)
summary_spacy = format_sentence(summary_spacy)
summary_spacy = reformat_sentence(summary_spacy)
return (file_path, summary_spacy)


Expand All @@ -166,7 +166,7 @@ def generate_summary_text(prompt: str) -> str:
completions = openai.Completion.create(
engine=ENGINE_ID,
prompt=prompt,
max_tokens=40,
max_tokens=69,
)
generated_text = completions.choices[0].text
return generated_text.lstrip()
Expand Down
8 changes: 5 additions & 3 deletions src/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def _get_file_parsers() -> Dict[str, callable]:
A dictionary containing file parsers for various file types.
"""
return {
"build.gradle": helper.parse_gradle,
"pom.xml": helper.parse_maven,
"cargo.toml": helper.parse_cargo_toml,
"cargo.lock": helper.parse_cargo_lock,
"go.mod": helper.parse_go_mod,
Expand Down Expand Up @@ -251,9 +253,9 @@ def get_repo_name(path: Union[str, Path]) -> str:
return repo_name


def format_sentence(text: str) -> str:
def reformat_sentence(text: str) -> str:
"""
Remove space between comma and period in a given string.
Remove extra spaces between punctuation marks
Parameters
----------
Expand All @@ -265,7 +267,7 @@ def format_sentence(text: str) -> str:
str
The input string with spaces between comma and period removed.
"""
return re.sub(r",\s*\.", ",.", text)
return re.sub(r"\s*([.,:;?!])\s*", r"\1 ", text)


def valid_url(s: str) -> bool:
Expand Down
28 changes: 28 additions & 0 deletions src/preprocess_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,31 @@ def parse_go_sum(file_path: str) -> List[str]:
dependencies = [match.group(1) for match in regex.finditer(content)]

return dependencies


# Java
def parse_gradle(file_path):
with open(file_path) as file:
content = file.read()

regex = re.compile(r"implementation\s+['\"]([^'\"]+)['\"]")
dependencies = regex.findall(content)

return dependencies


def parse_maven(file_path):
with open(file_path) as file:
content = file.read()

regex = re.compile(
r"<dependency>\s*<groupId>([^<]+)</groupId>\s*<artifactId>([^<]+)</artifactId>\s*<version>([^<]+)</version>"
)
dependencies = []
matches = regex.findall(content)
for match in matches:
group_id, artifact_id, version = match
dependency = f"{group_id}:{artifact_id}:{version}"
dependencies.append(dependency)

return dependencies

0 comments on commit 9ddd273

Please sign in to comment.