From 8c59f974ddd1ddd2acacf005b28bb5935a0e6923 Mon Sep 17 00:00:00 2001 From: Adrien Lecharpentier Date: Tue, 10 Oct 2023 14:34:28 +0200 Subject: [PATCH] Prevents executing probes on plugin with no scm configured (#381) --- .../pluginhealth/scoring/probes/ProbeEngine.java | 4 ++++ .../pluginhealth/scoring/probes/ProbeEngineTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/war/src/main/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngine.java b/war/src/main/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngine.java index a88d14f9f..c46de8cba 100644 --- a/war/src/main/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngine.java +++ b/war/src/main/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngine.java @@ -89,6 +89,10 @@ public void runOn(Plugin plugin) throws IOException { } private void runOn(Plugin plugin, UpdateCenter updateCenter) { + if (plugin.getScm() == null || plugin.getScm().isBlank()) { + LOGGER.info("Will not run probes on {} because its SCM is not set correctly.", plugin.getName()); + return; + } final ProbeContext probeContext; try { probeContext = probeService.getProbeContext(plugin, updateCenter); diff --git a/war/src/test/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngineTest.java b/war/src/test/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngineTest.java index bcd636842..ddf9afd83 100644 --- a/war/src/test/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngineTest.java +++ b/war/src/test/java/io/jenkins/pluginhealth/scoring/probes/ProbeEngineTest.java @@ -82,6 +82,7 @@ void shouldBeAbleToRunSimpleProbe() throws IOException { final ProbeResult expectedResult = ProbeResult.success("foo", "bar", 1); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getDetails()).thenReturn(Map.of()); when(probe.key()).thenReturn("probe"); when(probe.doApply(plugin, ctx)).thenReturn(expectedResult); @@ -105,6 +106,7 @@ void shouldNotApplyProbeWithReleaseRequirementOnPluginWithNoNewReleaseWithPastRe final Probe probe = spy(Probe.class); final ProbeContext ctx = mock(ProbeContext.class); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getName()).thenReturn("foo"); when(plugin.getReleaseTimestamp()).thenReturn(ZonedDateTime.now().minusDays(1)); when(plugin.getDetails()).thenReturn(Map.of(probeKey, ProbeResult.success(probeKey, "This is good", 1))); @@ -130,6 +132,7 @@ void shouldNotApplyProbeRelatedToCodeWithNoNewCode() throws IOException { final Probe probe = spy(Probe.class); final ProbeContext ctx = mock(ProbeContext.class); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getDetails()).thenReturn(Map.of( "probe", new ProbeResult("probe", "message", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1) )); @@ -159,6 +162,7 @@ void shouldApplyProbeRelatedToCodeWithNewCommit() throws IOException { final ProbeResult result = new ProbeResult(probeKey, "message", ProbeResult.Status.SUCCESS, 1); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getDetails()).thenReturn(Map.of( probeKey, new ProbeResult(probeKey, "message", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1) )); @@ -189,6 +193,7 @@ void shouldApplyProbeWithReleaseRequirementOnPluginWithNewReleaseAndPastResult() final Probe probe = spy(Probe.class); final ProbeContext ctx = mock(ProbeContext.class); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getReleaseTimestamp()).thenReturn(ZonedDateTime.now()); when(plugin.getDetails()).thenReturn(Map.of(probeKey, new ProbeResult(probeKey, "this is ok", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1))); @@ -215,6 +220,7 @@ void shouldApplyProbeWithNoReleaseRequirementOnPluginWithPastResult() throws IOE final Probe probe = spy(Probe.class); final ProbeContext ctx = mock(ProbeContext.class); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getDetails()).thenReturn(Map.of( probeKey, new ProbeResult(probeKey, "this is ok", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1) @@ -242,6 +248,7 @@ void shouldSaveEvenErrors() throws IOException { final Probe probe = spy(Probe.class); final ProbeContext ctx = mock(ProbeContext.class); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(probe.doApply(plugin, ctx)).thenReturn(ProbeResult.error("foo", "bar", 1)); when(probeService.getProbeContext(any(Plugin.class), any(UpdateCenter.class))).thenReturn(ctx); @@ -290,6 +297,8 @@ public long getVersion() { when(probeService.getProbes()).thenReturn(List.of(probeOne, probeTwo)); when(pluginService.streamAll()).thenReturn(Stream.of(plugin)); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); + final ProbeEngine probeEngine = new ProbeEngine(probeService, pluginService, updateCenterService, gitHub, pluginDocumentationService); probeEngine.run(); @@ -335,6 +344,7 @@ protected boolean isSourceCodeRelated() { final ProbeContext ctx = mock(ProbeContext.class); final ProbeResult previousResult = new ProbeResult(probeKey, "this is a message", ProbeResult.Status.SUCCESS, version); + when(plugin.getScm()).thenReturn("this-is-ok-for-testing"); when(plugin.getDetails()).thenReturn(Map.of( probeKey, previousResult ));