Skip to content

Instantly share code, notes, and snippets.

@Snger
Forked from JonasGroeger/sync-projects
Created July 13, 2019 12:09
Show Gist options
  • Save Snger/62ff1bfb3f8dfdf5da0ec852394909fd to your computer and use it in GitHub Desktop.
Save Snger/62ff1bfb3f8dfdf5da0ec852394909fd to your computer and use it in GitHub Desktop.

Revisions

  1. @JonasGroeger JonasGroeger revised this gist Dec 19, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sync-projects
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ fi

    FILENAME="repos.json"

    trap "{ rm -f $FILENAME; exit 255; }" EXIT
    trap "{ rm -f $FILENAME; }" EXIT

    curl -s "${BASE_PATH}api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM&per_page=999" \
    | jq --raw-output --compact-output ".[] | $PROJECT_SELECTION | $PROJECT_PROJECTION" > "$FILENAME"
    @@ -35,4 +35,4 @@ while read repo; do
    fi
    done < "$FILENAME"

    wait
    wait
  2. @JonasGroeger JonasGroeger revised this gist Dec 19, 2016. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions sync-projects
    Original file line number Diff line number Diff line change
    @@ -28,9 +28,11 @@ while read repo; do

    if [ ! -d "$THEPATH" ]; then
    echo "Cloning $THEPATH ( $GIT )"
    (git clone "$GIT" --quiet)
    git clone "$GIT" --quiet &
    else
    echo "Pulling $THEPATH"
    (cd "$THEPATH" && git pull --quiet)
    (cd "$THEPATH" && git pull --quiet) &
    fi
    done < "$FILENAME"

    wait
  3. @JonasGroeger JonasGroeger revised this gist Dec 19, 2016. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions sync-projects
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    NAMESPACE="YOUR_NAMESPACE"
    BASE_PATH="https://gitlab.example.com/"
    PROJECT_SEARCH_PARAM=""
    PROJECT_SELECTION="select(.namespace.name == \"$NAMESPACE\")"
    PROJECT_PROJECTION="{ "path": .path, "git": .ssh_url_to_repo }"

    if [ -z "$GITLAB_PRIVATE_TOKEN" ]; then
    echo "Please set the environment variable GITLAB_PRIVATE_TOKEN"
    @@ -15,8 +17,10 @@ fi

    FILENAME="repos.json"

    trap "{ rm -f $FILENAME; exit 255; }" EXIT

    curl -s "${BASE_PATH}api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM&per_page=999" \
    | jq --raw-output --compact-output ".[] | select(.namespace.name == \"$NAMESPACE\") | { "path": .path, "git": .ssh_url_to_repo }" > "$FILENAME"
    | jq --raw-output --compact-output ".[] | $PROJECT_SELECTION | $PROJECT_PROJECTION" > "$FILENAME"

    while read repo; do
    THEPATH=$(echo "$repo" | jq -r ".path")
    @@ -30,5 +34,3 @@ while read repo; do
    (cd "$THEPATH" && git pull --quiet)
    fi
    done < "$FILENAME"

    rm "$FILENAME"
  4. @JonasGroeger JonasGroeger revised this gist Dec 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sync-projects
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    NAMESPACE="YOUR_NAMESPACE"
    BASE_PATH="https://gitlab.example.com/"
    PROJECT_SEARCH_PARAM="YOUR_SEARCH_PARAM"
    PROJECT_SEARCH_PARAM=""

    if [ -z "$GITLAB_PRIVATE_TOKEN" ]; then
    echo "Please set the environment variable GITLAB_PRIVATE_TOKEN"
  5. @JonasGroeger JonasGroeger revised this gist Dec 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sync-projects
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ fi

    FILENAME="repos.json"

    curl -s "${BASE_PATH}api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM" \
    curl -s "${BASE_PATH}api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM&per_page=999" \
    | jq --raw-output --compact-output ".[] | select(.namespace.name == \"$NAMESPACE\") | { "path": .path, "git": .ssh_url_to_repo }" > "$FILENAME"

    while read repo; do
    @@ -24,7 +24,7 @@ while read repo; do

    if [ ! -d "$THEPATH" ]; then
    echo "Cloning $THEPATH ( $GIT )"
    git clone "$GIT" --quiet
    (git clone "$GIT" --quiet)
    else
    echo "Pulling $THEPATH"
    (cd "$THEPATH" && git pull --quiet)
  6. @JonasGroeger JonasGroeger renamed this gist Sep 28, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @JonasGroeger JonasGroeger created this gist Sep 28, 2016.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/bin/env bash

    # Documentation
    # https://docs.gitlab.com/ce/api/projects.html#list-projects

    NAMESPACE="YOUR_NAMESPACE"
    BASE_PATH="https://gitlab.example.com/"
    PROJECT_SEARCH_PARAM="YOUR_SEARCH_PARAM"

    if [ -z "$GITLAB_PRIVATE_TOKEN" ]; then
    echo "Please set the environment variable GITLAB_PRIVATE_TOKEN"
    echo "See ${BASE_PATH}profile/account"
    exit 1
    fi

    FILENAME="repos.json"

    curl -s "${BASE_PATH}api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM" \
    | jq --raw-output --compact-output ".[] | select(.namespace.name == \"$NAMESPACE\") | { "path": .path, "git": .ssh_url_to_repo }" > "$FILENAME"

    while read repo; do
    THEPATH=$(echo "$repo" | jq -r ".path")
    GIT=$(echo "$repo" | jq -r ".git")

    if [ ! -d "$THEPATH" ]; then
    echo "Cloning $THEPATH ( $GIT )"
    git clone "$GIT" --quiet
    else
    echo "Pulling $THEPATH"
    (cd "$THEPATH" && git pull --quiet)
    fi
    done < "$FILENAME"

    rm "$FILENAME"