-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
server/intelligence-service/app/detector/bad_practice_detector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import List | ||
|
||
class PullRequest: | ||
id: str | ||
title: str | ||
description: str | ||
|
||
class Rule: | ||
name: str | ||
description: str | ||
bad_practice_id: str | ||
|
||
class PullRequestWithBadPractices: | ||
pull_request_id: str | ||
bad_practice_ids: List[str] | ||
|
||
def detectbadpractices(pull_requests: List[PullRequest], rules: List[Rule]) -> List[PullRequestWithBadPractices]: | ||
bad_practices = [] | ||
for pull_request in pull_requests: | ||
bad_practice_ids = [] | ||
for rule in rules: | ||
if rule.bad_practice_id in pull_request.description: | ||
bad_practice_ids.append(rule.bad_practice_id) | ||
bad_practices.append(PullRequestWithBadPractices(pull_request_id=pull_request.id, bad_practice_ids=bad_practice_ids)) | ||
return bad_practices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import List | ||
from fastapi import APIRouter | ||
from pydantic import BaseModel | ||
|
||
from app.detector.bad_practice_detector import PullRequestWithBadPractices, PullRequest, Rule, detectbadpractices | ||
|
||
router = APIRouter(prefix="/detector", tags=["detector"]) | ||
|
||
class DetectorRequest(BaseModel): | ||
pull_requests: List[PullRequest] | ||
rules: List[Rule] | ||
|
||
class DetectorResponse(BaseModel): | ||
detectBadPractices: List[PullRequestWithBadPractices] | ||
|
||
@router.post( | ||
"/", | ||
response_model=DetectorResponse, | ||
summary="Detect bad practices given rules.", | ||
) | ||
def detect(request: DetectorRequest): | ||
return detectbadpractices(request.pull_requests, request.rules) |