|
26 | 26 | import os
|
27 | 27 | import fnmatch
|
28 | 28 | import logging
|
| 29 | +import urllib |
| 30 | + |
| 31 | +from requests.exceptions import HTTPError |
29 | 32 |
|
30 | 33 | from .exitvals import (
|
31 | 34 | FAILURE_EXITVAL,
|
32 | 35 | CONTINUE_EXITVAL,
|
33 | 36 | SUCCESS_EXITVAL
|
34 | 37 | )
|
35 | 38 | from .utils import is_exe, check_create_dir, get_int
|
36 |
| -from .opengrok import get_repos, get_repo_type |
| 39 | +from .webutil import get |
| 40 | +from .opengrok import get_repos, get_repo_type, get_uri |
37 | 41 | from .hook import run_hook
|
38 | 42 |
|
39 | 43 | from ..scm.repofactory import get_repository
|
@@ -196,13 +200,14 @@ def get_project_properties(project_config, project_name, hookdir):
|
196 | 200 | use_proxy, ignored_repos
|
197 | 201 |
|
198 | 202 |
|
199 |
| -def mirror_project(config, project_name, check_incoming, uri, |
| 203 | +def mirror_project(config, project_name, check_changes, uri, |
200 | 204 | source_root):
|
201 | 205 | """
|
202 | 206 | Mirror the repositories of single project.
|
203 | 207 | :param config global configuration dictionary
|
204 | 208 | :param project_name: name of the project
|
205 |
| - :param check_incoming: |
| 209 | + :param check_changes: check for changes in the project or its repositories |
| 210 | + and terminate if no change is found |
206 | 211 | :param uri
|
207 | 212 | :param source_root
|
208 | 213 | :return exit code
|
@@ -244,22 +249,44 @@ def mirror_project(config, project_name, check_incoming, uri,
|
244 | 249 | format(project_name))
|
245 | 250 | return CONTINUE_EXITVAL
|
246 | 251 |
|
247 |
| - # Check if any of the repositories contains incoming changes. |
248 |
| - if check_incoming: |
249 |
| - got_incoming = False |
250 |
| - for repo in repos: |
251 |
| - try: |
252 |
| - if repo.incoming(): |
253 |
| - logger.debug('Repository {} has incoming changes'. |
254 |
| - format(repo)) |
255 |
| - got_incoming = True |
256 |
| - break |
257 |
| - except RepositoryException: |
258 |
| - logger.error('Cannot determine incoming changes for ' |
259 |
| - 'repository {}'.format(repo)) |
260 |
| - return FAILURE_EXITVAL |
| 252 | + # Check if the project or any of its repositories have changed. |
| 253 | + if check_changes: |
| 254 | + changes_detected = False |
| 255 | + |
| 256 | + # check if the project is a new project - full index is necessary |
| 257 | + try: |
| 258 | + r = get(logger, get_uri(uri, 'api', 'v1', 'projects', |
| 259 | + urllib.parse.quote_plus(project_name), |
| 260 | + 'property', 'indexed')) |
| 261 | + r.raise_for_status() |
| 262 | + if not bool(r.json()): |
| 263 | + changes_detected = True |
| 264 | + logger.debug('Project {} has not been indexed yet' |
| 265 | + .format(project_name)) |
| 266 | + except ValueError as e: |
| 267 | + logger.error('Unable to parse project \'{}\' indexed flag: {}' |
| 268 | + .format(project_name, e)) |
| 269 | + return FAILURE_EXITVAL |
| 270 | + except HTTPError as e: |
| 271 | + logger.error('Unable to determine project \'{}\' indexed flag: {}' |
| 272 | + .format(project_name, e)) |
| 273 | + return FAILURE_EXITVAL |
261 | 274 |
|
262 |
| - if not got_incoming: |
| 275 | + # check if the project has any new changes in the SCM |
| 276 | + if not changes_detected: |
| 277 | + for repo in repos: |
| 278 | + try: |
| 279 | + if repo.incoming(): |
| 280 | + logger.debug('Repository {} has incoming changes'. |
| 281 | + format(repo)) |
| 282 | + changes_detected = True |
| 283 | + break |
| 284 | + except RepositoryException: |
| 285 | + logger.error('Cannot determine incoming changes for ' |
| 286 | + 'repository {}'.format(repo)) |
| 287 | + return FAILURE_EXITVAL |
| 288 | + |
| 289 | + if not changes_detected: |
263 | 290 | logger.info('No incoming changes for repositories in '
|
264 | 291 | 'project {}'.
|
265 | 292 | format(project_name))
|
|
0 commit comments