diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a448ff1a4a585415078006ccaed6ba79a95d9901..86d2fdee21ae1c220b2297893287d9b49138e2ae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,7 @@ variables: stages: - logs + - new_branch - test - synchronization @@ -173,3 +174,17 @@ logs: - BODY="{\"issue\":{\"notes\":\"$NOTE\",\"private_notes\":false}}" - echo "$BODY" - curl -v -H 'Content-Type:application/json' -H "X-Redmine-API-Key:$REDMINE_API_KEY" -d "$BODY" -X PUT https://forge.maarch.org/issues/$ISSUE_ID.json + +new_branch: + image: debian:10-slim + stage: new_branch + only: + - branches + before_script: + # Install git and curl command + - apt-get update -yqq > /dev/null + - apt install -y curl + - apt install -y jq + script: + - chmod +x ./ci/create_mr.sh + - ./ci/create_mr.sh diff --git a/ci/create_mr.sh b/ci/create_mr.sh new file mode 100644 index 0000000000000000000000000000000000000000..d16101b9fb532ba88b90c43e4e436af626811f84 --- /dev/null +++ b/ci/create_mr.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +structures=$(echo $CI_COMMIT_REF_NAME | tr "/" "\n") + +TRACKER="" + +US="" + +BRANCH="" + +IT=1 +for item in $structures +do + if [ $IT = 1 ]; then + TRACKER=$item + fi + + if [ $IT = 2 ]; then + US=$item + fi + + if [ $IT = 3 ]; then + BRANCH=$item + fi + + IT=$((IT+1)) +done + + +if [[ -z $TRACKER ]] || [[ -z $US ]] || [[ -z $BRANCH ]] +then + echo "Bad structure to find US ! => [TRACKER]/[US_ID]/[TARGET_BRANCH]" +else + + echo $TRACKER + echo $US + echo $BRANCH + + echo "GET https://forge.maarch.org/issues/$US.json" + + curl -H "X-Redmine-API-Key: ${REDMINE_API_KEY}" -H 'Content-Type: application/json' -X GET https://forge.maarch.org/issues/$US.json > issue_$US.json + + SUBJECT=`cat issue_$US.json | jq -r '.issue.subject'` + + BODY="{\"id\":\"$CI_PROJECT_ID\",\"source_branch\":\"$CI_COMMIT_REF_NAME\",\"target_branch\":\"$BRANCH\",\"title\":\"WIP:$CI_COMMIT_REF_NAME\",\"description\":\"$SUBJECT\n=> https://forge.maarch.org/issues/$US\",\"remove_source_branch\":\"true\"}" + + echo $BODY + + echo "POST https://labs.maarch.org/api/v4/projects/$CI_PROJECT_ID/merge_requests" + + curl -v -H "PRIVATE-TOKEN: $TOKEN_GITLAB" -H "Content-Type: application/json" -X POST -d "$BODY" "https://labs.maarch.org/api/v4/projects/$CI_PROJECT_ID/merge_requests" +fi \ No newline at end of file