Skip to content

Commit 7822b27

Browse files
Merge branch 'main' into tests-add-annotations
2 parents 0e1f3f3 + df5dbb9 commit 7822b27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4475
-707
lines changed

.codecov.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.env.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/lint_test.yml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ jobs:
9292
# black and flake8 action. As pre-commit does not support user installs,
9393
# we set PIP_USER=0 to not do a user install.
9494
- name: Run pre-commit hooks
95+
id: pre-commit
9596
run: export PIP_USER=0; SKIP="no-commit-to-branch,black,flake8" pre-commit run --all-files
9697

9798
# Run black seperately as we don't want to reformat the files
9899
# just error if something isn't formatted correctly.
99100
- name: Check files with black
101+
id: black
102+
if: always() && (steps.pre-commit.outcome == 'success' || steps.pre-commit.outcome == 'failure')
100103
run: black . --check --diff --color
101104

102105
# Run flake8 and have it format the linting errors in the format of
@@ -108,6 +111,8 @@ jobs:
108111
# Format used:
109112
# ::error file={filename},line={line},col={col}::{message}
110113
- name: Run flake8
114+
id: flake8
115+
if: always() && (steps.pre-commit.outcome == 'success' || steps.pre-commit.outcome == 'failure')
111116
run: "flake8 \
112117
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::\
113118
[flake8] %(code)s: %(text)s'"
@@ -162,12 +167,50 @@ jobs:
162167
# This is saved to ./.coverage to be used by codecov to link a
163168
# coverage report to github.
164169
- name: Run tests and generate coverage report
165-
run: python -m pytest -n auto --dist loadfile --cov --disable-warnings -q
170+
id: run_tests
171+
run: python -m pytest tests -n auto --dist loadfile --cov --disable-warnings -q
166172

167-
# This step will publish the coverage reports to codecov.io and
173+
# This step will publish the coverage reports to coveralls.io and
168174
# print a "job" link in the output of the GitHub Action
169-
- name: Publish coverage report to codecov.io
170-
run: python -m codecov
175+
- name: Publish coverage report to coveralls.io
176+
# upload coverage even if a test run failed
177+
# this is a test, and may be removed in the future
178+
if: always() && (steps.run_tests.outcome == 'success' || steps.run_tests.outcome == 'failure')
179+
# important that we don't fail the workflow when coveralls is down
180+
continue-on-error: true
181+
env:
182+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
183+
COVERALLS_FLAG_NAME: coverage-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}
184+
COVERALLS_PARALLEL: true
185+
COVERALLS_SERVICE_NAME: github
186+
run: python -m coveralls
187+
188+
coveralls-finish:
189+
name: Indicate completion to coveralls.io
190+
runs-on: ubuntu-latest
191+
needs: test
192+
# we don't want to fail the workflow when coveralls is down
193+
continue-on-error: true
194+
# we always want to ensure we attempt to send a finish to coveralls
195+
if: always()
196+
steps:
197+
# Set up a consistent version of Python
198+
- name: Set up Python 3.9
199+
id: python
200+
uses: actions/setup-python@v2
201+
with:
202+
python-version: '3.9'
203+
- name: Coveralls Finished
204+
continue-on-error: true
205+
env:
206+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
207+
COVERALLS_SERVICE_NAME: github
208+
# NOTE: this has a small thing where this will not always be the same with the poetry.lock file
209+
# given how this is installed for one api request, its not worth pinning to me.
210+
# any bugs caused by this can be solved when they occur
211+
run: |
212+
python3 -m pip install --upgrade coveralls
213+
python3 -m coveralls --finish
171214
172215
artifact:
173216
name: Generate Artifact

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ celerybeat.pid
105105

106106
# Environments
107107
.env
108+
!template.env
108109
!/tests/modmail/test.env
109110
.venv
110111
env/
@@ -134,10 +135,11 @@ dmypy.json
134135
.idea/
135136

