diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 36c5352..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Continuous Integration - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Install poetry - run: | - python -m pip install --upgrade pip - pip install poetry - - name: Install dependencies - run: | - poetry install - - name: Test with pytest - run: | - poetry run pytest diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..f9b0bb5 --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,14 @@ +name: Danger + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Run Danger + uses: ./ + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7f98cac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: python +python: + - "3.7" +cache: + yarn: true + pip: true + directories: + - node_modules +install: + - pip install poetry + - poetry install +script: + - poetry run pytest +after_script: + - nvm install 10.16.0 + - nvm use 10.16.0 + - yarn global add danger + - poetry run danger-python ci -v diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c9bc0d0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +## Master + +* No changes. + +### 0.1.0 + +* Initial release of the plugin. - [@turekj] + +[@turekj]: https://github.com/turekj diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75b0660 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.7 + +LABEL maintainer="Jakub Turek " +LABEL "com.github.actions.name"="danger-python" +LABEL "com.github.actions.description"="Runs Python Dangerfiles" +LABEL "com.github.actions.icon"="zap" +LABEL "com.github.actions.color"="blue" + +# Install dependencies +RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - +RUN apt-get install -y nodejs + +RUN python -m pip install --upgrade pip +RUN pip install poetry + +RUN mkdir -p /usr/src/danger-python +COPY . /usr/src/danger-python +RUN cd /usr/src/danger-python && \ + poetry config virtualenvs.create false && \ + poetry install --no-dev + +ENTRYPOINT ["npx", "--package", "danger", "danger-python", "ci"] diff --git a/README.md b/README.md index e4245b8..a41c4db 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,26 @@ title = danger.github.pr.title markdown(title) ``` +### Using as GitHub Action + +1. Create a `dangerfile.py` in the root directory of your repository. +2. Add a following workflow: + +```yaml +name: Danger +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: danger/python@f0ce9ea + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + ### Development To develop the code, clone the repository and run the following commands: diff --git a/danger_python/models.py b/danger_python/models.py index be438eb..fec7b02 100644 --- a/danger_python/models.py +++ b/danger_python/models.py @@ -1152,9 +1152,10 @@ class Config: class GitHubReviewState(Enum): APPROVED = "APPROVED" - COMMENT = "COMMENT" + CHANGES_REQUESTED = "CHANGES_REQUESTED" + COMMENTED = "COMMENTED" + DISMISSED = "DISMISSED" PENDING = "PENDING" - REQUEST_CHANGES = "REQUEST_CHANGES" class GitHubReviewers(BaseModel): diff --git a/dangerfile.py b/dangerfile.py index e3d6346..f20337c 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -1,2 +1,7 @@ -title = danger.github.pr.title -markdown(title) +touched_files = danger.git.modified_files + danger.git.created_files +has_source_changes = any(map(lambda f: f.startswith("danger_python"), touched_files)) +has_changelog_entry = "CHANGELOG.md" in touched_files +is_trivial = "#trivial" in danger.github.pr.title + +if has_source_changes and not has_changelog_entry and not is_trivial: + warn("Please, add a CHANGELOG.md entry for non-trivial changes") diff --git a/tests/conftest.py b/tests/conftest.py index 5877171..2d730d0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,10 +4,10 @@ from unittest import mock import pytest - -from danger_python.danger import Danger from pyfakefs.fake_filesystem_unittest import Patcher from testfixtures.popen import MockPopen + +from danger_python.danger import Danger from tests.fixtures.danger import danger_input_file_fixture from tests.fixtures.shell import SubprocessFixture diff --git a/tests/fixtures/shell.py b/tests/fixtures/shell.py index efc1d0a..46b6a9c 100644 --- a/tests/fixtures/shell.py +++ b/tests/fixtures/shell.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import List, Optional +from typing import Optional @dataclass diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..dc1e260 --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,27 @@ +from danger_python.models import DangerDSLJSONType, GitHubReviewState + + +def test_github_dsl_handles_correct_review_states(): + """ + Test that GitHub DSL handles correct review states. + """ + dsl_json = { + "github": { + "reviews": [ + {"state": "APPROVED"}, + {"state": "CHANGES_REQUESTED"}, + {"state": "COMMENTED"}, + {"state": "PENDING"}, + {"state": "DISMISSED"}, + ] + } + } + + dsl = DangerDSLJSONType(**dsl_json) + + assert len(dsl.github.reviews) == 5 + assert dsl.github.reviews[0].state == GitHubReviewState.APPROVED + assert dsl.github.reviews[1].state == GitHubReviewState.CHANGES_REQUESTED + assert dsl.github.reviews[2].state == GitHubReviewState.COMMENTED + assert dsl.github.reviews[3].state == GitHubReviewState.PENDING + assert dsl.github.reviews[4].state == GitHubReviewState.DISMISSED