Repository navigation
Conversation
Dependency funding tools need the donation links for a repository they have already resolved. GitHub keeps them in FUNDING.yml, and looks for it in .github/, the root, docs/ and then the owner's .github repository; this package does the same walk through FileService and returns the platform handles and custom URLs. Parse is callable on supplied content, so a consumer that already has the file does not need a FileService. The parser covers the flat subset GitHub accepts (scalars, quoted values, inline and block lists, comments) and ignores keys it does not know, so a file using a platform added later still parses. Closes git-pkgs#174
andrew
left a comment
There was a problem hiding this comment.
Thanks for picking this up. Discovery order and the mocked FileService tests match the issue. The parser is the main problem.
The hand-written parser rejects valid FUNDING.yml files, and Discover then returns an error for the whole repo:
- An unknown key with a block list (
new_platform:\n - a\n - b) fails with "list item outside a list key", becauseParseclearspendingfor every key and then skips unknown ones. That contradicts the goal of still parsing files that use a platform added later. - A flow list split across lines (
custom: ["https://a.example",then"https://b.example"]) fails inparseInlineListwith "unterminated list".
GitHub reads the file as YAML, so please replace Parse's hand-written parser with go.yaml.in/yaml/v3, unmarshalling into a struct. github and custom accept either a single string or a list, so they need a small type with UnmarshalYAML that handles both. The module also builds under TinyGo, so the tinygo CI job has to stay green. Keep the table tests and add cases for the two shapes above. That also removes stripComment, parseInlineList, unquote, the flush closure and the long Parse doc comment.
Smaller things:
Links.URLnever uses its receiver. Make itfunc URL(platform, handle string) stringbefore it becomes public API, and addotechietoTestURL.Locationis exported, but nothing public takes or returns it. Rename itlocation.- The
HTTPError404 branch inisMissingcan't be reached. Every backend already maps a 404 toErrNotFound(github/files.go,gitlab/files.go,gitea/errors.go). Drop it, thenet/httpimport, and the second half ofTestDiscoverReturnsOtherErrors. - Cut the doc comments down to a line or two. The
Discovercomment is 12 lines, theLinkscomment about field names vs button labels can go, and thelocationscomment repeats whatDiscoversays about stopping at the first file.
Adds the
fundingsubpackage from the issue:Discoverwalks where GitHub looks for aFUNDING.yml—.github/, the root,docs/, then the owner's.githubrepository — throughFileService, andParsereads the same file from bytes for a caller that already has it.Details worth knowing:
content, decides which file GitHub reads.
.githubrepository is read from its own default branch — a tag or branch name fromthe repository being asked about does not exist there.
ErrNotFoundandErrNotSupportedare both "nothing to read" (Tangled and Bitbucket answerErrNotSupportedfor everyFiles().Get); any other error is returned wrapped.lists, comments, a leading BOM, a
---marker, CRLF — and ignores unknown keys so a file using aplatform added later still parses.
Discovery is covered with a mocked
FileService(the location order, the ref it sends, the errorcases); the parser has table tests for the shapes above and for the four it rejects.
go build ./...,go vet ./...,golangci-lint run ./funding/(0 issues) andgo test ./funding/are clean. Four
internal/clitests fail on this machine both with and without the change: theyresolve the git remote before parsing the argument, and this clone's remote is an SSH alias.
Closes #174