Skip to content

Commit e56e68a

Browse files
committed
Feat: Automated Ticket Review
1 parent 029d2ba commit e56e68a

8 files changed

+396
-104
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ WORKDIR /app
33
COPY ./requirements.txt /app
44
RUN pip install -r requirements.txt
55
COPY . .
6+
COPY ./utils/c4gt-repository-monitor.2023-06-14.private-key.pem /app/utils/
67
EXPOSE 5000
78
ENV FLASK_APP=app.py
89
CMD ["flask", "run", "--host", "0.0.0.0"]

app.py

+263-57
Large diffs are not rendered by default.

githubApi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from jwt_generator import GenerateJWT
1+
from utils.jwt_generator import GenerateJWT
22
print(GenerateJWT().__call__())

markdown_handler.py

-45
This file was deleted.

utils/__init__.py

Whitespace-only changes.

utils/github_api.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from utils.jwt_generator import GenerateJWT
2+
import requests
3+
class GithubAPI:
4+
def __init__(self):
5+
self.headers = {
6+
'Accept': 'application/vnd.github+json',
7+
# 'Authorization': f'Bearer {os.getenv("GithubPAT")}'
8+
}
9+
return
10+
11+
def authenticate_app_as_installation(self, repo_owner):
12+
installation_id = 0
13+
jwt = GenerateJWT().__call__()
14+
url = f"https://api.github.com/app/installations"
15+
self.headers["Authorization"]=f'Bearer {jwt}'
16+
installations = requests.get(url, headers=self.headers).json()
17+
for installation in installations:
18+
if installation["account"]["login"] == repo_owner:
19+
installation_id = installation["id"]
20+
url=f"https://api.github.com/app/installations/{installation_id}/access_tokens"
21+
22+
if not installation_id:
23+
return None
24+
token_req = requests.post(url=url, headers=self.headers).json()
25+
return token_req["token"]
26+
27+
28+

jwt_generator.py renamed to utils/jwt_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class GenerateJWT:
1111
def __call__(self, *args: Any, **kwds: Any) -> Any:
12-
pem="/root/c4gt-server/repository_monitor_app_pk.pem"
12+
pem="/app/utils/c4gt-repository-monitor.2023-06-14.private-key.pem"
1313
app_id=346766
1414

1515
# Open PEM

utils/markdown_handler.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import markdown, re
2+
3+
test_md = """
4+
## Description
5+
[Provide a brief description of the feature, including why it is needed and what it will accomplish. You can skip any of Goals, Expected Outcome, Implementation Details, Mockups / Wireframes if they are irrelevant]
6+
7+
## Goals
8+
- [ ] [Goal 1]
9+
- [ ] [Goal 2]
10+
- [ ] [Goal 3]
11+
- [ ] [Goal 4]
12+
- [ ] [Goal 5]
13+
14+
## Expected Outcome
15+
[Describe in detail what the final product or result should look like and how it should behave.]
16+
17+
## Acceptance Criteria
18+
- [ ] [Criteria 1]
19+
- [ ] [Criteria 2]
20+
- [ ] [Criteria 3]
21+
- [ ] [Criteria 4]
22+
- [ ] [Criteria 5]
23+
24+
## Implementation Details
25+
[List any technical details about the proposed implementation, including any specific technologies that will be used.]
26+
27+
## Mockups / Wireframes
28+
[Include links to any visual aids, mockups, wireframes, or diagrams that help illustrate what the final product should look like. This is not always necessary, but can be very helpful in many cases.]
29+
30+
---
31+
32+
### Project
33+
[Project Name]
34+
35+
### Organization Name:
36+
[Organization Name]
37+
38+
### Domain
39+
[Area of governance]
40+
41+
### Tech Skills Needed:
42+
[Required technical skills for the project]
43+
44+
### Mentor(s)
45+
[@Mentor1] [@Mentor2] [@Mentor3]
46+
47+
### Complexity
48+
Pick one of [High]/[Medium]/[Low]
49+
50+
### Category
51+
Pick one or more of [CI/CD], [Integrations], [Performance Improvement], [Security], [UI/UX/Design], [Bug], [Feature], [Documentation], [Deployment], [Test], [PoC]
52+
53+
### Sub Category
54+
Pick one or more of [API], [Database], [Analytics], [Refactoring], [Data Science], [Machine Learning], [Accessibility], [Internationalization], [Localization], [Frontend], [Backend], [Mobile], [SEO], [Configuration], [Deprecation], [Breaking Change], [Maintenance], [Support], [Question], [Technical Debt], [Beginner friendly], [Research], [Reproducible], [Needs Reproduction].
55+
56+
57+
"""
58+
59+
class MarkdownHandler:
60+
def __init__(self) -> None:
61+
return
62+
63+
def markdownParser(self, markdown_content):
64+
65+
#Taking metadata
66+
markdown_metadata = markdown_content.split('---')[1]
67+
68+
# Parse Markdown to HTML
69+
html = markdown.markdown(markdown_metadata)
70+
# print("-------METADATA----------")
71+
72+
# Split HTML into sections using heading tags as delimiters
73+
sections = re.split("</h3>|<h3>", html)
74+
while '' in sections:
75+
sections.remove('')
76+
# print("------SECTIONS---------")
77+
for section in sections:
78+
# print(sections, section)
79+
section.strip()
80+
section = re.split("<p>|</p>", section)
81+
# Define regex pattern to match '\n', ':', and any html tags'<>'
82+
pattern = re.compile(r'[\n]|[:]|<(.*?)>')
83+
84+
# Remove matching substrings from each string
85+
clean_sections = [re.sub(pattern, '', s) for s in sections]
86+
87+
# Initialize dictionary
88+
markdown_dict = {}
89+
for i in range(0,len(clean_sections), 2):
90+
markdown_dict[clean_sections[i]] = clean_sections[i+1]
91+
return markdown_dict
92+
93+
def markdownMetadataValidator(self, markdown_dict):
94+
required_headings = ["Project", "Organization Name", "Domain", "Tech Skills Needed", "Mentor(s)", "Complexity", "Category", "Sub Category"]
95+
missing_headings=[]
96+
for heading in required_headings:
97+
if heading not in markdown_dict.keys():
98+
missing_headings.append(heading)
99+
100+
return missing_headings
101+
102+

0 commit comments

Comments
 (0)