Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods for feature Prs_not_reviwed_Merged in PulllrequestAnalysis Service #495

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

RISHIKESHk07
Copy link

Linked Issue(s)

#207

Acceptance Criteria fulfillment

  • Add Python Backend API to fetch Teams PRs merged without review for a team.

Proposed changes (including videos or screenshots)

Added required method in PullrequestAnalysisService & route in the pull_request.py

  • Added method which takes a team_id as the input , finds the list of org_repos from which we use to query the PullRequest realted tables
  • Finds the Prs (ids of pull_requests ) which are reviewed ( from the PullRequestEvent ) and then filters the Prs which are not reviewed , and finally filters for the ones which are Merged and returns the count of Prs which are not Reviwed But Merged

@CLAassistant
Copy link

CLAassistant commented Aug 1, 2024

CLA assistant check
All committers have signed the CLA.

@RISHIKESHk07
Copy link
Author

will clean up the the print statements and add types as well on the next commit

backend/analytics_server/mhq/api/pull_requests.py Outdated Show resolved Hide resolved
backend/analytics_server/mhq/store/repos/code.py Outdated Show resolved Hide resolved
backend/analytics_server/mhq/api/pull_requests.py Outdated Show resolved Hide resolved
backend/analytics_server/mhq/service/code/pr_analytics.py Outdated Show resolved Hide resolved
backend/analytics_server/mhq/store/repos/code.py Outdated Show resolved Hide resolved
@jayantbh
Copy link
Contributor

jayantbh commented Aug 7, 2024

Hey @RISHIKESHk07, have you had a chance to look at this?

@RISHIKESHk07
Copy link
Author

Evening @jayantbh , i did look at it , have done the changes except for one doubt , did ping samad about it , the change involved the need of adding interval as argument in the function , any where I could refer similar implementation of using interval , it was used inorder to not call all the prs from the db . It should be in the changes requested above , Thanks for notifying

@jayantbh
Copy link
Contributor

jayantbh commented Aug 7, 2024

