|
2 | 2 |
|
3 | 3 | All contributions are welcome! Besides code contributions, this includes things like documentation improvements, bug reports, and feature requests. |
4 | 4 |
|
5 | | -You should first check if there is a [GitHub issue](https://github.com/joshuadavidthomas/django-bird/issues) already open or related to what you would like to contribute. If there is, please comment on that issue to let others know you are working on it. If there is not, please open a new issue to discuss your contribution. |
| 5 | +You should first check if there is a [GitHub issue](https://github.com/joshuadavidthomas/django-github-app/issues) already open or related to what you would like to contribute. If there is, please comment on that issue to let others know you are working on it. If there is not, please open a new issue to discuss your contribution. |
6 | 6 |
|
7 | 7 | Not all contributions need to start with an issue, such as typo fixes in documentation or version bumps to Python or Django that require no internal code changes, but generally, it is a good idea to open an issue first. |
8 | 8 |
|
9 | 9 | We adhere to Django's Code of Conduct in all interactions and expect all contributors to do the same. Please read the [Code of Conduct](https://www.djangoproject.com/conduct/) before contributing. |
10 | 10 |
|
11 | | -## Setup |
| 11 | +### Requirements |
12 | 12 |
|
13 | | -The following setup steps assume you are using a Unix-like operating system, such as Linux or macOS, and that you have a [supported](https://django-bird.readthedocs.io/#requirements) version of Python installed. If you are using Windows, you will need to adjust the commands accordingly. If you do not have Python installed, you can visit [python.org](https://www.python.org/) for instructions on how to install it for your operating system. |
| 13 | +- [uv](https://github.com/astral-sh/uv) - Modern Python toolchain that handles: |
| 14 | + - Python version management and installation |
| 15 | + - Virtual environment creation and management |
| 16 | + - Fast, reliable dependency resolution and installation |
| 17 | + - Reproducible builds via lockfile |
| 18 | +- [direnv](https://github.com/direnv/direnv) (Optional) - Automatic environment variable loading |
| 19 | +- [just](https://github.com/casey/just) (Optional) - Command runner for development tasks |
14 | 20 |
|
15 | | -1. Fork the repository and clone it locally. |
16 | | -2. Create a virtual environment and activate it. You can use whatever tool you prefer for this. Below is an example using the Python standard library's `venv` module: |
| 21 | +### `Justfile` |
| 22 | + |
| 23 | +The repository includes a `Justfile` that provides all common development tasks with a consistent interface. Running `just` without arguments shows all available commands and their descriptions: |
| 24 | + |
| 25 | +```bash |
| 26 | +just |
| 27 | +# or explicitly |
| 28 | +just --list --list-submodules |
| 29 | +``` |
17 | 30 |
|
18 | | -```shell |
19 | | -python -m venv venv |
20 | | -source venv/bin/activate |
| 31 | +<!-- [[[cog |
| 32 | +import subprocess |
| 33 | +import cog |
| 34 | +
|
| 35 | +output_raw = subprocess.run(['just', '--list', '--list-submodules'], stdout=subprocess.PIPE) |
| 36 | +output_list = output_raw.stdout.decode('utf-8').split('\n') |
| 37 | +
|
| 38 | +cog.out('```bash\n') |
| 39 | +for i, line in enumerate(output_list): |
| 40 | + if not line: |
| 41 | + continue |
| 42 | + cog.out(line) |
| 43 | + if i < len(output_list): |
| 44 | + cog.out('\n') |
| 45 | +cog.out('```') |
| 46 | +]]] --> |
| 47 | +```bash |
| 48 | +Available recipes: |
| 49 | + bootstrap |
| 50 | + coverage *ARGS |
| 51 | + lint |
| 52 | + lock *ARGS |
| 53 | + manage *COMMAND |
| 54 | + test *ARGS |
| 55 | + testall *ARGS |
| 56 | + types *ARGS |
| 57 | + docs: |
| 58 | + build LOCATION="docs/_build/html" # Build documentation using Sphinx |
| 59 | + serve PORT="8000" # Serve documentation locally |
21 | 60 | ``` |
| 61 | +<!-- [[[end]]] --> |
| 62 | + |
| 63 | +All commands below will contain the full command as well as its `just` counterpart. |
| 64 | + |
| 65 | +## Setup |
| 66 | + |
| 67 | +The following instructions will use `uv` and assume a Unix-like operating system (Linux or macOS). |
22 | 68 |
|
23 | | -3. Install `django-bird` and the `dev` dependencies in editable mode: |
| 69 | +Windows users will need to adjust commands accordingly, though the core workflow remains the same. |
| 70 | +Alternatively, any Python package manager that supports installing from `pyproject.toml` ([PEP 621](https://peps.python.org/pep-0621/)) can be used. If not using `uv`, ensure you have Python installed from [python.org](https://www.python.org/). |
| 71 | + |
| 72 | +1. Fork the repository and clone it locally. |
| 73 | +2. Use `uv` too bootstrap your development environment: |
24 | 74 |
|
25 | | -```shell |
26 | | -python -m pip install --editable '.[dev]' |
27 | | -# or using [just](#just) |
| 75 | +```bash |
| 76 | +uv python install |
| 77 | +uv sync --locked |
| 78 | +# or |
28 | 79 | just bootstrap |
29 | 80 | ``` |
30 | 81 |
|
31 | | -## Testing |
| 82 | + This will install the correct Python version, create and configure a virtual environment, and install all dependencies. |
32 | 83 |
|
33 | | -We use [`pytest`](https://docs.pytest.org/) for testing and [`nox`](https://nox.thea.codes/) to run the tests in multiple environments. |
| 84 | +## Tests |
| 85 | + |
| 86 | +The project uses [`pytest`](https://docs.pytest.org/) for testing and [`nox`](https://nox.thea.codes/) to run the tests in multiple environments. |
34 | 87 |
|
35 | 88 | To run the test suite against the default versions of Python (lower bound of supported versions) and Django (lower bound of LTS versions), run: |
36 | 89 |
|
37 | | -```shell |
38 | | -python -m nox --session "test" |
39 | | -# or using [just](#just) |
| 90 | +```bash |
| 91 | +uv run nox --session test |
| 92 | +# or |
40 | 93 | just test |
41 | 94 | ``` |
42 | 95 |
|
43 | | -To run the test suite against all supported versions of Python and Django, run: |
| 96 | +To run the test suite against the entire matrix of supported versions of Python and Django, run: |
44 | 97 |
|
45 | | -```shell |
46 | | -python -m nox --session "tests" |
47 | | -# or using [just](#just) |
| 98 | +```bash |
| 99 | +uv run nox --session tests |
| 100 | +# or |
48 | 101 | just testall |
49 | 102 | ``` |
50 | 103 |
|
51 | | -## `just` |
52 | | - |
53 | | -[`just`](https://github.com/casey/just) is a command runner that is used to run common commands, similar to `make` or `invoke`. A `Justfile` is provided at the base of the repository, which contains commands for common development tasks, such as running the test suite or linting. |
| 104 | +Both can be passed additional arguments that will be provided to pytest: |
54 | 105 |
|
55 | | -To see a list of all available commands, ensure `just` is installed and run the following command at the base of the repository: |
| 106 | +```bash |
| 107 | +uv run nox --session test -- -v --last-failed |
| 108 | +uv run nox --session tests -- --failed-first --maxfail=1 |
| 109 | +# or |
| 110 | +just test -v --last-failed |
| 111 | +just testall --failed-first --maxfail=1 |
| 112 | +``` |
56 | 113 |
|
57 | | -```shell |
58 | | -just |
| 114 | +### Integration Tests |
| 115 | + |
| 116 | +Integration tests are contained in the [`tests/integration`](tests/integration) directory and test actual interactions with GitHub's API and webhooks. |
| 117 | + |
| 118 | +These tests are skipped by default and must be explicitly enabled by passing `--integration` as a pytest argument. Running them requires both a GitHub App and a Personal Access Token (PAT) configured in your environment. |
| 119 | + |
| 120 | +Follow these steps to set up your environment for integration tests: |
| 121 | + |
| 122 | +1. Create a test GitHub App: |
| 123 | + - Go to GitHub Developer Settings > GitHub Apps > New GitHub App |
| 124 | + - Set the Name to `@<username> - django-github-app tests` (this can be anything, but needs to be unique across GitHub and under 34 characters in length) |
| 125 | + - Set Homepage URL to your fork's URL, e.g. `https://github.com/<username>/django-github-app` |
| 126 | + - Turn webhooks off by toggling the Active checkbox under Webhook (there are currently no Webhook integration tests, this may need to be adjusted if/when they are added) |
| 127 | + - Set the following permissions: |
| 128 | + - Repository permissions: |
| 129 | + - Metadata: Read only |
| 130 | + - Select "Only on this account" for where the GitHub App can be installed |
| 131 | +2. After creating the test GitHub App: |
| 132 | + - Grab the following information from the admin panel: |
| 133 | + - App ID |
| 134 | + - Client ID |
| 135 | + - Generate and download private key |
| 136 | +3. Install the new test GitHub App on your user account by selecting "Install App" from the GitHub App admin panel. |
| 137 | + - After installation, make note of the unique ID in the URL, e.g. `https://github.com/settings/installations/<unique ID>` |
| 138 | +5. Configure the following environment variables: |
| 139 | + |
| 140 | + - `TEST_ACCOUNT_NAME` - your GitHub username |
| 141 | + - `TEST_ACCOUNT_TYPE` - user |
| 142 | + - `TEST_APP_ID` - the App ID of the GitHub App from step 2 |
| 143 | + - `TEST_CLIENT_ID` - the Client ID of the GitHub App from step 2 |
| 144 | + - `TEST_INSTALLATION_ID` - the ID of the installation of the GitHub App from step 3 |
| 145 | + - `TEST_NAME` - the Name of the GitHub App from step 1 |
| 146 | + - `TEST_WEBHOOK_SECRET` - can be left blank for now |
| 147 | + |
| 148 | + If you are using direnv, there is an `.env.example` file in the repository with all the required environment variables: |
| 149 | + |
| 150 | + ```bash |
| 151 | + cp .env.example .env |
| 152 | + ``` |
| 153 | + |
| 154 | + Otherwise export the variables in your development environment: |
| 155 | + |
| 156 | + ```bash |
| 157 | + export TEST_ACCOUNT_NAME="<username>" |
| 158 | + # etc... |
| 159 | + ``` |
| 160 | + |
| 161 | +After setup, you can run the test suite with the integration tests enabled by passing the `--integration` argument to any of the test commands: |
| 162 | + |
| 163 | +```bash |
| 164 | +uv run nox --session test -- --integration |
| 165 | +# or |
| 166 | +just test --integration |
59 | 167 | ``` |
0 commit comments