tmcgilchrist / ocaml-gitlab

Native OCaml bindings to Gitlab REST API v4
https://tmcgilchrist.github.io/ocaml-gitlab/gitlab/
BSD 3-Clause "New" or "Revised" License
27 stars 8 forks source link

Add rudimentary parser for Git config files #50

Closed OlivierNicole closed 2 years ago

OlivierNicole commented 2 years ago

Parsing .git/config should be useful to get the remote URLs, and hence the project name in Gitlab (the project name, or its ID, is needed to perform project-related requests to the API).

Is it a nice parser? No. Does it already exist elsewhere in a better version? Probably, although I couldn't find it. Git config files seem to be a form of INI files.

For now, nested sections are not supported properly. (They will parse, but the result will not be a hierarchy of sections.)

OlivierNicole commented 2 years ago

I implemented @maiste's suggestions, and implemented utility functions to find .git/config and read the project name from it.

OlivierNicole commented 2 years ago

Things are probably still a bit brittle, there may be corner cases in the parser or in the project name extractor that I didn't consider, but I think it can be a decent start.

tmcgilchrist commented 2 years ago

Thanks @OlivierNicole I'll merge this and people can create PRs for the various commands that should use this to guess the right project to use.