core.js
core.js copied to clipboard
Oktokit zipball download not including .git file in zip
I tried to download github repository zip file with oktokit/core like this but not getting .git file in folder when extract the files!
const response = await octokit.request('GET /repos/${repoFullName}/zipball', {
owner: owner,
repo: repoName,
ref: 'main',
})
Is this expected behavior or bug?
"@octokit/core": "^4.0.4",
👋🏻 Thanks for reaching out! This API just gives you the repository contents for a particular ref
(e.g. branch, tag or commit), and doesn't include the whole Git history (etc.) in the .git
directory. If you want to have all of that, your best bet is to clone the repo with Git itself.
Out of interest, why do you want the .git
directory?
@timrogers thanks for reply. We are developing a platform where you can import code from github so we need a copy of the whole repo in user's virtual machine. In that case user need git info to commit and update the repo with github after some modification. Is there any other way to download whole repo other than using git clone
command ?
There isn't, as far as I know, any way to download a repo from the API including all of the history in the .git
.
You should be able to clone with Git using an API access token, e.g. git clone [email protected]/octokit/octokit.rb.git
. Would that work for you?
Since this clone command happens within the code in node.js I have to spawn a shell to execute git clone command which we trying to avoid. I know git clone command works but it's slower than downloading whole repo.
Hey @SohelKabir, You might need to try the artifact endpoint as the download an archive endpoint will only create an archive, much like it does with the release, at a given :ref
and will contain no actual history.
Though I have not implemented it myself, I have a suggestion that might work. There are a few gymnastics involved with using this ( the idea is based on the result of an action
).
A possible workflow for this would be:
- For the given repo you have an action that generates an archive of the git command
git clone
- In your app you list the artifacts for the name of the action
- You then make an HTTP request using the value from the
archive_download_url
field in the response body.
Note this requires the actions scope on whatever auth token you have to be able to download the archive.
We typically do not have APIs that reproduce the behavior of git. This is because our APIs are trying to extend our platform, not git itself. I hope this helps.