File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
src/django_github_app/management/commands Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
18
18
19
19
## [ Unreleased]
20
20
21
+ ### Fixed
22
+
23
+ - ` github import-app ` management command is now wrapped in an atomic transaction, in case any import steps fail.
24
+
21
25
## [ 0.2.0]
22
26
23
27
### Added
Original file line number Diff line number Diff line change 3
3
from typing import Annotated
4
4
from typing import Any
5
5
6
+ from django .db import transaction
6
7
from django_typer .management import Typer
7
8
from typer import Option
8
9
@@ -34,7 +35,8 @@ def import_app(
34
35
"""
35
36
Import an existing GitHub App to database Models.
36
37
"""
37
- installation = Installation .objects .create (installation_id = installation_id )
38
- installation .refresh_from_gh (account_type = type , account_name = name )
39
- repository_data = installation .get_repos ()
40
- Repository .objects .create_from_gh_data (repository_data , installation )
38
+ with transaction .atomic ():
39
+ installation = Installation .objects .create (installation_id = installation_id )
40
+ installation .refresh_from_gh (account_type = type , account_name = name )
41
+ repository_data = installation .get_repos ()
42
+ Repository .objects .create_from_gh_data (repository_data , installation )
Original file line number Diff line number Diff line change @@ -80,3 +80,23 @@ def test_import_app_management_command(settings):
80
80
len (installation .get_repos ())
81
81
== Repository .objects .filter (installation = installation ).count ()
82
82
)
83
+
84
+
85
+ def test_import_app_transaction (settings , monkeypatch ):
86
+ def mock_create_from_gh_data (* args , ** kwargs ):
87
+ raise ValueError
88
+
89
+ monkeypatch .setattr (
90
+ Repository .objects , "create_from_gh_data" , mock_create_from_gh_data
91
+ )
92
+
93
+ with pytest .raises (ValueError ):
94
+ import_app (
95
+ type = settings .account_type ,
96
+ name = settings .account_name ,
97
+ installation_id = int (settings .installation_id ),
98
+ )
99
+
100
+ assert not Installation .objects .filter (
101
+ installation_id = settings .installation_id
102
+ ).exists ()
You can’t perform that action at this time.
0 commit comments