Commit a59582f2 authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

initial

parent 421ee2e3
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
/.gitlab-ci.yml
/.hadolint.yaml
/README.md

.gitlab-ci.yml

0 → 100644
+0 −0

Empty file added.

.hadolint.yaml

0 → 100644
+2 −0
Original line number Diff line number Diff line
ignored:
  - DL3008

Dockerfile

0 → 100644
+9 −0
Original line number Diff line number Diff line
FROM registry.cyberbrain.pw/docker/alpine:latest

RUN set -ex && \
    apk --no-cache add bash curl jq && \
    rm -rf /var/cache/apk/*

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "bash", "/entrypoint.sh" ]

entrypoint.sh

0 → 100644
+48 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash

# To/Die/For =)
unset TO_DIE
die() {
    RED='\033[0;31m'
    NC='\033[0m' # No Color
    echo -e "${RED}$1${NC}"
    TO_DIE=1
}
##########################################################################################################################

test -z "${CI_API_V4_URL}" && die "CI_API_V4_URL is missing"
test -z "${CI_PROJECT_ID}" && die "CI_PROJECT_ID is missing"
test -z "${CI_COMMIT_REF_NAME}" && die "CI_COMMIT_REF_NAME is missing"
test -z "${TARGET_BRANCH}" && die "TARGET_BRANCH is missing"
test -z "${PRIVATE_TOKEN}" && die "PRIVATE_TOKEN is missing"

##########################################################################################################################
test -n "${TO_DIE}" && exit 1
##########################################################################################################################

# Extract the host where the server is running, and add the URL to the APIs
HOST="${CI_API_V4_URL}/projects/"

# Look which is the default branch
TARGET_BRANCH=`curl --silent "${HOST}${CI_PROJECT_ID}" --header "PRIVATE-TOKEN:${PRIVATE_TOKEN}" | jq .default_branch`

# Require a list of all the merge request and take a look if there is already
# one with the same source branch
LISTMR=`curl --silent "${HOST}${CI_PROJECT_ID}/merge_requests?state=opened" --header "PRIVATE-TOKEN:${PRIVATE_TOKEN}"`
COUNTBRANCHES=`echo ${LISTMR} | grep -o "\"source_branch\":\"${CI_COMMIT_REF_NAME}\"" | wc -l`

# No MR found, let's create a new one
if [ ${COUNTBRANCHES} -eq "0" ]; then
    curl -X POST "${HOST}${CI_PROJECT_ID}/merge_requests" \
        --header "PRIVATE-TOKEN:${PRIVATE_TOKEN}" \
        --form "id=${CI_PROJECT_ID}" \
        --form "source_branch=${CI_COMMIT_REF_NAME}" \
        --form "target_branch=${TARGET_BRANCH}" \
        --form "title=\"WIP: ${CI_COMMIT_REF_NAME}\"" \
        --form "remove_source_branch=true"

    echo "Opened a new merge request: WIP: ${CI_COMMIT_REF_NAME}"
    exit
fi

echo "No new merge request opened"