diff --git a/InsightsBackend/pom.xml b/InsightsBackend/pom.xml
index d98bde8..0ae33ba 100644
--- a/InsightsBackend/pom.xml
+++ b/InsightsBackend/pom.xml
@@ -137,6 +137,15 @@
--enable-preview
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ local
+
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/GitHubProperties.java b/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/GitHubProperties.java
index 26bbe54..04da9e9 100644
--- a/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/GitHubProperties.java
+++ b/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/GitHubProperties.java
@@ -14,4 +14,5 @@ public class GitHubProperties {
private String url;
private String secret;
private List branchProtectionRegexes;
+ private Boolean fetch;
}
diff --git a/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/SystemDataInitializer.java b/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/SystemDataInitializer.java
index d83c8c4..c178981 100644
--- a/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/SystemDataInitializer.java
+++ b/InsightsBackend/src/main/java/org/frankframework/insights/common/configuration/SystemDataInitializer.java
@@ -18,7 +18,6 @@
@Configuration
@Slf4j
public class SystemDataInitializer implements CommandLineRunner {
-
private final GitHubRepositoryStatisticsService gitHubRepositoryStatisticsService;
private final LabelService labelService;
private final MilestoneService milestoneService;
@@ -27,6 +26,7 @@ public class SystemDataInitializer implements CommandLineRunner {
private final IssueService issueService;
private final PullRequestService pullRequestService;
private final ReleaseService releaseService;
+ private final Boolean gitHubFetchEnabled;
public SystemDataInitializer(
GitHubRepositoryStatisticsService gitHubRepositoryStatisticsService,
@@ -36,7 +36,8 @@ public SystemDataInitializer(
CommitService commitService,
IssueService issueService,
PullRequestService pullRequestService,
- ReleaseService releaseService) {
+ ReleaseService releaseService,
+ GitHubProperties gitHubProperties) {
this.gitHubRepositoryStatisticsService = gitHubRepositoryStatisticsService;
this.labelService = labelService;
this.milestoneService = milestoneService;
@@ -45,6 +46,7 @@ public SystemDataInitializer(
this.issueService = issueService;
this.pullRequestService = pullRequestService;
this.releaseService = releaseService;
+ this.gitHubFetchEnabled = gitHubProperties.getFetch();
}
@Override
@@ -56,7 +58,7 @@ public void run(String... args) {
initializeSystemData();
}
- @Scheduled(cron = "0 0 0 * * *")
+ @Scheduled(cron = "0 0 0 * * *")
@SchedulerLock(name = "dailyGitHubUpdate", lockAtMostFor = "PT2H", lockAtLeastFor = "PT30M")
public void dailyJob() {
log.info("Daily fetch job started");
@@ -67,6 +69,11 @@ public void dailyJob() {
@SchedulerLock(name = "fetchGitHubStatistics", lockAtMostFor = "PT10M")
public void fetchGitHubStatistics() {
try {
+ if (!gitHubFetchEnabled) {
+ log.info("Skipping GitHub fetch: skipping due to build/test configuration.");
+ return;
+ }
+
gitHubRepositoryStatisticsService.fetchRepositoryStatistics();
} catch (GitHubClientException e) {
log.error("Error fetching GitHub statistics", e);
@@ -76,6 +83,11 @@ public void fetchGitHubStatistics() {
@SchedulerLock(name = "initializeSystemData", lockAtMostFor = "PT2H")
public void initializeSystemData() {
try {
+ if (!gitHubFetchEnabled) {
+ log.info("Skipping GitHub fetch: skipping due to build/test configuration.");
+ return;
+ }
+
log.info("Start fetching all GitHub data");
labelService.injectLabels();
milestoneService.injectMilestones();
diff --git a/InsightsBackend/src/main/resources/application-local.properties b/InsightsBackend/src/main/resources/application-local.properties
new file mode 100644
index 0000000..11580ca
--- /dev/null
+++ b/InsightsBackend/src/main/resources/application-local.properties
@@ -0,0 +1,6 @@
+spring.datasource.url=jdbc:postgresql://localhost:5432/insights
+spring.datasource.username=postgres
+spring.datasource.password=postgres
+
+github.secret=dummytoken
+github.fetch=false
diff --git a/InsightsBackend/src/main/resources/application-production.properties b/InsightsBackend/src/main/resources/application-production.properties
new file mode 100644
index 0000000..79d7ee6
--- /dev/null
+++ b/InsightsBackend/src/main/resources/application-production.properties
@@ -0,0 +1,6 @@
+spring.datasource.url=jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
+spring.datasource.username=${DATABASE_USERNAME}
+spring.datasource.password=${DATABASE_PASSWORD}
+
+github.secret=${GITHUB_API_SECRET}
+github.fetch=true
diff --git a/InsightsBackend/src/main/resources/application.properties b/InsightsBackend/src/main/resources/application.properties
index 6572bc8..adb5ad9 100644
--- a/InsightsBackend/src/main/resources/application.properties
+++ b/InsightsBackend/src/main/resources/application.properties
@@ -1,18 +1,12 @@
spring.application.name=insights
-spring.profiles.active=production
spring.config.import=optional:file:.env[.properties]
-spring.datasource.url=jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
-spring.datasource.username=${DATABASE_USERNAME}
-spring.datasource.password=${DATABASE_PASSWORD}
-spring.datasource.driver-class-name=org.postgresql.Driver
-spring.datasource.hikari.auto-commit=false
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
-spring.sql.init.mode=always
+
+spring.datasource.driver-class-name=org.postgresql.Driver
github.url=https://api.github.com/graphql
-github.secret=${GITHUB_API_SECRET}
github.branchProtectionRegexes[0]=master
github.branchProtectionRegexes[1]=release
diff --git a/InsightsBackend/src/test/java/org/frankframework/insights/InsightsApplicationTests.java b/InsightsBackend/src/test/java/org/frankframework/insights/InsightsApplicationTests.java
deleted file mode 100644
index 6b697d1..0000000
--- a/InsightsBackend/src/test/java/org/frankframework/insights/InsightsApplicationTests.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.frankframework.insights;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class InsightsApplicationTests {
-
- @Test
- public void contextLoads() {}
-}
diff --git a/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockLocalTest.java b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockLocalTest.java
new file mode 100644
index 0000000..018cb9f
--- /dev/null
+++ b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockLocalTest.java
@@ -0,0 +1,94 @@
+package org.frankframework.insights.shedlock;
+
+import net.javacrumbs.shedlock.core.LockAssert;
+
+import org.frankframework.insights.branch.BranchService;
+import org.frankframework.insights.commit.CommitService;
+import org.frankframework.insights.common.configuration.GitHubProperties;
+import org.frankframework.insights.common.configuration.SystemDataInitializer;
+import org.frankframework.insights.github.GitHubRepositoryStatisticsService;
+import org.frankframework.insights.issue.IssueService;
+import org.frankframework.insights.label.LabelService;
+import org.frankframework.insights.milestone.MilestoneService;
+import org.frankframework.insights.pullrequest.PullRequestService;
+import org.frankframework.insights.release.ReleaseService;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+
+import javax.sql.DataSource;
+
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+@ActiveProfiles("local")
+@ExtendWith(MockitoExtension.class)
+public class ShedLockLocalTest {
+ @Mock
+ private DataSource dataSource;
+
+ @Mock
+ private GitHubRepositoryStatisticsService gitHubRepositoryStatisticsService;
+
+ @Mock
+ private LabelService labelService;
+
+ @Mock
+ private MilestoneService milestoneService;
+
+ @Mock
+ private BranchService branchService;
+
+ @Mock
+ private CommitService commitService;
+
+ @Mock
+ private IssueService issueService;
+
+ @Mock
+ private PullRequestService pullRequestService;
+
+ @Mock
+ private ReleaseService releaseService;
+
+ @Mock
+ private GitHubProperties gitHubProperties;
+
+ private SystemDataInitializer systemDataInitializer;
+
+ @BeforeEach
+ public void setUp() {
+ when(gitHubProperties.getFetch()).thenReturn(false);
+
+ systemDataInitializer = new SystemDataInitializer(
+ gitHubRepositoryStatisticsService,
+ labelService,
+ milestoneService,
+ branchService,
+ commitService,
+ issueService,
+ pullRequestService,
+ releaseService,
+ gitHubProperties);
+
+ LockAssert.TestHelper.makeAllAssertsPass(true);
+ }
+
+ @Test
+ public void should_SkipGitHubFetch_when_LocalProfileIsActive() {
+ systemDataInitializer.run();
+
+ verifyNoInteractions(gitHubRepositoryStatisticsService);
+ verifyNoInteractions(labelService);
+ verifyNoInteractions(milestoneService);
+ verifyNoInteractions(branchService);
+ verifyNoInteractions(commitService);
+ verifyNoInteractions(issueService);
+ verifyNoInteractions(pullRequestService);
+ verifyNoInteractions(releaseService);
+ }
+}
diff --git a/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockProductionTest.java b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockProductionTest.java
new file mode 100644
index 0000000..92eb21a
--- /dev/null
+++ b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockProductionTest.java
@@ -0,0 +1,103 @@
+package org.frankframework.insights.shedlock;
+
+import net.javacrumbs.shedlock.core.LockAssert;
+
+import org.frankframework.insights.branch.BranchInjectionException;
+import org.frankframework.insights.branch.BranchService;
+import org.frankframework.insights.commit.CommitInjectionException;
+import org.frankframework.insights.commit.CommitService;
+import org.frankframework.insights.common.configuration.GitHubProperties;
+import org.frankframework.insights.common.configuration.SystemDataInitializer;
+import org.frankframework.insights.github.GitHubClientException;
+import org.frankframework.insights.github.GitHubRepositoryStatisticsService;
+import org.frankframework.insights.issue.IssueInjectionException;
+import org.frankframework.insights.issue.IssueService;
+import org.frankframework.insights.label.LabelInjectionException;
+import org.frankframework.insights.label.LabelService;
+import org.frankframework.insights.milestone.MilestoneInjectionException;
+import org.frankframework.insights.milestone.MilestoneService;
+import org.frankframework.insights.pullrequest.PullRequestInjectionException;
+import org.frankframework.insights.pullrequest.PullRequestService;
+import org.frankframework.insights.release.ReleaseInjectionException;
+import org.frankframework.insights.release.ReleaseService;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+
+import javax.sql.DataSource;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ActiveProfiles("production")
+@ExtendWith(MockitoExtension.class)
+public class ShedLockProductionTest {
+ @Mock
+ private DataSource dataSource;
+
+ @Mock
+ private GitHubRepositoryStatisticsService gitHubRepositoryStatisticsService;
+
+ @Mock
+ private LabelService labelService;
+
+ @Mock
+ private MilestoneService milestoneService;
+
+ @Mock
+ private BranchService branchService;
+
+ @Mock
+ private CommitService commitService;
+
+ @Mock
+ private IssueService issueService;
+
+ @Mock
+ private PullRequestService pullRequestService;
+
+ @Mock
+ private ReleaseService releaseService;
+
+ @Mock
+ private GitHubProperties gitHubProperties;
+
+ private SystemDataInitializer systemDataInitializer;
+
+ @BeforeEach
+ public void setUp() {
+ when(gitHubProperties.getFetch()).thenReturn(true);
+
+ systemDataInitializer = new SystemDataInitializer(
+ gitHubRepositoryStatisticsService,
+ labelService,
+ milestoneService,
+ branchService,
+ commitService,
+ issueService,
+ pullRequestService,
+ releaseService,
+ gitHubProperties);
+
+ LockAssert.TestHelper.makeAllAssertsPass(true);
+ }
+
+ @Test
+ public void should_FetchGitHubData_when_ProductionProfileIsActive() throws LabelInjectionException, GitHubClientException, MilestoneInjectionException, BranchInjectionException, ReleaseInjectionException, CommitInjectionException, IssueInjectionException, PullRequestInjectionException {
+ systemDataInitializer.run();
+
+ verify(gitHubRepositoryStatisticsService, times(1)).fetchRepositoryStatistics();
+ verify(labelService, times(1)).injectLabels();
+ verify(milestoneService, times(1)).injectMilestones();
+ verify(branchService, times(1)).injectBranches();
+ verify(commitService, times(1)).injectBranchCommits();
+ verify(issueService, times(1)).injectIssues();
+ verify(pullRequestService, times(1)).injectBranchPullRequests();
+ verify(releaseService, times(1)).injectReleases();
+ }
+}
diff --git a/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockTest.java b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockTest.java
index b3a6bd7..aa3a6ea 100644
--- a/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockTest.java
+++ b/InsightsBackend/src/test/java/org/frankframework/insights/shedlock/ShedLockTest.java
@@ -10,8 +10,10 @@
import javax.sql.DataSource;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
+
import org.frankframework.insights.branch.BranchService;
import org.frankframework.insights.commit.CommitService;
+import org.frankframework.insights.common.configuration.GitHubProperties;
import org.frankframework.insights.common.configuration.ShedLockConfiguration;
import org.frankframework.insights.common.configuration.SystemDataInitializer;
import org.frankframework.insights.github.GitHubRepositoryStatisticsService;
@@ -47,14 +49,17 @@ public class ShedLockTest {
@Mock
private CommitService commitService;
- @Mock
- private ReleaseService releaseService;
+ @Mock
+ private IssueService issueService;
- @Mock
- private IssueService issueService;
+ @Mock
+ private PullRequestService pullRequestService;
@Mock
- private PullRequestService pullRequestService;
+ private ReleaseService releaseService;
+
+ @Mock
+ private GitHubProperties gitHubProperties;
private SystemDataInitializer systemDataInitializer;
@@ -66,9 +71,10 @@ public void setUp() {
milestoneService,
branchService,
commitService,
- issueService,
- pullRequestService,
- releaseService);
+ issueService,
+ pullRequestService,
+ releaseService,
+ gitHubProperties);
LockAssert.TestHelper.makeAllAssertsPass(true);
}