image: node:12

variables:
    PROJECT_BRANCH: master
    CI_REPOSITORY_URL: https://$USER_LOGIN:$USER_TOKEN@gitlab.com/$CI_PROJECT_PATH.git

changelog:
    before_script:
        - git checkout $CI_COMMIT_REF_NAME
        - git remote set-url origin $CI_REPOSITORY_URL
        - git config user.name $USER_NAME
        - git config user.email $USER_EMAIL
        - git stash
        - git pull
        - npm install --ignore-scripts --no-save
    script:
        - node ./node_modules/.bin/or-changelog "${CI_COMMIT_MESSAGE}" $PWD
        - git add .
        - git commit -m "CHANGELOG.md updated" || echo "No changes to commit"
        - git push origin master
    only:
        refs:
            - master
    except:
        variables:
            - $GITLAB_USER_LOGIN == $USER_LOGIN
