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: Add author filter option for [GithubCommitActivity] #9251

Merged
merged 14 commits into from
Jun 15, 2023

Conversation

jNullj
Copy link
Collaborator

@jNullj jNullj commented Jun 10, 2023

Add a new filter option to [GithubCommitActivity], allowing users to filter the commit activity by a specific author.

To make the filter more explicit, The label display "commits by [author]" for the total amount of commits and "commit activity by [author]" for other intervals when an author filter is selected.

To maintain a clear and organized code structure, The filtered author is added as an argument and not to the shield path.

The request to find the number of commits by the author is made using the REST api rather then the GraphQL api to make it in 1 request rather then 2.

Resolves #9215

@github-actions
Copy link
Contributor

github-actions bot commented Jun 10, 2023

Messages
📖 ✨ Thanks for your contribution to Shields, @jNullj!

Generated by 🚫 dangerJS against 713374a

@jNullj jNullj force-pushed the feat/9215/commit-activity-author-filter branch 3 times, most recently from 6cac096 to a932b25 Compare June 10, 2023 20:40
Add a new filter option to [GithubCommitActivity], allowing users to filter the commit activity by a specific author.

To make the filter more explicit, The label display "commits by [author]" for the total amount of commits and "commit activity by [author]" for other intervals when an author filter is selected.

To maintain a clear and organized code structure, The filtered author is added as an argument and not to the shield path.

The request to find the number of commits by the author is made using the REST api rather then the GraphQL api to make it in 1 request rather then 2.

Resolves badges#9215
Add tests for the new filter by author feature.
Add test for new transformAuthorFilter function of GithubCommitActivity added for the author filter feature.
@jNullj jNullj force-pushed the feat/9215/commit-activity-author-filter branch from a932b25 to ab006fc Compare June 10, 2023 20:48
@jNullj jNullj marked this pull request as ready for review June 10, 2023 20:52
@jNullj
Copy link
Collaborator Author

jNullj commented Jun 10, 2023

I am ready for a review! Hope i got some quality on first attempt.

@jNullj
Copy link
Collaborator Author

jNullj commented Jun 10, 2023

Just to make it a bit nicer to see behavior before running this, here is a short video of how it looks like on my testing env. (note, i used node 20)

test_author_filter1.mp4

@github-actions
Copy link
Contributor

🚀 Updated review app: https://pr-9251-badges-shields.fly.dev

@@ -31,6 +41,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
// Override the pattern to omit the deprecated interval "4w".
pattern: ':interval(t|y|m|w)/:user/:repo',
namedParams: { interval: 'm', user: 'eslint', repo: 'eslint' },
queryParams: { authorFilter: 'chris48s' },
Copy link
Member

Choose a reason for hiding this comment

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

Just to make the example "make sense", can we pick a username of someone who has made one or more commits to the example repos. e.g: for eslint/eslint, nzakas would make more sense as an example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will pick one of the users for the example, no problem

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Could we do the same on the other example (pick an author who has contributed to the repo)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure

Comment on lines 156 to 158
if (buffer.message === 'Not Found') {
throw new InvalidResponse({ prettyMessage: 'invalid branch' })
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever hit this line?
If I call something like /github/commit-activity/t/badges/shields/does-not-exist?authorFilter=chris48s it tells me "repo not found". If we can't distinguish between branch not found and repo not found then we can just make the other error "repo or branch not found" (this is quite common).

While I was testing this, I also noticed that the branch not found case doesn't seem to be hanled correctly. It is not new in this PR (already exists in prod https://shields.io/github/commit-activity/t/badges/shields/does-not-exist ), but if you have a chance to look at it while you are looking at this, that would be amazing.

Given neither of these work but the spec tests pass, I'd suggest we move the "branch not found" test cases out to the service tests layer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made api calls with both unexisting repo and branch, and i could not find any way to seperate the two, they both reply with 404 same content/headers, thats why this code will never activate.
I will change the error into "repo or branch not found" as suggested.
You are currect as well about the interval='t' not being used, should i remove it with this PR? it would mix into the commit when squashed, which i think would be undesireable... Should be a mistake from #9196 .
Used it becouse the call from the GraphQL api also used this, but it appears that even the GraphQL code is never used.
I also tested the GraphQL requests, seems like you can seperate wrong branch and wrong repository, altho i am not sure if we want to do that. Wrong repo will return an error object which is used, while bad branch returns a null repo object without erros.
I think thats the reason the transform function tests if (!repo). but the _requestGraphql function cataches this in validation as it differ from schema, which require object inside repo and it gets null.
I could fix that, but i think it needs it's own issue to keep this commit clean when we merge, if so let me know and i will open this issue, and i could offer my fix there.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I am not following. What do you mean when you say

You are correct as well about the interval='t' not being used

?

This behaves the same way if I call https://shields.io/github/commit-activity/m/badges/shields/does-not-exist

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My bad, there is no diffrence, no idea how i mixed this in my reply. I edited the reply as i was debugging.
Should have read it twice before posting.

Copy link
Member

Choose a reason for hiding this comment

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

Could we add a couple of test cases to the service tests file (.tester.js) covering invalid branch (for both the GraphQL and Rest paths).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I separated the GraphQL test and fixed the error handling in PR #9258 as this is not related directly to this change, i think its better for history.
I will add another test for the REST path in this PR

@chris48s chris48s added the service-badge Accepted and actionable changes, features, and bugs label Jun 12, 2023
@jNullj jNullj marked this pull request as draft June 13, 2023 21:39
jNullj and others added 7 commits June 14, 2023 20:26
The author filter error handling removed was redundent as it would never execute, there is no way to seperate branch not found from repo not found.
PR badges#9233 replaced errorsMessages with httpErrors.
This commit updates the new changes to stay up to date with that PR
this exception was removed in commit 9e358c8 and is not needed anymore
@jNullj jNullj marked this pull request as ready for review June 14, 2023 18:33
@jNullj jNullj requested a review from chris48s June 14, 2023 18:33
Picked a user with commits in the repo as an example that would work
Add test for REST API calls in commit activity branch
@chris48s
Copy link
Member

I've merged #9258 Can you sort out the merge conflict.

I suspect once that conflict is resolved, that will be the last thing and this will be ready to merge too, but I'll give it another quick read over tomorrow.

Cheers

@github-actions
Copy link
Contributor

🚀 Updated review app: https://pr-9251-badges-shields.fly.dev

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thanks

@chris48s chris48s merged commit 67d9354 into badges:master Jun 15, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New filter option for CommitActivity
2 participants