This will let me get an archive from a repo:
GET /projects/:id/repository/archive.tar.gz
Is there any way to pass a parameter such that I get an archive for the latest release rather than just the HEAD?
You can get the tags of repository using the following API:
GET /projects/:id/repository/tags
As the docs describe https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags
You get a list of repository tags from a project, sorted by update date and time in descending order
In combination with the archive API
GET /projects/:id/repository/archive[.format]
We can have the latest release with the following one-liner:
curl --header "PRIVATE-TOKEN: <private token>" https://gitlab.com/api/v4/projects/<project id>/repository/archive.tar.gz?sha=$(curl -s --header "PRIVATE-TOKEN: <private token>" "https://gitlab.com/api/v4/projects/<project id>/repository/tags" | jq '.[0].commit.id' | sed 's/^"\(.*\)"$/\1/') -o /path/to/file
Related
I have some bare git repository on my filesystem where users do pull/push.
I install gitea and can't find how to add it to gitea.
Other git-management systems have something like "add repository from filesystem", "scan directory", etc. which added existing repo to system.
How to add it in gitea?
At the moment I migrate from Filesystem Repositorys to Gitea.
How this could be done is heavily discussed here (we used SSH), where I got the basis for my approach.
The following steps worked for me:
Clone the repo.git folder to another location git clone path/to/repo.git
Create an empty repo in Gitea. Either by hand or using the api
curl \
-X POST "http://localhost:3000/api/v1/user/repos" \
-H "accept: application/json" \
-H "Authorization: token MY_TOKEN*" \
-H "Content-Type: application/json" \
-d "{\"name\": \"REPO_NAME\"}" \
-i
Optionally transfer to a organization
curl \
-X POST "http://localhost:3000/api/v1/repos/CURRENT_OWNER/REPO_NAME/transfer" \
-H "accept: application/json" \
-H "Authorization: token MY_TOKEN*" \
-H "Content-Type: application/json" \
-d "{\"new_owner\": \"NEW_ORGANIZATION_OR_INDIVIDUAL\"}" \
-i
Push the repo to gitea
git remote add neworigin "http://localhost:3000/username/test.git"
git push neworigin --all
git push neworigin --tags
*https://docs.gitea.io/en-us/api-usage/
You can use the 'unadopted repositories' method (merged in 2020 with this pull request).
Locate gitea's app.ini config file and find the values of APP_NAME (the user name) and the repositories ROOT.
Let's assume your config looks like this:
APP_NAME = dinsdale
...
[repository]
ROOT = /usr/local/data/gitea-repositories
cd to $REPO/$APP_NAME which for the config above will be: /usr/local/data/gitea-repositories/dinsdale and make a bare clone from each repo on your local file system:
cd /usr/local/data/gitea-repositories/dinsdale
git clone --bare /path/to/my/local/repo1
git clone --bare /path/to/my/local/repo2
..
git clone --bare /path/to/my/local/repo42
Click your profile icon in the top right corner and select Site Administration -> tab Repositories -> click Unadopted Repositories.
Leave the search field blank, and click the Search button. The 'unadopted' orphan folders that you added will be displayed below.
For each repo click the Adopt Files button to import the orphaned repo.
💡 NOTE: You can also simply copy the repo folders to your $REPO/$APP_NAME but then you'll need to append the .git suffix to the folder name and this has the disadvantage of also including the full file tree and any untracked files/changes which might increase the disk size.
To manually convert a regular repo to a bare one see How to convert a normal Git repository to a bare one?
Issue
I am trying to use the Gitlab yaml API linting tool on an enterprise instance of Gitlab. However, I am getting an empty response (not just an empty json object, like absolutely zero output).
Steps to duplicate
I am using a stripped version of the sample .yaml file shown on the gitlab CI/CD tutorial page. The file is shown here:
build-job:
stage: build
script:
- echo "Hello, $GITLAB_USER_LOGIN!"
deploy-prod:
stage: deploy
script:
- echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
I am using the 1 line curl command as shown on the CI Linting API page.
If I use the command as given (replacing only the filename), I get
$ jq --null-input --arg yaml "$(<.gitlab-ci.yml)" '.content=$yaml' \
| curl "https://gitlab.mycompany.com/api/v4/ci/lint?include_merged_yaml=true" \
--header 'Content-Type: application/json' \
--data #-
I get the output {"message":"401 Unauthorized"}, which is to be expected as the API call requires an API key. I generate an API key in my profile and try again:
$ export TOKEN='xxxxxxxxxx'
$ jq --null-input --arg yaml "$(<.gitlab-ci.yml)" '.content=$yaml' \
| curl "https://gitlab.mycompany.com/api/v4/ci/lint?include_merged_yaml=true" \
--header "Content-Type: application/json PRIVATE-TOKEN=${TOKEN}" \
--data #-
When I run this, the output shows nothing. This is confirmed by a pipe to wc -c which outputs 0.
My expected output should be:
{
"status": "valid",
"errors": [],
"warnings": []
}
Questions:
Why is no response a result of me using my valid API key (This is with a newly generated key)?
How can I fix this, and receive the expected output shown above?
Make sure your token as the api scope, as illustrated here.
Without that scope, you would get a 401 Unauthorized, which would not be parsed parsed by jq at all.
Background
I'm looking to make backups of the code that i have hosted on gitlab. I only need the zip/tar.gz files, not the whole code history. (I have many repositories there so it wouldn't be practical to do this manually)
My OS is Ubuntu 21.04
Question
How can I download zip/tar.gz files for all my gitlab repos?
What I've found so far
I've tried using gitlabber but it turns out it only works for gitlab groups, and not personal repos (almost all my projects are personal repos). (Also gitlabber will download the whole repos, not just the tar.gz files)
I found ghorg which works with GitLab and clones all repos
ghorg clone <gitlab_username> --clone-type=user --base-url=https://<your.instance.gitlab.com> --scm=gitlab --token=XXXXXXXXXXXXX
I would still like to find a better option, which downloads the tar.gz files rather than cloning the repos. Also ghorg relies on brew which is somewhat cumbersome to install on my OS (Ubuntu). It would be better if there is a quicker/easier option
To download all your repos you could use the following script
#!/bin/bash
ACCESS_TOKEN=$1
GITLAB_URL=$2
BRANCH=$3
curl --header "PRIVATE-TOKEN: $ACCESS_TOKEN" $GITLAB_URL/api/v4/projects?owned=true | jq '.[] | "\(.id) \(.name)"' | sed 's/^"\(.*\)"$/\1/' | while read line
do
PROJECT_ID=$(echo $line | cut -d " " -f1)
PROJECT_NAME=$(echo $line | cut -d " " -f2- )
curl --header "PRIVATE-TOKEN: $ACCESS_TOKEN" "$GITLAB_URL/api/v4/projects/$PROJECT_ID/repository/archive.zip?sha=$BRANCH" -o "$PROJECT_NAME".zip
done
You pass your access token, gitlab url and the desired branch
Execution exmple:
./get_archive.sh "access_token" "https://gitlab.example.com" "master"
Output:
It will download all the code for the repos that you own in format repo1_name.zip repo2_name.zip
I've been having trouble acquiring and changing some of the basic data available from the Nest thermostat.
Using a command line, how can I get or change individual settings or values on my thermostat?
This is a compilation from several users explaining how to retrieve or change some basic information with some of my own experiences added in. Wherever I use <VALUE>, replace that with the applicable information in your setup. If you're using Windows, you'll need something like git-scm.
The following a part of the authentication process. You'll need to have a client already made on Nest's developer page and followed the provided authorization URL to get your auth code. Run this line to get an access token:
curl --data 'code=<AUTH CODE>&client_id=<CLIENT ID>&client_secret=<CLIENT SECRET>&grant_type=authorization_code' https://api.home.nest.com/oauth2/access_token
To fetch some information about the thermostats associated with the authorization code:
curl -v -L https://developer-api.nest.com/devices/thermostats?auth=<AUTH CODE>
To fetch some information about a specific thermostat:
curl -v -L https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>?auth=<AUTH CODE>
To fetch the target temperature in F from the specified thermostat. You can replace target_temperature_f with any other value listed under thermostat on Nest's API reference:
curl -v -L https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>/target_temperature_f?auth=<AUTH CODE>
To change the target_temperature_f:
curl -v -L -X PUT "https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>/target_temperature_f?auth=<AUTH CODE>" -H "Content-Type: application/json" -d "65"
To change the specific structure to away. The value here is a string so be sure to include the single quotes:
curl -v -L -X PUT "https://developer-api.nest.com/structures/<STRUCTURE ID>/away?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '"away"'
Credit for this is primarily to the following users:
thesimm, mccv, Nagesh Susarla, and David W. Keith.
I am trying to download a tarball from GitHub using cURL, but it does not seem to be redirecting:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being redirected.</body></html>
Note: wget works for me:
$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2
However I want to use cURL because ultimately I want to untar it inline with something like:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
I found that the URL after redirecting turned out to be https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz, but I would like cURL to be smart enough to figure this out.
Use the -L option to follow redirects:
curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
The modernized way of doing this is:
curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz
Replace user-or-org, repo, and sha1-or-ref accordingly.
If you want a zip file instead of a tarball, specify .zip instead of .tar.gz suffix.
You can also retrieve the archive of a private repo, by specifying -u token:x-oauth-basic option to curl. Replace token with a personal access token.
You can also use wget to »untar it inline«. Simply specify stdout as the output file (-O -):
wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2 -O - | tar xz
All the other solutions require specifying a release/version number which obviously breaks automation.
This solution- currently tested and known to work with Github API v3- however can be used programmatically to grab the LATEST release without specifying any tag or release number and un-TARs the binary to an arbitrary name you specify in switch --one-top-level="pi-ap". Just swap-out user f1linux and repo pi-ap in below example with your own details and Bob's your uncle:
curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1
with a specific dir:
cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx