Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions toasty/pr_analyzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
46 changes: 46 additions & 0 deletions toasty/pr_analyzer/PR_prioritizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from github import Github
from sarvamai import SarvamAI
from PR_seeker import Seeker
from priority_generator import Generator


seeker = Seeker()
generator = Generator()
client = SarvamAI(api_subscription_key=os.getenv("SARVAM_API_KEY"))

# Priority segregation.
high = ["Bug Fix", "Performance Improvement", "Security Fix"]
mid = ["Feature Addition", "Refactoring", "Testing"]
low = ["Documentation Update", "Others"]

gh_link = input("Enter repo link: ").strip()
# Converting repo links to a 'owner/repo' format, without requiring the maintainer to format it themselves, thus reducing the cognitive load needed (to an extent).
new_gh_link = gh_link
if new_gh_link.startswith("https://github.com/"):
new_gh_link = new_gh_link.replace("https://github.com/", "")
'''
elif new_gh_link.startswith("http://github.com/"):
new_gh_link = new_gh_link.replace("http://github.com/", "")
'''
new_gh_link = new_gh_link.rstrip('/')

if new_gh_link.endswith('.git'):
new_gh_link = new_gh_link[:-4]

print(new_gh_link)

response = ''
store_lst = seeker.forward(new_gh_link)
for i in range(len(store_lst)):
title = store_lst[i]['Title']
body = store_lst[i]['Body']

response = generator.forward(title, body).strip()

if response in high:
print(response, ": high")
elif response in mid:
print(response, ": medium")
elif response in low:
print(response, ": low")
27 changes: 27 additions & 0 deletions toasty/pr_analyzer/PR_seeker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from github import Github
import os

class Seeker:
def __init__(self):
self.PERSONAL_TOKEN = os.getenv('PERSONAL_TOKEN')
self.store_dict = {}
self.store_list = []
self.do_not_include = """<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey)."""

#self.f = open("Output.txt", "w")
def forward(self, repository:str):
g = Github(self.PERSONAL_TOKEN)
repo = g.get_repo(repository)
pulls = repo.get_pulls(state='all')
store_list = []
for pr in pulls:
if pr != self.do_not_include:
store_dict = {}
store_dict['Title'] = pr.title
store_dict['Body'] = pr.body
store_list.append(store_dict)
#self.f.writelines(store_list)
return store_list
3 changes: 3 additions & 0 deletions toasty/pr_analyzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PR (Pull Request) analyzer.

This module retrieves PRs from GitHub, classifies them using Sarvam-M API, and generates priority categories (High, Medium, and Low) for project managers.
Empty file added toasty/pr_analyzer/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions toasty/pr_analyzer/priority_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from sarvamai import SarvamAI
from PR_seeker import Seeker
#from dotenv import load_dotenv
import os

#load_dotenv()
client = SarvamAI(api_subscription_key=os.getenv("SARVAM_API_KEY"))

class Generator:
def __init__(self):
self.client = client
self.categories = ["Bug Fix", "Feature Addition", "Documentation Update",
"Performance Improvement", "Refactoring", "Testing", "Others"]

def forward(self, pr_title: str, pr_body: str):
pr_content = f"Title: {pr_title}\nBody: {pr_body}"

response = self.client.chat.completions(
messages=[
{'role': 'system', 'content': f'You are a Pull Request (PR) analyzer. You classify them into the following categories: {", ".join(self.categories)}. Classify the PR into exactly ONE of these categories: {", ".join(self.categories)}. Output ONLY the category label, with no explanation or additional text.'},
{"role": "user", "content": pr_content}
],
temperature=0.5,
top_p=1,
max_tokens=1000,
)

return response.choices[0].message.content
2 changes: 2 additions & 0 deletions toasty/pr_analyzer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github
sarvamai
16 changes: 16 additions & 0 deletions toasty/pr_analyzer/testing_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Add:
def __init__(self, c):
self.c = c
def forward(self, a, b):
c = a+b
return c

class test:
def __init__(self):
self.add = Add(0)
def forward(self, a, b):
c = self.add.forward(a, b)
return c

t = test()
print(t.forward(10, 12))