diff --git a/docs/integration.rst b/docs/integration.rst index 9a6a935..f328e98 100644 --- a/docs/integration.rst +++ b/docs/integration.rst @@ -65,3 +65,44 @@ You can configure yamllint to run on ``arc lint``. Here is an example } } } + +Intergration with GitLab +------------------------ + +You can use the following gitlab-ci stage to do run yamllint and get the results as a +`Code quality (Code Climate) ` report. + +.. code:: yaml + + --- + lint: + stage: lint + script: + - pip install yamllint + - mkdir reports + - > + yamllint -f parsable . | tee >(awk ' + BEGIN {FS = ":"; ORS="\n"; first=1} + { + gsub(/^[ \t]+|[ \t]+$|"/, "", $4); + match($4, /^\[(warning|error)\](.*)\((.*)\)$/, a); + sev = (a[1] == "error" ? "major" : "minor"); + if (first) { + first=0; + printf("["); + } else { + printf(","); + } + printf("{\"location\":{\"path\":\"%s\",\"lines\":{\"begin\":%s,\"end\":%s}}," \ + "\"severity\":\"%s\",\"check_name\":\"%s\",\"categories\":[\"Style\"]," \ + "\"type\":\"issue\",\"description\":\"%s\"}", + $1, $2, $3, sev, a[3], a[2]); + } + END { if (!first) printf("]\n"); }' > reports/codequality.json) + artifacts: + when: always + paths: + - reports + expire_in: 1 week + reports: + codequality: reports/codequality.json