-
Notifications
You must be signed in to change notification settings - Fork 61
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
Unable to PUT to the file pertaining to a specific branch despite providing it in the path #461
Comments
Hi @subramani-r-0595, Could you share a more complete snippet of code, the Octokit version you are using and the response you are obtaining? Thanks |
I have a similar question. Are query params supposed to be supported? There's no documentation for it on octokit (as far as I can tell), but I believe this is how the GitHub's API works for specifying a branch. |
Parameters you set to a
Sends a For other request methods such as await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', {
owner: 'octokit',
repo: 'request.js',
release_id: 1234,
name: "my-release-asset.text",
data: "lorem ipsum"
}) For the case of updating a file, all parameters are expected to be passed as URL path and body parameters, none as URL query parameters, see documentation. The Could you share a snippet of code that is not behaving as expected? Does it work when you use |
In my case I'm doing a GET and was just surprised by the lack of documentation. When doing a search I landed here. I've not tried it yet, but if it is supported it should probably be documented |
Yeah, the documentation is ... lacking. The gist is you can take any of GItHub's REST API endpoint documented at https://docs.github.com/en/rest/, pass the route as first argument, and the parameters as second, independent of how they are transported. If you want to use Octokit, you'll probably also want to use the all-batteries included library at https://github.com/octokit/octokit.js. If bundle size is a concern, use https://github.com/octokit/core.js. If you have any more questions / would like to discuss your use case, you know how to reach me 👋🏼 |
Thanks! I'll give it a shot and report back whether I have any issues. |
That worked great. Thanks a bunch! Here's the code I'm using it in for others who want a reference (no pun intended): async function downloadFile(path: string) {
const {data} = (await octokit.request(
`GET /repos/{owner}/{repo}/contents/{path}`,
{
owner: 'kentcdodds',
repo: 'kentcdodds.com',
path,
ref,
},
)) as {data: {content?: string; encoding?: string}}
if (!data.content || !data.encoding) {
console.error(data)
throw new Error(
`Tried to get ${path} but got back something that was unexpected. It doesn't have a content or encoding property`,
)
}
// lol
const encoding = data.encoding as Parameters<typeof Buffer.from>['1']
return Buffer.from(data.content, encoding).toString()
} |
It's odd that you need to type the response.
See my TypeScript playground here I really should finally encapsulate the "get file contents" use case into a re-usable plugin, because this endpoint really is pain. I created one to create/update a file: https://github.com/octokit/plugin-create-or-update-text-file.js#readme Lastly, if the repository from which you download the files is public and you are worried about rate limiting, you can download static filed data from, you can download it from https://raw.githubusercontent.com which is not rate limited , e.g. https://raw.githubusercontent.com/octokit/core.js/master/README.md |
Thanks for the tips @gr2m! |
octokit.request(
PUT /repos/looker-bi-eng/gcsc_intel_auto_prod/contents/intl_ppc/views/inline_table.view.lkml?ref=dev-subramani-ravichandran-cxzc
, {.....Although, I am passing the branch name in the ref parameter, the request is being redirected the file on the master branch. Can you help?
The text was updated successfully, but these errors were encountered: