Skip to content

Commit

Permalink
Merge pull request #5 from turekj/feature/github_actions_support
Browse files Browse the repository at this point in the history
Initial support for GitHub actions
  • Loading branch information
turekj authored Feb 14, 2020
2 parents 958d729 + cd69d40 commit e7f15d2
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 31 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/ci.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Master

* No changes.

### 0.1.0

* Initial release of the plugin. - [@turekj]

[@turekj]: https://github.com/turekj
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.7

LABEL maintainer="Jakub Turek <[email protected]>"
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"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions danger_python/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions dangerfile.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/shell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import Optional


@dataclass
Expand Down
27 changes: 27 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7f15d2

Please sign in to comment.