Page History

Managing GitBucket

Mark George edited this page on 4 Jun 2020

Clone this wiki locally

OUT OF DATE

Much of this is now out of date since the newer version of GitBucket that we have can now be almost entirely driven via the REST API. Leaving as-is until I get around to documenting how to use the REST API.

Creating users via the database

  1. Log in to GitBucket using an admin account.
  2. Open the H2 Console via the Administration page.
  3. Figure out what the JDBC URL is. Looking at the GITBUCKET_HOME setting in the System Settings will show you the parent folder. Append /data to that folder for the database name. Staff server is: jdbc:h2:/home/git/data/data;IFEXISTS=TRUE INFO323 student server is: jdbc:h2:/home/git-info323/data-info323/data;IFEXISTS=TRUE INFO221 student server is: jdbc:h2:/home/git-info221/data-info221/data;IFEXISTS=TRUE
  4. Both username and password are sa.
  5. Generate some passwords using https://www.random.org/passwords/
  6. Convert passwords to SHA1 hashes. The following zsh one-liner does this:
    for p (`cat passwords.txt`); do echo -n $p | sha1sum; done;
    for a CSV :
    for p (`cat data.csv | cut -d ',' -f5`); do echo -n $p | sha1sum; done
    For TSV:
    for p (`cat data.tsv | cut -f4`); do echo -n $p | sha1sum; done
  7. Generate insert statements that look like

    insert into account
     (user_name, mail_address, password, administrator, registered_date, updated_date, group_account, full_name, removed)
    values
     ('username', 'email@address', 'SHA1 hashed password', FALSE, now(), now(), FALSE, 'full name', FALSE);
  8. Make sure you keep the original passwords since you need to give those to the users.

Creating groups via the database

If you are dealing with a small number of groups, then do it via the web interface. Otherwise:

  1. Create an account using a similar insert statement as above, but set an empty string for the password, and set the group_account field to true.
  2. Add group memberships by adding to the group_member table using insert statements that look like:
    insert into group_member (group_name, user_name, manager)
    values ('group name from account table', 'username from account table', false);

Making use of groups

Groups are useful for organising repositories, but can also be used to simplify access to a shared repository.

For a new repository

Make sure that you select the group in the drop down on the left when creating it. All members of the group will automatically get access.

For existing repositories owned by a single user

You can transfer ownership to a group account using the Danger Zone option in the repository's settings.

Downloading a bunch of repositories

I.e. downloading student submissions

SQL

select user_name, repository_name,last_activity_date 
from repository order by user_name ,last_activity_date desc

Regex

(.*)\t(.*)

Format string to turn result into GitBucket URIs

http://isgb.otago.ac.nz:8081/info323/git/$1/$2.git

Script for cloning

#IFS is field separator used by 'for', so spaces will cause issues if IFS is left at default (thanks Chris).

IFS="
"

for line  in `cat repos.txt` ;
do
    student=`echo $line | cut -d ' ' -f 1`
    repo=`echo $line | cut -d ' ' -f 2`

    echo Student: $student  Repo: $repo
    
    mkdir $student
    cd $student
    
    git clone $repo
    
    cd -
done

Creating repositories using curl

  1. Users must already exist in the database, so create those first if needed.
  2. Log in to GitBucket via a web browser with an administrator account.
  3. Get the JSESSIONID cookie value from the browser. This needs to be passed in the curl requests as the authentication token.
  4. Use curl as follows to create the repositories:
    curl  \
    --cookie JSESSIONID=$sessionid \
    --request POST \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data "owner=$owner&name=$repo_name&description=$repo_description&isPrivate=true&createReadme=on" \
    --url http://gitbucketserver.wherever.com:8080/new
    Omit the createReadme=on part completely if you don't want a README.md created.