The first link gives a redirection to the second one:
curl --head https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
HTTP/1.1 302 Found
Location: https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
...
How is the filename altered by the browsers when I directly click the source code link?
The filename is defined via a custom Content-Disposition HTTP header:
curl --head https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
HTTP/1.1 200 OK
Content-Disposition: attachment; filename=nfql-0.7.tar.gz
...
So you can use curl's -O, --remote-name, -L, --location and -J, --remote-header-name to (resp.) write output to a file named as the remote file, follow redirects and use the header-provided filename:
curl -LOJ https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
Answer from deltheil on Stack OverflowVideos
The first link gives a redirection to the second one:
curl --head https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
HTTP/1.1 302 Found
Location: https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
...
How is the filename altered by the browsers when I directly click the source code link?
The filename is defined via a custom Content-Disposition HTTP header:
curl --head https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
HTTP/1.1 200 OK
Content-Disposition: attachment; filename=nfql-0.7.tar.gz
...
So you can use curl's -O, --remote-name, -L, --location and -J, --remote-header-name to (resp.) write output to a file named as the remote file, follow redirects and use the header-provided filename:
curl -LOJ https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
Not sure if this worked when the question was originally posted, but now you can use https://github.com/vbajpai/nfql/archive/v0.7/nfql-0.7.tar.gz to get the correct filename directly without looking at headers. This is very nice when using wget as you need no flags, just simply wget https://github.com/vbajpai/nfql/archive/v0.7/nfql-0.7.tar.gz
Note that it is the next-to-last path component that selects the release to use - you can put whatever filename you want to have as the last path component.
You can control the contents of sourcecode archive within automatic generation using the .gitattributes file (and make it part of your repository).
Add lines like:
src export-ignore
to exclude the directory "src" from being part of the generated source package. Internally github uses "git archive" to create packages based on the tags - and "git archive" can be controlled via ".gitattributes".
Don't know whether you can avoid generating the source package completely - but this is at least a workaround to control the contents of the source code package
To create a new release and upload additional binaries, you can :
- create the release using
POST /repos/:username/:repo/releasesand store theupload_urlfield from the response - upload your asset using
POST $upload_urlwith additional parametersnameand optionallabel(refer to this)
A quick example using bash, curl and jq (JSON parser) :
#!/bin/bash
token=YOUR_TOKEN
repo=username/your-repo
upload_url=$(curl -s -H "Authorization: token $token" \
-d '{"tag_name": "test", "name":"release-0.0.1","body":"this is a test release"}' \
"https://api.github.com/repos/$repo/releases" | jq -r '.upload_url')
upload_url="${upload_url%\{*}"
echo "uploading asset to release to url : $upload_url"
curl -s -H "Authorization: token $token" \
-H "Content-Type: application/zip" \
--data-binary @test.zip \
"$upload_url?name=test.zip&label=some-binary.zip"