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

feat(scm): pull request file issues API #74352

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Jul 16, 2024

API for users to upload their PR file information (filename, patch) to find issues associated with those files. This API can fetch issues for a single file.

This expands the scope of open PR issue comments beyond GitHub, and people can hit the API in their custom flows as well.

The API supports the ability to set a max limit on the number of issues to return, open PR comments only fetches a max of 5 per file -- using that as the default here.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 16, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 88.05970% with 8 lines in your changes missing coverage. Please review.

Project coverage is 78.24%. Comparing base (c6e4b4c) to head (9a59982).
Report is 704 commits behind head on master.

Files Patch % Lines
...endpoints/organization_pull_request_file_issues.py 93.22% 2 Missing and 2 partials ⚠️
...entry/tasks/integrations/github/open_pr_comment.py 42.85% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #74352      +/-   ##
==========================================
- Coverage   78.25%   78.24%   -0.01%     
==========================================
  Files        6829     6830       +1     
  Lines      303325   303389      +64     
  Branches    52201    52214      +13     
==========================================
+ Hits       237352   237398      +46     
- Misses      59597    59611      +14     
- Partials     6376     6380       +4     
Files Coverage Δ
src/sentry/api/urls.py 100.00% <100.00%> (ø)
...endpoints/organization_pull_request_file_issues.py 93.22% <93.22%> (ø)
...entry/tasks/integrations/github/open_pr_comment.py 88.93% <42.85%> (-1.61%) ⬇️

... and 6 files with indirect coverage changes

@cathteng cathteng marked this pull request as ready for review August 5, 2024 22:06
@cathteng cathteng requested review from a team as code owners August 5, 2024 22:06
@cathteng cathteng requested a review from a team August 5, 2024 22:42
]
pr_file_issues.sort(key=lambda k: k.get("event_count", 0), reverse=True)

return Response(pr_file_issues)
Copy link
Member

Choose a reason for hiding this comment

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

nit - if the end goal is for others to use this api, i would use a serializer here to return to make life less painful when ur documenting the endpoint. or u can just kick the can when u get there.

Copy link
Member

Choose a reason for hiding this comment

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

Use a serializer everywhere actually even if it's not going to be publicly documented. It's more typed and readable.

@iamrajjoshi iamrajjoshi requested a review from a team August 5, 2024 22:52
@getsantry
Copy link
Contributor

getsantry bot commented Aug 27, 2024

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

]
pr_file_issues.sort(key=lambda k: k.get("event_count", 0), reverse=True)

return Response(pr_file_issues)
Copy link
Member

Choose a reason for hiding this comment

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

Use a serializer everywhere actually even if it's not going to be publicly documented. It's more typed and readable.

)


class PullRequestFileSerializer(serializers.Serializer):
Copy link
Member

Choose a reason for hiding this comment

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

How is this gets related to a PR? Is it by patch? Or I can pass any file and get issues for it regardless of PR?

return value

def validate_limit(self, value):
if value and value < 1 or value > 100:
Copy link
Member

Choose a reason for hiding this comment

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

Should be if value is not None? It looks like this won't raise an error on an int value of 0.

Also, nit: value < 1 or value > 100 can be written as not (1 <= value <= 100).

org_id=organization.id, repo_name=repo_name, pr_filename=filename
)

if not len(projects) or not len(sentry_filenames):
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: empty collections are falsy, so you don't need len. Just if not projects or not sentry_filenames will work.

I'd also consider writing if not (projects and sentry_filenames), but that's a matter of taste.

group_id_to_info = {}
for issue in top_issues:
group_id = issue["group_id"]
group_id_to_info[group_id] = dict(filter(lambda k: k[0] != "group_id", issue.items()))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
group_id_to_info[group_id] = dict(filter(lambda k: k[0] != "group_id", issue.items()))
group_id_to_info[group_id] = {k: v for (k, v) in issue.items() if k != "group_id"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants