Skip to content

Commit d5fd3ef

Browse files
authored
always refresh the list of repositories for projects (#4446)
1 parent c89376d commit d5fd3ef

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

apiary.apib

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ This includes also projects of any sub-groups.
404404

405405
This will merely add the project and its repositories to the web application configuration.
406406
The project will not be searchable (and thus appear in the UI) until it is indexed.
407+
If the project is already present in the configuration, the list of its repositories will be refreshed
408+
if history is enabled.
407409

408410
+ Request (text/plain)
409411
+ Body

docker/start.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
add_project,
5656
delete_project,
5757
get_configuration,
58+
get_repos,
5859
list_projects,
5960
)
6061
from opengrok_tools.utils.readconfig import read_config
@@ -255,15 +256,25 @@ def refresh_projects(logger, uri, api_timeout):
255256
logger.debug("Projects from the web app: {}".format(webapp_projects))
256257
src_root = OPENGROK_SRC_ROOT
257258

258-
# Add projects.
259+
# Add projects for top-level directories under source root.
259260
for item in os.listdir(src_root):
260261
logger.debug("Got item {}".format(item))
261262
if os.path.isdir(os.path.join(src_root, item)):
262-
if item not in webapp_projects:
263-
logger.info("Adding project {}".format(item))
264-
add_project(logger, item, uri, timeout=api_timeout)
265-
266-
# Remove projects
263+
if item in webapp_projects:
264+
action = "Refreshing"
265+
else:
266+
action = "Adding"
267+
logger.info(f"{action} project {item}")
268+
add_project(logger, item, uri, timeout=api_timeout)
269+
270+
if logger.level == logging.DEBUG:
271+
repos = get_repos(logger, item, uri)
272+
if repos:
273+
logger.debug(
274+
"Project {} has these repositories: {}".format(item, repos)
275+
)
276+
277+
# Remove projects that no longer have source.
267278
for item in webapp_projects:
268279
if not os.path.isdir(os.path.join(src_root, item)):
269280
logger.info("Deleting project {}".format(item))

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/ProjectsControllerTest.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ void testAdd() throws Exception {
199199
// Add the project.
200200
env.setScanningDepth(3);
201201

202-
addProject("mercurial");
202+
try (Response response = addProject("mercurial")) {
203+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
204+
}
203205

204206
// Check that the project was added properly.
205207
assertTrue(env.getProjects().containsKey("mercurial"));
@@ -224,7 +226,9 @@ void testAdd() throws Exception {
224226
// At the same time, it checks that multiple projects can be added
225227
// with single message.
226228

227-
addProject("git");
229+
try (Response response = addProject("git")) {
230+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
231+
}
228232

229233
assertEquals(2, env.getProjects().size());
230234
assertEquals(3, env.getRepositories().size());
@@ -370,7 +374,10 @@ private Response deleteProject(final String project) throws InterruptedException
370374
void testDeleteCache(boolean historyCache) throws Exception {
371375
final String cacheName = historyCache ? "historycache" : "annotationcache";
372376
final String projectName = "git";
373-
addProject(projectName);
377+
378+
try (Response response = addProject(projectName)) {
379+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
380+
}
374381

375382
Indexer.getInstance().prepareIndexer(
376383
env,
@@ -424,7 +431,9 @@ void testIndexed() throws Exception {
424431
String projectName = "mercurial";
425432

426433
// When a project is added, it should be marked as not indexed.
427-
addProject(projectName);
434+
try (Response response = addProject(projectName)) {
435+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
436+
}
428437

429438
assertFalse(env.getProjects().get(projectName).isIndexed());
430439

@@ -480,11 +489,15 @@ private Response markIndexed(final String project) throws InterruptedException {
480489

481490
@Test
482491
void testList() throws Exception {
483-
addProject("mercurial");
492+
try (Response response = addProject("mercurial")) {
493+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
494+
}
484495
assertEquals(markIndexed("mercurial").getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL);
485496

486497
// Add another project.
487-
addProject("git");
498+
try (Response response = addProject("git")) {
499+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
500+
}
488501

489502
GenericType<List<String>> type = new GenericType<>() {
490503
};
@@ -531,7 +544,9 @@ void testGetRepos() throws Exception {
531544
"clone", mercurialRoot.getAbsolutePath(),
532545
mercurialRoot.getAbsolutePath() + File.separator + "closed");
533546

534-
addProject("mercurial");
547+
try (Response response = addProject("mercurial")) {
548+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
549+
}
535550

536551
// Get repositories of the project.
537552
List<String> repos = target("projects")
@@ -565,7 +580,9 @@ void testGetRepos() throws Exception {
565580
@Test
566581
void testSetIndexed() throws Exception {
567582
String project = "git";
568-
addProject(project);
583+
try (Response response = addProject(project)) {
584+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
585+
}
569586
assertEquals(1, env.getProjectList().size());
570587

571588
env.getProjects().get(project).setIndexed(false);
@@ -585,7 +602,9 @@ void testSetGet() throws Exception {
585602
String[] projects = new String[] {"mercurial", "git"};
586603

587604
for (String proj : projects) {
588-
addProject(proj);
605+
try (Response response = addProject(proj)) {
606+
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
607+
}
589608
}
590609

591610
assertEquals(2, env.getProjectList().size());

0 commit comments

Comments
 (0)