qontract-reconcile 0.10.2.dev216__py3-none-any.whl → 0.10.2.dev217__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {qontract_reconcile-0.10.2.dev216.dist-info → qontract_reconcile-0.10.2.dev217.dist-info}/METADATA +1 -1
- {qontract_reconcile-0.10.2.dev216.dist-info → qontract_reconcile-0.10.2.dev217.dist-info}/RECORD +17 -17
- reconcile/cli.py +620 -505
- reconcile/gitlab_housekeeping.py +57 -58
- reconcile/gitlab_permissions.py +13 -5
- reconcile/gitlab_projects.py +5 -3
- reconcile/integrations_manager.py +32 -41
- reconcile/jenkins_job_builder.py +1 -1
- reconcile/jenkins_job_builds_cleaner.py +10 -5
- reconcile/jenkins_job_cleaner.py +6 -3
- reconcile/jenkins_roles.py +15 -8
- reconcile/jenkins_webhooks.py +6 -3
- reconcile/jenkins_webhooks_cleaner.py +3 -2
- reconcile/jira_watcher.py +25 -9
- reconcile/utils/jira_client.py +1 -1
- {qontract_reconcile-0.10.2.dev216.dist-info → qontract_reconcile-0.10.2.dev217.dist-info}/WHEEL +0 -0
- {qontract_reconcile-0.10.2.dev216.dist-info → qontract_reconcile-0.10.2.dev217.dist-info}/entry_points.txt +0 -0
reconcile/jira_watcher.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import logging
|
2
|
+
from collections.abc import Callable, Mapping, Sequence
|
3
|
+
from typing import Any
|
2
4
|
|
3
5
|
from reconcile import queries
|
4
6
|
from reconcile.slack_base import slackapi_from_slack_workspace
|
@@ -6,6 +8,7 @@ from reconcile.utils.defer import defer
|
|
6
8
|
from reconcile.utils.jira_client import JiraClient
|
7
9
|
from reconcile.utils.secret_reader import SecretReader
|
8
10
|
from reconcile.utils.sharding import is_in_shard_round_robin
|
11
|
+
from reconcile.utils.slack_api import SlackApi
|
9
12
|
from reconcile.utils.state import (
|
10
13
|
State,
|
11
14
|
init_state,
|
@@ -14,7 +17,9 @@ from reconcile.utils.state import (
|
|
14
17
|
QONTRACT_INTEGRATION = "jira-watcher"
|
15
18
|
|
16
19
|
|
17
|
-
def fetch_current_state(
|
20
|
+
def fetch_current_state(
|
21
|
+
jira_board: Mapping, settings: Mapping
|
22
|
+
) -> tuple[JiraClient, dict[str, dict[str, str]]]:
|
18
23
|
jira = JiraClient(jira_board, settings=settings)
|
19
24
|
issues = jira.get_issues(fields=["key", "status", "summary"])
|
20
25
|
return jira, {
|
@@ -23,11 +28,18 @@ def fetch_current_state(jira_board, settings):
|
|
23
28
|
}
|
24
29
|
|
25
30
|
|
26
|
-
def fetch_previous_state(state, project):
|
31
|
+
def fetch_previous_state(state: State, project: str) -> dict:
|
27
32
|
return state.get(project, {})
|
28
33
|
|
29
34
|
|
30
|
-
def format_message(
|
35
|
+
def format_message(
|
36
|
+
server: str,
|
37
|
+
key: str,
|
38
|
+
data: Mapping,
|
39
|
+
event: str,
|
40
|
+
previous_state: Mapping | None = None,
|
41
|
+
current_state: Mapping | None = None,
|
42
|
+
) -> str:
|
31
43
|
summary = data["summary"]
|
32
44
|
info = (
|
33
45
|
": {} -> {}".format(previous_state["status"], current_state["status"])
|
@@ -38,7 +50,9 @@ def format_message(server, key, data, event, previous_state=None, current_state=
|
|
38
50
|
return f"{url} ({summary}) {event}{info}"
|
39
51
|
|
40
52
|
|
41
|
-
def calculate_diff(
|
53
|
+
def calculate_diff(
|
54
|
+
server: str, current_state: Mapping, previous_state: Mapping
|
55
|
+
) -> list[str]:
|
42
56
|
messages = []
|
43
57
|
new_issues = [
|
44
58
|
format_message(server, key, data, "created")
|
@@ -64,7 +78,7 @@ def calculate_diff(server, current_state, previous_state):
|
|
64
78
|
return messages
|
65
79
|
|
66
80
|
|
67
|
-
def init_slack(jira_board):
|
81
|
+
def init_slack(jira_board: Mapping[str, Any]) -> SlackApi:
|
68
82
|
secret_reader = SecretReader(queries.get_secret_reader_settings())
|
69
83
|
slack_info = jira_board["slack"]
|
70
84
|
|
@@ -77,7 +91,7 @@ def init_slack(jira_board):
|
|
77
91
|
)
|
78
92
|
|
79
93
|
|
80
|
-
def act(dry_run, jira_board, diffs):
|
94
|
+
def act(dry_run: bool, jira_board: Mapping[str, str], diffs: Sequence[str]) -> None:
|
81
95
|
if not dry_run and diffs:
|
82
96
|
slack = init_slack(jira_board)
|
83
97
|
|
@@ -87,16 +101,17 @@ def act(dry_run, jira_board, diffs):
|
|
87
101
|
slack.chat_post_message(diff)
|
88
102
|
|
89
103
|
|
90
|
-
def write_state(state: State, project, state_to_write):
|
104
|
+
def write_state(state: State, project: str, state_to_write: Mapping) -> None:
|
91
105
|
state.add(project, value=state_to_write, force=True)
|
92
106
|
|
93
107
|
|
94
108
|
@defer
|
95
|
-
def run(dry_run, defer):
|
109
|
+
def run(dry_run: bool, defer: Callable | None = None) -> None:
|
96
110
|
jira_boards = [j for j in queries.get_jira_boards() if j.get("slack")]
|
97
111
|
settings = queries.get_app_interface_settings()
|
98
112
|
state = init_state(integration=QONTRACT_INTEGRATION)
|
99
|
-
defer
|
113
|
+
if defer:
|
114
|
+
defer(state.cleanup)
|
100
115
|
for index, jira_board in enumerate(jira_boards):
|
101
116
|
if not is_in_shard_round_robin(jira_board["name"], index):
|
102
117
|
continue
|
@@ -109,6 +124,7 @@ def run(dry_run, defer):
|
|
109
124
|
continue
|
110
125
|
previous_state = fetch_previous_state(state, jira.project)
|
111
126
|
if previous_state:
|
127
|
+
assert jira.server
|
112
128
|
diffs = calculate_diff(jira.server, current_state, previous_state)
|
113
129
|
act(dry_run, jira_board, diffs)
|
114
130
|
if not dry_run:
|
reconcile/utils/jira_client.py
CHANGED
{qontract_reconcile-0.10.2.dev216.dist-info → qontract_reconcile-0.10.2.dev217.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|