Difference between revisions of "Git/GitLab"
< Git
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
= GitLab - download all repositories = | |||
You can get token when log in to your account > settings and generate access token. Assign all permissions. Also so you know v3 APIs may be deployed on older version Gitlab. | |||
<source lang="bash"> | |||
#!/bin/bash | |||
# Get pages count of all repos you can access | |||
# $ curl --head "http://<host.com>/api/v4/projects?private_token=<token>=100&page=1" | grep Total | |||
# X-Total: 509 | |||
# X-Total-Pages: 6 | |||
#Create JSON file with repo name and path | |||
#for PAGE in {1..6}; do curl "<host.com>/api/v4/projects?private_token=CMQdz-Qik8XanGYJTbnH&per_page=100&page=$PAGE" | jq --raw-output --compact-output ".[] | { "path": .path, "git": .ssh_url_to_repo }" >> repos.json; done | |||
[ -d repos ] || mkdir repos | |||
cd repos | |||
while read repo; do | |||
THEPATH=$(echo "$repo" | jq -r ".path") | |||
echo "path: $THEPATH" | |||
GIT=$(echo "$repo" | jq -r ".git") | |||
echo "git: $GIT" | |||
if [ ! -d "$THEPATH" ]; then | |||
echo "Cloning $THEPATH ( $GIT )" | |||
git clone "$GIT" | |||
else | |||
echo "Pulling $THEPATH" | |||
(cd "$THEPATH" && git pull) | |||
fi | |||
done < "../$FILENAME" | |||
cd .. | |||
</source> | |||
Example repos.json | |||
<source lang="json"> | |||
{"path":"project-x","git":"git@<host.com>:Spikes/project-x.git"} | |||
{"path":"project-y","git":"git@<host.com>:Spikes/AWS/project-y.git"} | |||
</source> | |||
= Reset a user password = | = Reset a user password = | ||
This could be also ''root'' user. | This could be also ''root'' user. | ||
Line 21: | Line 61: | ||
=> false | => false | ||
</source> | </source> | ||
= Deployment token = | = Deployment token = | ||
In course to grant access to a single repository for reading, writting or both we can use feature called ''Deploy Tokens''. Go to <tt>repository > repository settings > Deploy Tokens</tt> to create one. | In course to grant access to a single repository for reading, writting or both we can use feature called ''Deploy Tokens''. Go to <tt>repository > repository settings > Deploy Tokens</tt> to create one. |
Revision as of 21:31, 30 March 2020
GitLab - download all repositories
You can get token when log in to your account > settings and generate access token. Assign all permissions. Also so you know v3 APIs may be deployed on older version Gitlab.
#!/bin/bash # Get pages count of all repos you can access # $ curl --head "http://<host.com>/api/v4/projects?private_token=<token>=100&page=1" | grep Total # X-Total: 509 # X-Total-Pages: 6 #Create JSON file with repo name and path #for PAGE in {1..6}; do curl "<host.com>/api/v4/projects?private_token=CMQdz-Qik8XanGYJTbnH&per_page=100&page=$PAGE" | jq --raw-output --compact-output ".[] | { "path": .path, "git": .ssh_url_to_repo }" >> repos.json; done [ -d repos ] || mkdir repos cd repos while read repo; do THEPATH=$(echo "$repo" | jq -r ".path") echo "path: $THEPATH" GIT=$(echo "$repo" | jq -r ".git") echo "git: $GIT" if [ ! -d "$THEPATH" ]; then echo "Cloning $THEPATH ( $GIT )" git clone "$GIT" else echo "Pulling $THEPATH" (cd "$THEPATH" && git pull) fi done < "../$FILENAME" cd ..
Example repos.json
{"path":"project-x","git":"git@<host.com>:Spikes/project-x.git"} {"path":"project-y","git":"git@<host.com>:Spikes/AWS/project-y.git"}
Reset a user password
This could be also root user.
ubuntu@gitlab:~$ sudo gitlab-rails console ------------------------------------------------------------------------------------- GitLab: 11.4.0 (6ebbd70) GitLab Shell: 8.3.3 postgresql: 9.6.8 ------------------------------------------------------------------------------------- Loading production environment (Rails 4.2.10) irb(main):001:0> user = User.find_by(username: "bob") user = User.find_by(id: 1) //by id => #<User id:5 @bob> irb(main):002:0> user.password = 'test1234' //at least 8 characters long => "test1" irb(main):003:0> user.password_confirmation = 'test1234' => "test1" irb(main):007:0> user.unlock_access! => true irb(main):008:0> user.save! => false
Deployment token
In course to grant access to a single repository for reading, writting or both we can use feature called Deploy Tokens. Go to repository > repository settings > Deploy Tokens to create one.
Access repository
# Syntax # git clone http://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git # Example git clone https://darkmatter:PLjeFh56F15yJeq8xrZv@gitlab.com/hackerrank1/apache-nginx-ssl.git Cloning into 'apache-nginx-ssl'... remote: Enumerating objects: 110, done. remote: Counting objects: 100% (110/110), done. ...
- References
- Deploy Tokens Introduced in GitLab 10.7.