136137
# logs
137-
logs
138+
/logs/
138139

139140
# Configuration
140-
*config.toml
141+
/modmail_config.toml
142+
/modmail_config.yaml
141143

142144
# Custom docker compose override
143145
docker-compose.override.yml

.pre-commit-config.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
## Pre-commit setup
22

33
repos:
4+
# its possible to put this at the bottom, but we want the pre-commit-hooks to check these files as well.
5+
- repo: local
6+
hooks:
7+
- id: ensure-default-configuration-is-exported
8+
name: Export default configuration
9+
language: python
10+
entry: poetry run python -m scripts.export_new_config_to_default_config
11+
files: '(app\.json|template\.env|modmail\/(config\.py|default_config(\.toml|\.yaml)))$'
12+
require_serial: true
13+
additional_dependencies:
14+
# so apparently these are needed, but the versions don't have to be pinned since it uses the local env
15+
# go figure.
16+
- atoml
17+
- attrs
18+
- click
19+
- coloredlogs
20+
- desert
21+
- discord.py
22+
- marshmallow
23+
- python-dotenv
24+
- pyyaml
25+
426
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.0.1
27+
rev: v4.2.0
628
hooks:
729
- id: check-case-conflict
830
- id: check-added-large-files
@@ -11,6 +33,7 @@ repos:
1133
- id: check-yaml
1234
exclude: 'mkdocs.yml' # Exclude all mkdocs.yml as they use tags i.e. `!!!`
1335
- id: pretty-format-json
36+
exclude: 'app.json'
1437
args: [--indent=4, --autofix]
1538
- id: end-of-file-fixer
1639
- id: no-commit-to-branch
@@ -42,19 +65,19 @@ repos:
4265
- id: python-use-type-annotations
4366

4467
- repo: https://github.com/PyCQA/isort
45-
rev: 5.9.3
68+
rev: 5.10.1
4669
hooks:
4770
- id: isort
4871

4972
- repo: https://github.com/asottile/blacken-docs
50-
rev: v1.11.0
73+
rev: v1.12.1
5174
hooks:
5275
- id: blacken-docs
5376
additional_dependencies:
5477
- black
5578

5679
- repo: https://github.com/psf/black
57-
rev: 21.8b0
80+
rev: 22.3.0
5881
hooks:
5982
- id: black
6083
language_version: python3

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Discord Modmail
22

33
[![Lint & Test](https://img.shields.io/github/workflow/status/discord-modmail/modmail/Lint%20&%20Test/main?label=Lint+%26+Test&logo=github&style=flat)](https://github.com/discord-modmail/modmail/actions/workflows/lint_test.yml "Lint and Test")
4-
[![Code Coverage](https://img.shields.io/codecov/c/gh/discord-modmail/modmail/main?logo=codecov&style=flat&label=Code+Coverage)](https://app.codecov.io/gh/discord-modmail/modmail "Code Coverage")
5-
[![Codacy Grade](https://img.shields.io/codacy/grade/78be21a49835484595aea556d5920638?logo=codacy&style=flat&label=Code+Quality)](https://www.codacy.com/gh/discord-modmail/modmail/dashboard "Codacy Grade")
4+
[![Code Coverage](https://img.shields.io/coveralls/github/discord-modmail/modmail?logo=coveralls&style=flat&label=Code+Coverage)](https://coveralls.io/github/discord-modmail/modmail)
65
[![Python](https://img.shields.io/static/v1?label=Python&message=3.8+%7C+3.9&color=blue&logo=Python&style=flat)](https://www.python.org/downloads/ "Python 3.8 | 3.9")
76
[![License](https://img.shields.io/github/license/discord-modmail/modmail?style=flat&label=License)](./LICENSE "License file")
87
[![Code Style](https://img.shields.io/static/v1?label=Code%20Style&message=black&color=000000&style=flat)](https://github.com/psf/black "The uncompromising python formatter")

app.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
22
"env": {
3-
"TOKEN": {
4-
"description": "Discord bot token. This is from https://discord.com/developers/applications",
3+
"MODMAIL_BOT_TOKEN": {
4+
"description": "Discord bot token. Required to log in to discord.\nThis is obtainable from https://discord.com/developers/applications",
55
"required": true
6+
},
7+
"MODMAIL_BOT_PREFIX": {
8+
"description": "Command prefix.",
9+
"required": false,
10+
"value": "?"
611
}
712
},
813
"name": "Modmail Bot",

docs/changelog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
### Added
10+
### Breaking
11+
- Bot now requires a `RELAY_CHANNEL_ID` configuration variable. (#53)
12+
- This is where tickets with users will be relayed.
13+
- At a later point in time, this will be additionally included in a configuration command.
1114

15+
### Added
16+
- Threads system (#53)
17+
- Messages can now be relayed between a user and a server.
18+
- NOTE: There is not a database yet, so none of these messages are stored.
1219
- Added Dispatcher system, although it is not hooked into important features like thread creation yet. (#71)
1320
- Officially support python 3.10 (#119)
1421
- Officially support windows and macos (#121)
22+
- Completely rewrote configuration system (#75)
1523

1624
### Changed
1725

1826
- Embedified the meta commands so they have a nicer UI (#78)
27+
- Improved the logging system to allow trace logging and a specific logging directory to be configured. (#118)
1928

2029
## [0.2.0] - 2021-09-29
2130

docs/contributing.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ $ poetry install
152152

153153
### Set up modmail config
154154

155-
1. Create a copy of `config-default.yml` named `config.yml` in the the `modmail/` directory.
155+
1. Create a copy of `modmail/default_config.toml` named `modmail_config.toml` in the root of the repository.
156156

157157
=== "Linux, macOS"
158158

159159
<div class="termy">
160160

161161
```console
162-
$ cp -v modmail/config-default.toml modmail/config.toml
162+
$ cp -v modmail/default_config.toml modmail_config.toml
163163
```
164164

165165
</div>
@@ -169,20 +169,37 @@ $ poetry install
169169
<div class="termy">
170170

171171
```console
172-
$ xcopy /f modmail/config-default.toml modmail/config.toml
172+
$ xcopy /f modmail/default_config.toml modmail_config.toml
173173
```
174174

175175
</div>
176176

177+
!!! note
178+
If you would like, there is optional support for yaml configuration. Make sure that pyyaml is installed with `poetry install --extras yaml`,
179+
and copy modmail/defaults_config.yaml to modmail_config.yaml.
180+
177181
2. Set the modmail bot prefix in `bot.prefix`.
178182
3. In case you are a contributor set `dev.mode.plugin_dev` and `dev.mode.develop` to `true`. The `develop` variable enables the developer bot extensions and `plugin_dev` enables plugin-developer friendly bot extensions.
179183
4. Create a text file named `.env` in your project root (that's the base folder of your repository):
180-
- You can also copy the `.env.template` file to `.env`
184+
- You can also copy the `template.env` file to `.env`
181185

182186
!!!note
183187
The entire file name is literally `.env`
184188

185-
5. Open the file with any text editor and write the bot token to the files in this format: `TOKEN="my_token"`.
189+
5. Open the file with any text editor and write the bot token to the files in this format: `MODMAIL_BOT_TOKEN="my_token"`.
190+
191+
192+
Of the several supported configuration sources, they are loaded in a specific priority. In decreasing priority:
193+
- `os.environ`
194+
- .env
195+
- modmail_config.yaml (if PyYaml is installed and the file exists)
196+
- modmail_config.toml (if the above file does not exist)
197+
- defaults
198+
199+
Internally, the actual parsing order may not match the above,
200+
but the end configuration object will have the above priorty.
201+
202+
186203

187204
### Run The Project
188205

0 commit comments

Comments
 (0)