Skip to content

Commit

Permalink
Added the pr_filter to query params and made response to non_paginate…
Browse files Browse the repository at this point in the history
…d_pr_response
  • Loading branch information
RISHIKESHk07 committed Oct 4, 2024
1 parent 437396f commit 9422021
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
15 changes: 11 additions & 4 deletions backend/analytics_server/mhq/api/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,21 @@ def get_team_lead_time_trends(
{
Required("from_time"): All(str, Coerce(datetime.fromisoformat)),
Required("to_time"): All(str, Coerce(datetime.fromisoformat)),
Optional("pr_filter"): All(str, Coerce(json.loads)),
}
),
)
def merged_without_review(team_id: str, from_time: datetime, to_time: datetime):
def merged_without_review(
team_id: str, from_time: datetime, to_time: datetime, pr_filter: Dict = None
):
query_validator = get_query_validator()
team: Team = query_validator.team_validator(team_id)
interval: Interval = query_validator.interval_validator(from_time, to_time)
pr_filter: PRFilter = apply_pr_filter(
pr_filter, EntityType.TEAM, team_id, [SettingType.EXCLUDED_PRS_SETTING]
)
pr_analytics = get_pr_analytics_service()
result = pr_analytics.get_prs_merged_without_review(team.id, interval)
prs_map = [pr.id for pr in result]
return {"PrsWithoutReviewMerged": prs_map}
repos = pr_analytics.get_team_repos(team_id)
prs = pr_analytics.get_prs_merged_without_review(team.id, interval, pr_filter)
repo_id_repo_map = {repo.id: repo for repo in repos}
return get_non_paginated_pr_response(prs, repo_id_repo_map, len(prs))
5 changes: 5 additions & 0 deletions backend/analytics_server/mhq/api/resources/code_resouces.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,8 @@ def adapt_team_repos(team_repos: List[TeamRepos]) -> List[Dict[str, any]]:
}
for team_repo in team_repos
]

def get_non_paginated_merged_without_review(prs: List[PullRequest]) -> List[Dict[str,any]]:
return {
"data": []
}
6 changes: 4 additions & 2 deletions backend/analytics_server/mhq/service/code/pr_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def get_prs_by_ids(self, pr_ids: List[str]) -> List[PullRequest]:
return self.code_repo_service.get_prs_by_ids(pr_ids)

def get_prs_merged_without_review(
self, team_id: str, interval: Interval
self, team_id: str, interval: Interval, pr_filter: dict
) -> List[PullRequest]:
return self.code_repo_service.get_prs_merged_without_review(team_id, interval)
return self.code_repo_service.get_prs_merged_without_review(
team_id, interval, pr_filter
)

def get_team_repos(self, team_id: str) -> List[OrgRepo]:
return self.code_repo_service.get_team_repos(team_id)
Expand Down
20 changes: 15 additions & 5 deletions backend/analytics_server/mhq/store/repos/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,30 @@ def get_team_repos(self, team_id) -> List[OrgRepo]:
return self.get_repos_by_ids(team_repo_ids)

@rollback_on_exc
def get_prs_merged_without_review(self, team_id, interval) -> List[PullRequest]:
def get_prs_merged_without_review(
self, team_id: str, interval: Interval, pr_filter: PRFilter = None
) -> List[PullRequest]:
AllOrg = self.get_team_repos(team_id)
AllOrg_ids = [tr.id for tr in AllOrg]
return (
query = (
self._db.session.query(PullRequest)
.filter(PullRequest.repo_id.in_(AllOrg_ids))
.filter(PullRequest.state == PullRequestState.MERGED)
.filter(PullRequest.merge_time == None)
.filter(
PullRequest.created_in_db_at.between(
interval.from_time, interval.to_time
or_(
PullRequest.created_at.between(
interval.from_time, interval.to_time
),
PullRequest.updated_at.between(
interval.from_time, interval.to_time
),
)
)
.all()
)
query = self._filter_prs(query, pr_filter)

return query.all()

@rollback_on_exc
def get_team_repos_by_team_id(self, team_id: str) -> List[TeamRepos]:
Expand Down

0 comments on commit 9422021

Please sign in to comment.