Sounds good, @RISHIKESHk07
You can also join our Slack (if you haven't) and ping in the #open-source channel for help.

@jayantbh
Copy link
Contributor

jayantbh commented Aug 8, 2024

@RISHIKESHk07 there's a failing linter check.

@RISHIKESHk07
Copy link
Author

@RISHIKESHk07 there's a failing linter check.

i did not run the linting command mostly , where could i find it ?

@RISHIKESHk07 RISHIKESHk07 force-pushed the Feature-Prs_Not_Reviwed_Merged branch from d6bbf30 to 60165f9 Compare August 11, 2024 04:52
@samad-yar-khan
Copy link
Contributor

@RISHIKESHk07 Try using black version 24.4.2

@RISHIKESHk07 RISHIKESHk07 force-pushed the Feature-Prs_Not_Reviwed_Merged branch from 60165f9 to 9ba14e2 Compare August 15, 2024 05:26
@RISHIKESHk07
Copy link
Author

@RISHIKESHk07 Try using black version 24.4.2

done

jayantbh
jayantbh previously approved these changes Aug 15, 2024
Copy link
Contributor

@jayantbh jayantbh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. But I'll let @samad-yar-khan or @adnanhashmi09 take a final look.

Comment on lines 174 to 180
Schema(
{
Required("from_time"): All(str, Coerce(datetime.fromisoformat)),
Required("to_time"): All(str, Coerce(datetime.fromisoformat)),
}
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RISHIKESHk07 we additionally have a PR filter that we use in query params which is missing here. PR filter helps us add more querying from branch, author etc at a api level by just adding handler for the query.

Copy link
Author

@RISHIKESHk07 RISHIKESHk07 Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan do i need to include pr_filter in the pr_analytics_service ( for prs_merged_without_review ) as well ? , any more info i need to know about this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, PR filter is applied at repo, so you will have to pass it down funcs as argument

Comment on lines 359 to 390
PullRequest.created_in_db_at.between(
interval.from_time, interval.to_time
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kamlesh72 created_at_in_db is the timestamp at which the data was stored in our db, which is irrelevant for a user. If they wish to query data in a date range, they are likely searching PRs that were either created or updated in that interval.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan created_at & updated_at should fix this

Copy link
Contributor

@samad-yar-khan samad-yar-khan Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RISHIKESHk07 there is one more logical bug in this query. Its fetching open PRs as well as merged PRs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan I believe this is for @RISHIKESHk07

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan querying state for merged should correct that , i did try testing on a team repo but i see only closed & merged state Prs ,but we do have a few open Prs , (selcted pr merge while creating team did i miss anything ??)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should work but I dont see that in your PR.

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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested out this API. It just returns a list of ids. This is not useful for the front end. We need to send a list of PRs as data to the backend. We are already using a func in the same file in /lead_time/prs API. Please refer the implementation for that API. Should help.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't name our property keys that go in API responses in that case either. @RISHIKESHk07

@jayantbh jayantbh dismissed their stale review August 17, 2024 10:54

I missed some things.

@RISHIKESHk07 RISHIKESHk07 force-pushed the Feature-Prs_Not_Reviwed_Merged branch 2 times, most recently from 61ddad8 to 9422021 Compare October 4, 2024 14:13
@RISHIKESHk07
Copy link
Author

@samad-yar-khan @jayantbh please take a look at the changes , apologies for the stale period of the PR was occupied with a university matter

Comment on lines 359 to 390
PullRequest.created_in_db_at.between(
interval.from_time, interval.to_time
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should work but I dont see that in your PR.


def get_non_paginated_merged_without_review(prs: List[PullRequest]) -> List[Dict[str,any]]:
return {
"data": []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this func has to be deleted ? since you are now using get_non_paginated_pr_response

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan Was going to implement my own before finding the get_non_paginated_pr_response , and if i use the _filter_prs_merged_in_interval, i would not need to query for merge state explicitly again as it will be handled by this method

self._db.session.query(PullRequest)
.filter(PullRequest.repo_id.in_(AllOrg_ids))
.filter(PullRequest.state == PullRequestState.MERGED)
.filter(PullRequest.merge_time == None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter(PullRequest.merge_time == None)
.filter(PullRequest.merge_time.is_(None))

Comment on lines 382 to 389
or_(
PullRequest.created_at.between(
interval.from_time, interval.to_time
),
PullRequest.updated_at.between(
interval.from_time, interval.to_time
),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are fetching PRs merged without review in interval. I think it would be valuable to look into _filter_prs_merged_in_interval method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samad-yar-khan will replace it with already implemented method , did see this while scrolling the file

Comment on lines 374 to 375
AllOrg = self.get_team_repos(team_id)
AllOrg_ids = [tr.id for tr in AllOrg]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AllOrg = self.get_team_repos(team_id)
AllOrg_ids = [tr.id for tr in AllOrg]
team_repos = self.get_team_repos(team_id)
repo_ids = [team_repo.id for team_repo in team_repos]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable names should be better and follow similar patterns as other part of the codebase. Having var names like AllOrg and AllOrg_ids makes the code harder to read and do not follow either snake case or camel case. We generally follow snake case in the python backend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move the repo fetching part to PullRequestAnalyticsService and the just pass on repo_ids to the Repo. Separates the basic query from business layer and we can also follow the same pattern as get_prs_merged_in_interval

@samad-yar-khan
Copy link
Contributor

@samad-yar-khan @jayantbh please take a look at the changes , apologies for the stale period of the PR was occupied with a university matter

@RISHIKESHk07 no worries, can totally understand. There has been significant improvement in the code quality since the previous review. Its 90% there and almost usable 🚀 Keep pushing 💯

@RISHIKESHk07 RISHIKESHk07 force-pushed the Feature-Prs_Not_Reviwed_Merged branch from 9422021 to ac14715 Compare October 30, 2024 16:44
@RISHIKESHk07
Copy link
Author

@samad-yar-khan please take a look if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants