Skip to content

Commit 323a169

Browse files
authored
Move most modules to package at root level, rename from "src" to "jbi" (#176)
* Move most files to root project folder, rename too to "jbi" Before, we had this project structure ``` src ├── __init__.py ├── app ├── jbi ├── static ├── templates ``` the differences between `src/app` and `src/jbi` weren't clear enough to warrant separate packages, so in this commit we move most modules into the root package, renamed to `jbi/`. We also change the structure of the test files accordingly and update any other files that referred to src/*. * Rename "whiteboard_actions" package to "actions"
1 parent ac34fac commit 323a169

Some content is hidden

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

45 files changed

+180
-187
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
!/asgi.py
55
!/bin
66
!/config
7+
!/jbi
78
!/poetry.lock
89
!/pyproject.toml
9-
!/src
1010
!/version.json

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
extends: default
44

55
ignore: |
6-
src/
6+
jbi/
77
tests/
88
bin/
99
.github/

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Below is a full example of an action configuration:
2222
2323
description: example configuration
2424
enabled: true
25-
module: src.jbi.whiteboard_actions.default
25+
module: jbi.actions.default
2626
parameters:
2727
jira_project_key: EXMPL
2828
```
@@ -50,7 +50,7 @@ A bit more about the different fields...
5050
- If false, matching events will not be synchronized
5151
- `module` (optional)
5252
- string
53-
- default: [src.jbi.whiteboard_actions.default](src/jbi/whiteboard_actions/default.py)
53+
- default: [jbi.actions.default](jbi/actions/default.py)
5454
- The specified Python module must be available in the `PYTHONPATH`
5555
- `parameters` (optional)
5656
- dict
@@ -66,7 +66,7 @@ A bit more about the different fields...
6666
## Available Actions
6767

6868
### Default
69-
The `src.jbi.whiteboard_actions.default` action will create or update the Jira issue and its comments.
69+
The `jbi.actions.default` action will create or update the Jira issue and its comments.
7070
It will also set the Jira issue URL in the Bugzilla bug `see_also` field.
7171

7272
**Parameters**
@@ -80,13 +80,13 @@ Example configuration:
8080
whiteboard_tag: example
8181
8282
description: example configuration
83-
module: src.jbi.whiteboard_actions.default
83+
module: jbi.actions.default
8484
parameters:
8585
jira_project_key: EXMPL
8686
```
8787

8888
### Default with assignee and status action
89-
The `src.jbi.whiteboard_actions.default_with_assignee_and_status` action adds some additional
89+
The `jbi.actions.default_with_assignee_and_status` action adds some additional
9090
features on top of the default.
9191

9292
It will attempt to assign the Jira issue the same person as the bug is assigned to. This relies on
@@ -111,7 +111,7 @@ Example configuration:
111111
112112
description: example configuration
113113
enabled: true
114-
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
114+
module: jbi.actions.default_with_assignee_and_status
115115
parameters:
116116
jira_project_key: EXMPL
117117
status_map:
@@ -125,7 +125,7 @@ linked Jira issue status to "Closed". If the bug changes to a status not listed
125125
no change will be made to the Jira issue.
126126

127127
### Custom Actions
128-
If you're looking for a unique capability for your team's data flow, you can add your own Python methods and functionality[...read more here.](src/jbi/whiteboard_actions/README.md)
128+
If you're looking for a unique capability for your team's data flow, you can add your own Python methods and functionality[...read more here.](jbi/actions/README.md)
129129

130130

131131
## Diagram Overview
@@ -210,7 +210,7 @@ GET /whiteboard_tags/
210210
"contact": "[email protected]",
211211
"description": "Addons whiteboard tag for AMO Team",
212212
"enabled": true,
213-
"module": "src.jbi.whiteboard_actions.default",
213+
"module": "jbi.actions.default",
214214
"parameters": {
215215
"jira_project_key": "WEBEXT"
216216
}

asgi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import uvicorn
22

3-
from src.app.environment import get_settings
4-
from src.app.log import CONFIG as LOGGING_CONFIG
3+
from jbi.environment import get_settings
4+
from jbi.log import CONFIG as LOGGING_CONFIG
55

66
settings = get_settings()
77

88

99
if __name__ == "__main__":
1010
server = uvicorn.Server(
1111
uvicorn.Config(
12-
"src.app.main:app",
12+
"jbi.app:app",
1313
host=settings.host,
1414
port=settings.port,
1515
reload=settings.app_reload,

bin/lint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ set -e
55
POETRY_RUN="poetry run"
66

77
bandit () {
8-
$POETRY_RUN bandit -lll --recursive src
8+
$POETRY_RUN bandit -lll --recursive jbi
99
}
1010
black () {
11-
$POETRY_RUN black ${check:+--check} src tests
11+
$POETRY_RUN black ${check:+--check} jbi tests
1212
}
1313
detect_secrets () {
1414
# Scan only files fixed into the repo, omit poetry.lock
@@ -19,10 +19,10 @@ isort () {
1919
$POETRY_RUN isort ${check:+--check-only} .
2020
}
2121
pylint () {
22-
$POETRY_RUN pylint src tests
22+
$POETRY_RUN pylint jbi tests
2323
}
2424
mypy () {
25-
$POETRY_RUN mypy src
25+
$POETRY_RUN mypy jbi
2626
}
2727
yamllint () {
2828
$POETRY_RUN yamllint -c .yamllint config/*.yaml

config/config.nonprod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
description: Flowstate whiteboard tag
1414
enabled: true
15-
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
15+
module: jbi.actions.default_with_assignee_and_status
1616
parameters:
1717
jira_project_key: MR2
1818
status_map:

config/config.prod.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contact: tbd
55
description: Addons whiteboard tag for AMO Team
66
enabled: true
7-
# module: src.jbi.whiteboard_actions.default
7+
# module: jbi.actions.default
88
parameters:
99
jira_project_key: WEBEXT
1010

@@ -19,7 +19,7 @@
1919
2020
description: Firefox Front End whiteboard tag
2121
enabled: true
22-
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
22+
module: jbi.actions.default_with_assignee_and_status
2323
parameters:
2424
jira_project_key: FIDEFE
2525
status_map:
@@ -32,7 +32,7 @@
3232
3333
description: Flowstate whiteboard tag
3434
enabled: true
35-
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
35+
module: jbi.actions.default_with_assignee_and_status
3636
parameters:
3737
jira_project_key: MR2
3838
status_map:
File renamed without changes.

jbi/actions/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Looking to add a new action?
2+
3+
"actions" are Python modules that, if available in the `PYTHONPATH`,
4+
can be run by updating the `module` attribute of the YAML config file.
5+
6+
### Create a new action...
7+
8+
Let's create a `new_action`!
9+
10+
1. First, add a new Python file (eg. `my_team_action.py`) in the `jbi/actions/` directory.
11+
1. Add the Python function `init` to the module, for example:
12+
13+
```python
14+
from jbi import ActionResult, Operation
15+
16+
def init(jira_project_key, optional_param=42):
17+
18+
def execute(payload) -> ActionResult:
19+
print(f"{optional_param}, going to {jira_project_key}!")
20+
return True, {"result": 42}
21+
22+
return execute
23+
```
24+
25+
1. In the above example the `jira_project_key` parameter is required
26+
1. `optional_param`, which has a default value, is not required to run this action
27+
1. `init()` returns a `__call__`able object that the system calls with the Bugzilla request payload
28+
1. The returned `ActionResult` features a boolean to indicate whether something was performed or not, along with a `Dict` (used as a response to the WebHook endpoint).
29+
30+
1. Use the `payload` to perform the desired processing!
31+
1. Use the available service calls from `jbi/services.py` (or make new ones)
32+
1. Update the `README.md` to document your action
33+
1. Now the action `jbi.actions.my_team_actions` can be used in the YAML configuration, under the `module` key.
File renamed without changes.

0 commit comments

Comments
 (0)