gitlab-watcher 1.0.0__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.
- gitlab_watcher/__init__.py +3 -0
- gitlab_watcher/__main__.py +6 -0
- gitlab_watcher/cache.py +76 -0
- gitlab_watcher/cli.py +24 -0
- gitlab_watcher/config.py +233 -0
- gitlab_watcher/discord.py +112 -0
- gitlab_watcher/exceptions.py +106 -0
- gitlab_watcher/git_ops.py +138 -0
- gitlab_watcher/gitlab_client.py +364 -0
- gitlab_watcher/logging_utils.py +56 -0
- gitlab_watcher/processor.py +444 -0
- gitlab_watcher/protocols.py +96 -0
- gitlab_watcher/state.py +201 -0
- gitlab_watcher/watcher.py +267 -0
- gitlab_watcher-1.0.0.dist-info/METADATA +175 -0
- gitlab_watcher-1.0.0.dist-info/RECORD +19 -0
- gitlab_watcher-1.0.0.dist-info/WHEEL +5 -0
- gitlab_watcher-1.0.0.dist-info/entry_points.txt +2 -0
- gitlab_watcher-1.0.0.dist-info/top_level.txt +1 -0
gitlab_watcher/state.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""State management for tracking processed items."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
import threading
|
|
6
|
+
from dataclasses import dataclass, asdict
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Default delay for debounced saves
|
|
14
|
+
DEFAULT_SAVE_DELAY = 1.0
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ProjectState:
|
|
19
|
+
"""State for a single project."""
|
|
20
|
+
|
|
21
|
+
last_mr_iid: Optional[int] = None
|
|
22
|
+
last_mr_state: Optional[str] = None
|
|
23
|
+
last_note_id: int = 0
|
|
24
|
+
last_branch: Optional[str] = None
|
|
25
|
+
processing: bool = False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class StateManager:
|
|
29
|
+
"""Manages state for multiple projects with debounced saving."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, work_dir: Path, save_delay: float = DEFAULT_SAVE_DELAY) -> None:
|
|
32
|
+
"""Initialize state manager.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
work_dir: Directory to store state files
|
|
36
|
+
save_delay: Delay in seconds for debounced saves
|
|
37
|
+
"""
|
|
38
|
+
self.work_dir = work_dir
|
|
39
|
+
self.work_dir.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
self._states: dict[int, ProjectState] = {}
|
|
41
|
+
self._dirty: set[int] = set()
|
|
42
|
+
self._save_timer: Optional[threading.Timer] = None
|
|
43
|
+
self._save_delay = save_delay
|
|
44
|
+
self._lock = threading.Lock()
|
|
45
|
+
|
|
46
|
+
def _state_file(self, project_id: int) -> Path:
|
|
47
|
+
"""Get the state file path for a project."""
|
|
48
|
+
return self.work_dir / f"state_{project_id}.json"
|
|
49
|
+
|
|
50
|
+
def _load_from_file(self, project_id: int, reset_processing: bool = False) -> ProjectState:
|
|
51
|
+
"""Load state from file without caching.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
project_id: The project ID
|
|
55
|
+
reset_processing: If True, reset processing flag to False
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
ProjectState instance
|
|
59
|
+
"""
|
|
60
|
+
state_file = self._state_file(project_id)
|
|
61
|
+
|
|
62
|
+
if state_file.exists():
|
|
63
|
+
try:
|
|
64
|
+
data = json.loads(state_file.read_text())
|
|
65
|
+
state = ProjectState(**data)
|
|
66
|
+
except (json.JSONDecodeError, TypeError):
|
|
67
|
+
state = ProjectState()
|
|
68
|
+
else:
|
|
69
|
+
state = ProjectState()
|
|
70
|
+
|
|
71
|
+
if reset_processing:
|
|
72
|
+
state.processing = False
|
|
73
|
+
|
|
74
|
+
return state
|
|
75
|
+
|
|
76
|
+
def _schedule_save(self, project_id: int) -> None:
|
|
77
|
+
"""Schedule a debounced save operation."""
|
|
78
|
+
with self._lock:
|
|
79
|
+
self._dirty.add(project_id)
|
|
80
|
+
if self._save_timer is not None:
|
|
81
|
+
self._save_timer.cancel()
|
|
82
|
+
self._save_timer = threading.Timer(
|
|
83
|
+
self._save_delay,
|
|
84
|
+
self._flush_dirty,
|
|
85
|
+
)
|
|
86
|
+
self._save_timer.start()
|
|
87
|
+
|
|
88
|
+
def _flush_dirty(self) -> None:
|
|
89
|
+
"""Save all dirty states."""
|
|
90
|
+
with self._lock:
|
|
91
|
+
for project_id in self._dirty:
|
|
92
|
+
self._save_sync(project_id)
|
|
93
|
+
self._dirty.clear()
|
|
94
|
+
self._save_timer = None
|
|
95
|
+
|
|
96
|
+
def _save_sync(self, project_id: int) -> None:
|
|
97
|
+
"""Synchronous save to file."""
|
|
98
|
+
if project_id not in self._states:
|
|
99
|
+
return
|
|
100
|
+
state_file = self._state_file(project_id)
|
|
101
|
+
try:
|
|
102
|
+
state_file.write_text(json.dumps(asdict(self._states[project_id]), indent=2))
|
|
103
|
+
except Exception as e:
|
|
104
|
+
logger.error(f"Failed to save state for project {project_id}: {e}")
|
|
105
|
+
|
|
106
|
+
def load(self, project_id: int) -> ProjectState:
|
|
107
|
+
"""Load state for a project, returning cached state if available.
|
|
108
|
+
|
|
109
|
+
This does NOT reset the processing flag. Use init_state() for
|
|
110
|
+
startup initialization.
|
|
111
|
+
"""
|
|
112
|
+
if project_id in self._states:
|
|
113
|
+
return self._states[project_id]
|
|
114
|
+
|
|
115
|
+
state = self._load_from_file(project_id)
|
|
116
|
+
self._states[project_id] = state
|
|
117
|
+
return state
|
|
118
|
+
|
|
119
|
+
def init_state(self, project_id: int) -> ProjectState:
|
|
120
|
+
"""Initialize state for a project, resetting processing flag.
|
|
121
|
+
|
|
122
|
+
This matches the Bash script's init_state behavior which resets
|
|
123
|
+
processing on watcher startup. Call this once at startup for each
|
|
124
|
+
project.
|
|
125
|
+
"""
|
|
126
|
+
state = self._load_from_file(project_id, reset_processing=True)
|
|
127
|
+
self._states[project_id] = state
|
|
128
|
+
self._save_sync(project_id)
|
|
129
|
+
return state
|
|
130
|
+
|
|
131
|
+
def save(self, project_id: int) -> None:
|
|
132
|
+
"""Save state for a project (debounced)."""
|
|
133
|
+
if project_id not in self._states:
|
|
134
|
+
return
|
|
135
|
+
self._schedule_save(project_id)
|
|
136
|
+
|
|
137
|
+
def force_save(self, project_id: int) -> None:
|
|
138
|
+
"""Immediately save state for a project."""
|
|
139
|
+
with self._lock:
|
|
140
|
+
self._dirty.discard(project_id)
|
|
141
|
+
self._save_sync(project_id)
|
|
142
|
+
|
|
143
|
+
def force_save_all(self) -> None:
|
|
144
|
+
"""Immediately save all dirty states."""
|
|
145
|
+
with self._lock:
|
|
146
|
+
if self._save_timer is not None:
|
|
147
|
+
self._save_timer.cancel()
|
|
148
|
+
for project_id in self._dirty:
|
|
149
|
+
self._save_sync(project_id)
|
|
150
|
+
self._dirty.clear()
|
|
151
|
+
self._save_timer = None
|
|
152
|
+
|
|
153
|
+
def get(self, project_id: int, key: str) -> Optional[str | int | bool]:
|
|
154
|
+
"""Get a state value."""
|
|
155
|
+
state = self.load(project_id)
|
|
156
|
+
return getattr(state, key, None)
|
|
157
|
+
|
|
158
|
+
def set(
|
|
159
|
+
self,
|
|
160
|
+
project_id: int,
|
|
161
|
+
key: str,
|
|
162
|
+
value: Optional[str | int | bool],
|
|
163
|
+
) -> None:
|
|
164
|
+
"""Set a state value."""
|
|
165
|
+
state = self.load(project_id)
|
|
166
|
+
if hasattr(state, key):
|
|
167
|
+
setattr(state, key, value)
|
|
168
|
+
self.save(project_id)
|
|
169
|
+
|
|
170
|
+
def is_processing(self, project_id: int) -> bool:
|
|
171
|
+
"""Check if a project is currently processing."""
|
|
172
|
+
state = self.load(project_id)
|
|
173
|
+
return state.processing
|
|
174
|
+
|
|
175
|
+
def set_processing(self, project_id: int, processing: bool) -> None:
|
|
176
|
+
"""Set the processing flag."""
|
|
177
|
+
self.set(project_id, "processing", processing)
|
|
178
|
+
|
|
179
|
+
def update_mr_state(
|
|
180
|
+
self,
|
|
181
|
+
project_id: int,
|
|
182
|
+
mr_iid: Optional[int],
|
|
183
|
+
mr_state: Optional[str],
|
|
184
|
+
note_id: int,
|
|
185
|
+
branch: Optional[str],
|
|
186
|
+
) -> None:
|
|
187
|
+
"""Update MR tracking state."""
|
|
188
|
+
state = self.load(project_id)
|
|
189
|
+
state.last_mr_iid = mr_iid
|
|
190
|
+
state.last_mr_state = mr_state
|
|
191
|
+
state.last_note_id = note_id
|
|
192
|
+
state.last_branch = branch
|
|
193
|
+
self.save(project_id)
|
|
194
|
+
|
|
195
|
+
def reset(self, project_id: int) -> None:
|
|
196
|
+
"""Reset state for a project."""
|
|
197
|
+
self._states[project_id] = ProjectState()
|
|
198
|
+
self.save(project_id)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
__all__ = ["StateManager", "ProjectState", "DEFAULT_SAVE_DELAY"]
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Main watcher loop."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import re
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from .config import DEFAULT_CONFIG_PATH, Config, ProjectConfig, load_config
|
|
10
|
+
from .discord import DiscordWebhook
|
|
11
|
+
from .exceptions import GitLabError
|
|
12
|
+
from .git_ops import GitOps
|
|
13
|
+
from .gitlab_client import GitLabClient
|
|
14
|
+
from .logging_utils import SensitiveDataFilter
|
|
15
|
+
from .processor import Processor
|
|
16
|
+
from .state import StateManager
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Watcher:
|
|
20
|
+
"""Main watcher class that monitors GitLab projects."""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
config_path: str = DEFAULT_CONFIG_PATH,
|
|
25
|
+
verbose: bool = False,
|
|
26
|
+
*,
|
|
27
|
+
gitlab: Optional[GitLabClient] = None,
|
|
28
|
+
discord: Optional[DiscordWebhook] = None,
|
|
29
|
+
processor: Optional[Processor] = None,
|
|
30
|
+
state: Optional[StateManager] = None,
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Initialize watcher.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
config_path: Path to configuration file
|
|
36
|
+
verbose: Enable verbose logging
|
|
37
|
+
gitlab: Optional GitLab client (for testing)
|
|
38
|
+
discord: Optional Discord webhook (for testing)
|
|
39
|
+
processor: Optional processor (for testing)
|
|
40
|
+
state: Optional state manager (for testing)
|
|
41
|
+
"""
|
|
42
|
+
self.config = load_config(config_path)
|
|
43
|
+
self.verbose = verbose
|
|
44
|
+
|
|
45
|
+
# Setup logging
|
|
46
|
+
log_level = logging.DEBUG if verbose else logging.INFO
|
|
47
|
+
logging.basicConfig(
|
|
48
|
+
level=log_level,
|
|
49
|
+
format="%(asctime)s [%(levelname)s] %(message)s",
|
|
50
|
+
)
|
|
51
|
+
self.logger = logging.getLogger(__name__)
|
|
52
|
+
|
|
53
|
+
# Add sensitive data filter to prevent token leakage in logs
|
|
54
|
+
sensitive_filter = SensitiveDataFilter()
|
|
55
|
+
self.logger.addFilter(sensitive_filter)
|
|
56
|
+
# Also add to root logger for comprehensive coverage
|
|
57
|
+
logging.getLogger().addFilter(sensitive_filter)
|
|
58
|
+
|
|
59
|
+
# Create work directory
|
|
60
|
+
self.work_dir = Path("/tmp/gitlab-watcher")
|
|
61
|
+
self.work_dir.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
|
|
63
|
+
# Initialize or use injected state manager
|
|
64
|
+
self.state = state or StateManager(self.work_dir)
|
|
65
|
+
|
|
66
|
+
# Get GitLab credentials
|
|
67
|
+
gitlab_url = self.config.gitlab_url
|
|
68
|
+
gitlab_token = self.config.gitlab_token
|
|
69
|
+
|
|
70
|
+
# Try to extract from git remote if not in config
|
|
71
|
+
if not gitlab_url or not gitlab_token:
|
|
72
|
+
first_project = self.config.projects[0]
|
|
73
|
+
gitlab_url, gitlab_token = self._extract_from_remote(first_project.path)
|
|
74
|
+
|
|
75
|
+
if not gitlab_url or not gitlab_token:
|
|
76
|
+
raise ValueError("GitLab URL and token must be set in config or git remote")
|
|
77
|
+
|
|
78
|
+
# Initialize or use injected dependencies
|
|
79
|
+
self.gitlab = gitlab or GitLabClient(url=gitlab_url, token=gitlab_token)
|
|
80
|
+
self.discord = discord or DiscordWebhook(
|
|
81
|
+
webhook_url=self.config.discord_webhook
|
|
82
|
+
)
|
|
83
|
+
self.processor = processor or Processor(
|
|
84
|
+
gitlab=self.gitlab,
|
|
85
|
+
discord=self.discord,
|
|
86
|
+
state=self.state,
|
|
87
|
+
gitlab_username=self.config.gitlab_username,
|
|
88
|
+
label_in_progress=self.config.label_in_progress,
|
|
89
|
+
label_review=self.config.label_review,
|
|
90
|
+
ai_tool_mode=self.config.ai_tool_mode,
|
|
91
|
+
ai_tool_custom_command=self.config.ai_tool_custom_command,
|
|
92
|
+
default_branch=self.config.default_branch,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def _extract_from_remote(self, repo_path: Path) -> tuple[str | None, str | None]:
|
|
96
|
+
"""Extract GitLab URL and token from git remote.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
repo_path: Path to git repository
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Tuple of (url, token) or (None, None) if not found
|
|
103
|
+
"""
|
|
104
|
+
git = GitOps(repo_path)
|
|
105
|
+
remote_url = git.get_remote_url()
|
|
106
|
+
|
|
107
|
+
if not remote_url:
|
|
108
|
+
return None, None
|
|
109
|
+
|
|
110
|
+
# Parse URL like: https://token@git.example.com/...
|
|
111
|
+
# or: https://user:token@git.example.com/...
|
|
112
|
+
|
|
113
|
+
# Extract URL
|
|
114
|
+
url_match = re.match(r"https?://([^@]+@)?([^/]+)", remote_url)
|
|
115
|
+
if not url_match:
|
|
116
|
+
return None, None
|
|
117
|
+
|
|
118
|
+
host = url_match.group(2)
|
|
119
|
+
url = f"https://{host}"
|
|
120
|
+
|
|
121
|
+
# Extract token
|
|
122
|
+
token_match = re.match(r"https?://[^:]*:([^@]+)@", remote_url)
|
|
123
|
+
if token_match:
|
|
124
|
+
token = token_match.group(1)
|
|
125
|
+
else:
|
|
126
|
+
# Try format: https://token@host
|
|
127
|
+
token_match = re.match(r"https?://([^@]+)@", remote_url)
|
|
128
|
+
token = token_match.group(1) if token_match else None
|
|
129
|
+
|
|
130
|
+
return url, token
|
|
131
|
+
|
|
132
|
+
def _log(self, project_id: int, message: str) -> None:
|
|
133
|
+
"""Log a message for a project."""
|
|
134
|
+
project_name = next(
|
|
135
|
+
(p.name for p in self.config.projects if p.project_id == project_id),
|
|
136
|
+
str(project_id),
|
|
137
|
+
)
|
|
138
|
+
self.logger.info("[%s] %s", project_name, message)
|
|
139
|
+
|
|
140
|
+
def check_issues(self, project: ProjectConfig) -> None:
|
|
141
|
+
"""Check for new issues to process."""
|
|
142
|
+
if self.state.is_processing(project.project_id):
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
issues = self.gitlab.get_issues(
|
|
146
|
+
project_id=project.project_id,
|
|
147
|
+
state="opened",
|
|
148
|
+
assignee_username=self.config.gitlab_username,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
if not issues:
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
# Find first issue without workflow labels (backlog)
|
|
155
|
+
for issue in issues:
|
|
156
|
+
has_in_progress = self.config.label_in_progress in issue.labels
|
|
157
|
+
has_review = self.config.label_review in issue.labels
|
|
158
|
+
|
|
159
|
+
if not has_in_progress and not has_review:
|
|
160
|
+
self._log(
|
|
161
|
+
project.project_id,
|
|
162
|
+
f"Found backlog issue #{issue.iid}: {issue.title}",
|
|
163
|
+
)
|
|
164
|
+
self.state.set_processing(project.project_id, True)
|
|
165
|
+
self.processor.process_issue(project, issue)
|
|
166
|
+
break
|
|
167
|
+
|
|
168
|
+
def check_mr_status(self, project: ProjectConfig) -> None:
|
|
169
|
+
"""Check MR status for comments and merge cleanup."""
|
|
170
|
+
if self.state.is_processing(project.project_id):
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
state = self.state.load(project.project_id)
|
|
174
|
+
|
|
175
|
+
# Check for merge cleanup BEFORE checking for open MRs
|
|
176
|
+
if state.last_mr_iid is not None:
|
|
177
|
+
mr = self.gitlab.get_merge_request(project.project_id, state.last_mr_iid)
|
|
178
|
+
|
|
179
|
+
if mr and mr.state == "merged":
|
|
180
|
+
self._log(project.project_id, f"MR !{state.last_mr_iid} was merged")
|
|
181
|
+
|
|
182
|
+
self.processor.cleanup_after_merge(
|
|
183
|
+
project=project,
|
|
184
|
+
branch=state.last_branch or "",
|
|
185
|
+
mr_title=mr.title,
|
|
186
|
+
mr_url=mr.web_url,
|
|
187
|
+
)
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
# Check for open MRs
|
|
191
|
+
mrs = self.gitlab.get_merge_requests(
|
|
192
|
+
project_id=project.project_id,
|
|
193
|
+
state="opened",
|
|
194
|
+
author_username=self.config.gitlab_username,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
if not mrs:
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
mr = mrs[0] # Get first open MR
|
|
201
|
+
|
|
202
|
+
# Get latest comments
|
|
203
|
+
notes = self.gitlab.get_notes(project.project_id, mr.iid)
|
|
204
|
+
latest_note = notes[0] if notes else None
|
|
205
|
+
|
|
206
|
+
# Save the old note_id BEFORE updating state
|
|
207
|
+
old_note_id = state.last_note_id
|
|
208
|
+
|
|
209
|
+
# Update state
|
|
210
|
+
self.state.update_mr_state(
|
|
211
|
+
project.project_id,
|
|
212
|
+
mr.iid,
|
|
213
|
+
mr.state,
|
|
214
|
+
latest_note.id if latest_note else 0,
|
|
215
|
+
mr.source_branch,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
# Check for new comments (not by Claude)
|
|
219
|
+
if (
|
|
220
|
+
latest_note
|
|
221
|
+
and latest_note.id != old_note_id
|
|
222
|
+
and latest_note.author_username != self.config.gitlab_username
|
|
223
|
+
):
|
|
224
|
+
self._log(
|
|
225
|
+
project.project_id, f"New comment on MR !{mr.iid}: {latest_note.body}"
|
|
226
|
+
)
|
|
227
|
+
self.state.set_processing(project.project_id, True)
|
|
228
|
+
self.processor.process_comment(project, mr, latest_note.body)
|
|
229
|
+
|
|
230
|
+
def run(self) -> None:
|
|
231
|
+
"""Run the main watcher loop."""
|
|
232
|
+
# Print summary
|
|
233
|
+
print("GitLab Watcher started")
|
|
234
|
+
print(f"Monitoring {len(self.config.projects)} project(s):")
|
|
235
|
+
for project in self.config.projects:
|
|
236
|
+
print(f" - {project.name} (ID: {project.project_id})")
|
|
237
|
+
print(f"Logs: {self.work_dir}")
|
|
238
|
+
|
|
239
|
+
# Initialize state for all projects (resets processing flag)
|
|
240
|
+
for project in self.config.projects:
|
|
241
|
+
self.state.init_state(project.project_id)
|
|
242
|
+
|
|
243
|
+
try:
|
|
244
|
+
# Main loop
|
|
245
|
+
while True:
|
|
246
|
+
try:
|
|
247
|
+
for project in self.config.projects:
|
|
248
|
+
self.check_mr_status(project)
|
|
249
|
+
self.check_issues(project)
|
|
250
|
+
|
|
251
|
+
time.sleep(self.config.poll_interval)
|
|
252
|
+
|
|
253
|
+
except KeyboardInterrupt:
|
|
254
|
+
break
|
|
255
|
+
except GitLabError as e:
|
|
256
|
+
self.logger.error(f"GitLab API Error: {e.message}")
|
|
257
|
+
time.sleep(self.config.poll_interval)
|
|
258
|
+
except Exception as e:
|
|
259
|
+
self.logger.error(f"Error in main loop: {e}")
|
|
260
|
+
time.sleep(self.config.poll_interval)
|
|
261
|
+
finally:
|
|
262
|
+
# Ensure all pending state is saved before shutdown
|
|
263
|
+
print("\nShutting down...")
|
|
264
|
+
self.state.force_save_all()
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
__all__ = ["Watcher"]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitlab-watcher
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Monitor GitLab projects and automatically process issues and merge requests
|
|
5
|
+
Author: Gyengus
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gyengus/gitlab-watcher
|
|
8
|
+
Project-URL: Repository, https://github.com/gyengus/gitlab-watcher.git
|
|
9
|
+
Project-URL: Issues, https://github.com/gyengus/gitlab-watcher/issues
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Bug Tracking
|
|
19
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: click>=8.0.0
|
|
23
|
+
Requires-Dist: requests>=2.28.0
|
|
24
|
+
Requires-Dist: charset-normalizer>=3.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# GitLab Watcher
|
|
30
|
+
|
|
31
|
+
Monitor GitLab projects and automatically process issues and merge requests using AI tools. It features built-in support for automated branch management, AI-driven code generation, and Discord notifications.
|
|
32
|
+
|
|
33
|
+
## What the Watcher Does
|
|
34
|
+
|
|
35
|
+
### Issue Processing (Automatic)
|
|
36
|
+
|
|
37
|
+
When an issue is assigned to the configured user without workflow labels:
|
|
38
|
+
|
|
39
|
+
1. Adds "In progress" label
|
|
40
|
+
2. Creates branch `<issue-id>-<slug>` from default branch
|
|
41
|
+
3. Runs AI tool with the issue description
|
|
42
|
+
4. Pushes changes and creates merge request
|
|
43
|
+
5. Moves issue to "Review" label
|
|
44
|
+
6. Sends optional Discord notification
|
|
45
|
+
|
|
46
|
+
### MR Comment Processing (Automatic)
|
|
47
|
+
|
|
48
|
+
When a new comment appears on an open MR (not from the bot user):
|
|
49
|
+
|
|
50
|
+
1. Checks out the MR's source branch
|
|
51
|
+
2. Runs AI tool with the comment as feedback
|
|
52
|
+
3. Pushes the changes to the remote branch
|
|
53
|
+
4. Notifies Discord channels about applied changes
|
|
54
|
+
|
|
55
|
+
### Post-Merge Cleanup (Automatic)
|
|
56
|
+
|
|
57
|
+
When an MR is merged:
|
|
58
|
+
|
|
59
|
+
1. Updates default branch (e.g., master/main)
|
|
60
|
+
2. Deletes the merged feature branch
|
|
61
|
+
3. Sends Discord notification to confirm cleanup
|
|
62
|
+
|
|
63
|
+
## Prerequisites
|
|
64
|
+
|
|
65
|
+
- **Python 3.11** or higher
|
|
66
|
+
- **Git** installed and available in your system path
|
|
67
|
+
- **GitLab Access Token** with API access
|
|
68
|
+
- **Claude CLI** (or `opencode`) must be installed and available in your PATH. (`ollama` is optional but supported for launching Claude).
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# From PyPI (recommended)
|
|
74
|
+
pip install gitlab-watcher
|
|
75
|
+
|
|
76
|
+
# From source (development mode)
|
|
77
|
+
git clone https://git.gyengus.hu/gyengus/gitlab-watcher.git
|
|
78
|
+
cd gitlab-watcher
|
|
79
|
+
pip install -e ".[dev]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Run with default config
|
|
86
|
+
gitlab-watcher
|
|
87
|
+
|
|
88
|
+
# Custom config file
|
|
89
|
+
gitlab-watcher -c /path/to/config.conf
|
|
90
|
+
|
|
91
|
+
# Verbose mode
|
|
92
|
+
gitlab-watcher --verbose
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
Create the default configuration directory:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
mkdir -p ~/.config/gitlab-watcher
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Create `~/.config/gitlab-watcher/config.conf` with your environment details:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Your GitLab instance URL
|
|
107
|
+
GITLAB_URL="https://git.example.com"
|
|
108
|
+
|
|
109
|
+
# Personal or Group Access Token
|
|
110
|
+
GITLAB_TOKEN="your_token_here"
|
|
111
|
+
|
|
112
|
+
# (Optional) Discord Webhook for detailed event notifications
|
|
113
|
+
DISCORD_WEBHOOK="https://discord.com/api/webhooks/your_webhook_id"
|
|
114
|
+
|
|
115
|
+
# Monitoring interval in seconds
|
|
116
|
+
POLL_INTERVAL=30
|
|
117
|
+
|
|
118
|
+
# AI Tool implementation style (ollama, direct, opencode, custom)
|
|
119
|
+
AI_TOOL_MODE="ollama"
|
|
120
|
+
|
|
121
|
+
# List of absolute paths to project directories to monitor
|
|
122
|
+
PROJECT_DIRS=(
|
|
123
|
+
"/path/to/project1"
|
|
124
|
+
"/path/to/project2"
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
*(Note: If `GITLAB_URL` and `GITLAB_TOKEN` are not provided in the configuration, the watcher will attempt to extract them from your git remotes automatically.)*
|
|
129
|
+
|
|
130
|
+
Each monitored project directory must have a `PROJECT.md`, `AGENTS.md`, or `CLAUDE.md` file with a corresponding Project ID:
|
|
131
|
+
|
|
132
|
+
```markdown
|
|
133
|
+
Project ID: 31
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Supported AI Tools
|
|
137
|
+
|
|
138
|
+
The watcher supports multiple AI tools:
|
|
139
|
+
|
|
140
|
+
| Mode | Description |
|
|
141
|
+
|------|-------------|
|
|
142
|
+
| `ollama` | Launches Claude via Ollama (requires both `ollama` and `claude`) (default) |
|
|
143
|
+
| `direct` | Direct Claude CLI execution (`claude`) |
|
|
144
|
+
| `opencode` | Opencode CLI execution (`opencode`) |
|
|
145
|
+
| `custom` | Custom command for any AI tool |
|
|
146
|
+
|
|
147
|
+
Configure in `config.conf`:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
AI_TOOL_MODE="ollama" # or "direct", "opencode", "custom"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Install dev dependencies
|
|
157
|
+
pip install -e ".[dev]"
|
|
158
|
+
|
|
159
|
+
# Run tests
|
|
160
|
+
pytest
|
|
161
|
+
|
|
162
|
+
# Run tests with coverage
|
|
163
|
+
pytest --cov=gitlab_watcher
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Support & Donations
|
|
167
|
+
|
|
168
|
+
If you find this tool helpful and would like to support its continued development, crypto donations are very much appreciated!
|
|
169
|
+
|
|
170
|
+
- **Bitcoin (BTC):** `bc1qx4q5epl7nsyu9mum8edrvp2my8tut0enrz7kcn`
|
|
171
|
+
- **Dogecoin (DOGE):** `DS62HBswTfAJLadRcMyrUJq6CAE8XV6SqC`
|
|
172
|
+
- **EVM (ETH/BSC/Polygon):** `0x9F0a70A7306DF3fc072446cAF540F6766a4CC4E8`
|
|
173
|
+
- **Web3 Domain:** `gyengus.sendme1satoshi.wallet`
|
|
174
|
+
|
|
175
|
+
Thank you for your support!
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
gitlab_watcher/__init__.py,sha256=WB-J_3BPnkV3BGKurawkyHn5OHZ0i8NBLkHPLidcpUY,100
|
|
2
|
+
gitlab_watcher/__main__.py,sha256=4NAR1Isc2lCr0HpNbogK3rdIAmVvyFjFnaJ7-rO8Us0,111
|
|
3
|
+
gitlab_watcher/cache.py,sha256=_jfRdqdTGxylccUdMU5gyOBj7qM6ijmhVPQCY7k3qWQ,1932
|
|
4
|
+
gitlab_watcher/cli.py,sha256=BiedQqRIAhLOrrA0ZKdM9579CAlDON3NhdlEcqF58gw,540
|
|
5
|
+
gitlab_watcher/config.py,sha256=v6ayNx3mt9h-nxpa2wq84y40z_Az3OOjgw71ayeych4,6466
|
|
6
|
+
gitlab_watcher/discord.py,sha256=rd54lktXRPOAePn1CwcOOpavvx18Jo6W7mL-20ceBiw,3027
|
|
7
|
+
gitlab_watcher/exceptions.py,sha256=VP5k71EySf8q-k6G__cJJL5o5XKo82XD0eUFWir46XQ,2889
|
|
8
|
+
gitlab_watcher/git_ops.py,sha256=qOvB4fJKONoK1GePeRx7ul57EumQBFZ7ECu04sIQVp8,4172
|
|
9
|
+
gitlab_watcher/gitlab_client.py,sha256=5fP8iJMxWhZg3ldJY55F7Pb63RPFyfH3DP0lij53JXg,11083
|
|
10
|
+
gitlab_watcher/logging_utils.py,sha256=ofM8Qz_9qiZVbzQ3kCInO36FPkqY6_FEycNdBXMml1g,1595
|
|
11
|
+
gitlab_watcher/processor.py,sha256=4e1STT1sv8X-PaEbUWCGRGNJXaNIcNQ-0BhBE7WYtF4,13678
|
|
12
|
+
gitlab_watcher/protocols.py,sha256=yXjGbQ1TO7h7GYlx9qzuHArODbm1XH22XRJJuqN1P-4,2176
|
|
13
|
+
gitlab_watcher/state.py,sha256=xBukobV99Ko2m8UIQHD7sIqmSbwLE2UHLhgx414SLcU,6452
|
|
14
|
+
gitlab_watcher/watcher.py,sha256=UkHu2jNJ4DzSIPSfDQOlccWuGePfX_SJ1_-zkckqJ5w,9324
|
|
15
|
+
gitlab_watcher-1.0.0.dist-info/METADATA,sha256=5bsl2a5aSASzBCsko_X_KnO18rZFBr6AC16ivz3RLNc,4998
|
|
16
|
+
gitlab_watcher-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
17
|
+
gitlab_watcher-1.0.0.dist-info/entry_points.txt,sha256=Wo0CCBFIPGuPZMjOKo96nY7ce2ai0eI1kpHQI3_yWG0,59
|
|
18
|
+
gitlab_watcher-1.0.0.dist-info/top_level.txt,sha256=z2hCppdrWcRzD17gnyINhhkiqbAW6sUMhonojh0fGzw,15
|
|
19
|
+
gitlab_watcher-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gitlab_watcher
|