WIP: Adds requirements that supports anything in sha params
What does this MR do?
Fix the 404 error in API when the branch has a dot in its name as stated in #26561 (moved) and in #2709 (moved).
Why was this MR needed?
Since we use Grape gem, every param we define for a given endpoint is restricted to a default format. This default format does not allow dots in value, so whenever we have a :sha
param we are going to explicitly allow any kind of text for it to work. This has been already done for some endpoints, so I just replicated the strategy for the other cases.
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added -
Tests added for this feature/bug - Review
-
Has been reviewed by UX -
Has been reviewed by Frontend -
Has been reviewed by Backend -
Has been reviewed by Database
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Squashed related commits together
What are the relevant issue numbers?
Closes #26561 (moved), #2709 (moved)
Merge request reports
Activity
mentioned in issue #26561 (moved)
marked the checklist item Changelog entry added, if necessary as completed
mentioned in issue #2709 (moved)
@gvieira37 Thanks for the contribution
🙂 added Community Contribution Platform api repository labels
- Resolved by username-removed-1616781
@markglenfletcher Do you think this can be merged or should I do anything else?
@godfat Please can you review it?
@gvieira37 Well done, looks good to me. On the other hand, what do you think about that we also add a similar test for v4 (current) API, like the one for
spec/requests/api/v3/repositories_spec.rb
? I guess it's fine not testing all the routes you touched for v4 for now, but let's at least add something for v4?assigned to @gvieira37
@godfat Sure! I'm gonna take a look on this tests for v4. Thanks for reviewing.
@godfat Sorry for my late response. I took a look and I found out that this "filepath" API was moved to files API (
lib/api/files.rb
) in V4 and we have similar tests for this cases inspec/requests/api/files_spec.rb
. Of course things have changed, but I believe it covers everything V3 spec does. WDYT?69 69 params do 70 70 requires :sha, type: String, desc: 'The commit, branch name, or tag name' 71 71 end 72 get ':id/repository/blobs/:sha' do 72 get ':id/repository/blobs/:sha', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do @godfat I followed the
assign_blob_vars!
and it feels like maybe it can be a ref name as well. Also, I did some tests and it actually works with a tag name, even that it is not actually correct to assign a tag to a blob sha. Also, even the params definition a few lines above and the docs says it has to be "The commit or branch name ". Anyway, it feels wrong to me, so I think I'm gonna remove the requirement I added and fix de docs. Does it still makes sense for you?
21 21 optional :all, type: String, desc: 'Show all statuses, default: false' 22 22 use :pagination 23 23 end 24 get ':id/repository/commits/:sha/statuses' do 24 get ':id/repository/commits/:sha/statuses', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do @gvieira37 You're right, I think we don't need more tests for v4, however after some investigation, I also realized that we don't need to change some API for v4, as they're really just for SHA. Let's remove them then.
@godfat Nice. At first, I thought
sha
could only be hexa, but then I found some places wheresha
could also be a branch or tag name. So I assumed this was right. Anyway, I'll take care of this. Thank you again for reviewing it and helping me not mess with the code.@gvieira37 Yeah, we're not very consistent here yet. Thank you for checking all the possible places we should also fix, that's really nice.
@godfat No problem at all. I know this can be hard sometimes. I was looking at git ref-parse docs and found out they refer to this args that allow anything as
rev
. If you would like, I can rename does places where this is accepted fromsha
torev
. Of course this is not gonna make any difference to the API user, but can avoid conflicts in the future. If that is the case, maybe it would be better to make this in another MR, so the change can be as small as possible.@gvieira37 Yes, let's separate the changes so that it's easier to review (and easier to revert if needed). On the other hand, it's not just doc, some of them are API parameters, so we can't just change them. We also need to make sure they're backward compatible, for example.
@godfat Sure. I'm gonna be careful with this. Thank you for the hint.