-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[GitHub] Number of commits between branches/tags/commits #8394
[GitHub] Number of commits between branches/tags/commits #8394
Conversation
…for branches with slashes in their names
|
Following a discussion with @calebcartwright on Discord Caleb wrote:
|
This PR is ready to be reviewed. |
I don’t think that the recent pipeline failed because of the changes introduced in this PR (?) https://github.com/badges/shields/actions/runs/3055809500/jobs/4929284513 |
Yeah - looks like a transient issue with NPM. They should pass next time you push a commit |
I think the approach of having 2 query params is fine, and we don't need to change it. That said, while I was reading this it occurred to me that another way we could have approached this would have been to take a single string param |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. This one is a bit easier than the packagist PR 😌 Nearly all of this is already ready to go.
branchA: '1.60.0', | ||
branchB: '82f2db7', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As is often the case, the hardest job is giving things good names :)
As demonstrated by the fact that the 2 examples you've used here are a commit hash and a tag, branchA
and branchB
don't actually have to be branches. Fortunately in git there is a word for this identifier that could be a branch name, commit hash or tag name, which is "ref" (you'll also notice you can use the "special" ref names just fine here like HEAD~1
, etc if you try them).
The other thing here is that A and B aren't very descriptive either. It isn't really clear to me which one of this is expected to be the ref that is further ahead/behind. The Github API calls these params {base}...{head}
which isn't going to be completely obvious to everyone, but I think those terms are more descriptive than A and B and at least have the advantage of maintaining consistency with the terms GitHub uses. Another option is GitLab uses {from}...{to}
for these concepts..
So we could go with
base
/head
base_ref
/head_ref
from
/to
from_ref
/to_ref
(we use underscores in query params)
Personally, I have a weak preference for base
and head
just because they're the same words github uses in the API docs, but if you have a strong preference that one of the other 3 options there is more meaningful we can go with any of those. And lets make the error message "could not establish commit difference between refs"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I have a weak preference for
base
andhead
just because they're the same words github uses in the API docs, but if you have a strong preference that one of the other 3 options there is more meaningful we can go with any of those. And lets make the error message "could not establish commit difference between refs"
Why do we use underscores in query params (and not hyphens or camelCase)?
Sure, I'll rename branchA
to base
, and branchB
to head
.
The error message will read "could not establish commit difference between refs"
.
Yeah, I was also not fond of putting branch
in the URL (since users can use a couple of other options) - you're right that ref
is a great term to encompass all of the possibilities. Thanks;)
Yes, at first I wrote the solution with |
This is a good question. I can tell you that at some point we seem to have (mostly?) consistently settled on underscore for query params e.g:
Given the param names get converted to variables, it would be inconvenient to use kebab-case as |
Related to: #6901
It returns the number of commits between given branches/tags/commits.
We call under the hood:
https://api.github.com/repos/microsoft/vscode/compare/1.60.0...82f2db7
Example branches names taken from
stale branches
from:https://github.com/microsoft/vscode/branches/stale
correct - branches
http://localhost:8080/github/commits-difference/microsoft/vscode?branchA=standalone/0.1.x&branchB=release/1.21
correct - tag...commit
http://localhost:8080/github/commits-difference/microsoft/vscode?branchA=82f2db7&branchB=1.60.0
incorrect - commits
http://localhost:8080/github/commits-difference/microsoft/vscode?branchA=82f2db7&branchB=fffffff
incorrect - missing required query param
http://localhost:8080/github/commits-difference/microsoft/vscode?branchA=82f2db7