From 4a302dc7865fb44c6fb77d80c5054b8cc10d1871 Mon Sep 17 00:00:00 2001 From: Kayou Date: Sat, 23 Jan 2021 00:21:02 +0100 Subject: [PATCH] add auto-format-code (#1142) * add auto-format-code * add github remote * add GITHUB_TOKEN to the remove url * select Yunohost:dev * force push as it's only a code format * pull before running black * working on a clean directory * pull before push? /o\ * do not clone single branch * a last one? * only on dev branch --- .gitlab/ci/lint.gitlab-ci.yml | 22 +++++++++++++++++++++- tox.ini | 7 ++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitlab/ci/lint.gitlab-ci.yml b/.gitlab/ci/lint.gitlab-ci.yml index dabe33d62..94be52f7d 100644 --- a/.gitlab/ci/lint.gitlab-ci.yml +++ b/.gitlab/ci/lint.gitlab-ci.yml @@ -24,4 +24,24 @@ format-check: needs: [] allow_failure: true script: - - tox -e py37-black + - tox -e py37-black-check + +format-run: + stage: lint + image: "before-install" + needs: [] + before_script: + - apt-get update -y && apt-get install git hub -y + - git config --global user.email "yunohost@yunohost.org" + - git config --global user.name "$GITHUB_USER" + - hub clone --branch ${CI_COMMIT_REF_NAME} "https://$GITHUB_TOKEN:x-oauth-basic@github.com/YunoHost/yunohost.git" github_repo + - cd github_repo + script: + # checkout or create and checkout the branch + - hub checkout "ci-format-${CI_COMMIT_REF_NAME}" || hub checkout -b "ci-format-${CI_COMMIT_REF_NAME}" + - tox -e py37-black-run + - hub commit -am "[CI] Format code" || true + - hub pull-request -m "[CI] Format code" -b Yunohost:dev -p || true # GITHUB_USER and GITHUB_TOKEN registered here https://gitlab.com/yunohost/yunohost/-/settings/ci_cd + only: + refs: + - dev \ No newline at end of file diff --git a/tox.ini b/tox.ini index 36134e85a..7607c4a41 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,13 @@ [tox] -envlist = py37-{lint,invalidcode},py37-black +envlist = py37-{lint,invalidcode},py37-black-{run,check} [testenv] skip_install=True deps = py37-{lint,invalidcode}: flake8 - py37-black: black + py37-black-{run,check}: black commands = py37-lint: flake8 src doc data tests --ignore E402,E501 --exclude src/yunohost/vendor py37-invalidcode: flake8 src data --exclude src/yunohost/tests,src/yunohost/vendor --select F - py37-black: black --check --diff src doc data tests + py37-black-check: black --check --diff src doc data tests + py37-black-run: black src doc data tests