Skip to content

Commit

Permalink
Creates method to get dependency bot name (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp authored Aug 9, 2023
1 parent 333e802 commit a4d1c53
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ public abstract class AbstractDependencyBotConfigurationProbe extends Probe {
public static final int ORDER = LastCommitDateProbe.ORDER + 100;
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDependencyBotConfigurationProbe.class);

private final String botName;

/**
* The constructor gets initialized with botName when extended.
*
* @param botName A "botName" is the name of a dependency bot for ex: dependabot, renovate bot, etc
*/
AbstractDependencyBotConfigurationProbe(String botName) {
this.botName = botName;
}

@Override
protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
final Path scmRepository = context.getScmRepository();
Expand All @@ -63,23 +52,31 @@ protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
}

try (Stream<Path> paths = Files.find(githubConfig, 1, (path, $) ->
Files.isRegularFile(path) && path.getFileName().toString().startsWith(botName))) {
Files.isRegularFile(path) && path.getFileName().toString().startsWith(getBotName()))) {
return paths.findFirst()
.map(file -> ProbeResult.success(key(), String.format("%s is configured", botName)))
.orElseGet(() -> ProbeResult.failure(key(), String.format("%s is not configured", botName)));
.map(file -> ProbeResult.success(key(), String.format("%s is configured", getBotName())))
.orElseGet(() -> ProbeResult.failure(key(), String.format("%s is not configured", getBotName())));
} catch (IOException ex) {
LOGGER.error("Could not browse the plugin folder during probe {}", key(), ex);
return ProbeResult.error(key(), "Could not browse the plugin folder");
}
}

/**
* Provides the name of the bot.
* This is normally the name of the file
*
* @return a "botName" is the name of a dependency bot for ex: dependabot, renovate bot, etc
*/
protected abstract String getBotName();

@Override
protected boolean isSourceCodeRelated() {
return true;
}

@Override
public String[] getProbeResultRequirement() {
return new String[]{SCMLinkValidationProbe.KEY, LastCommitDateProbe.KEY};
return new String[] { SCMLinkValidationProbe.KEY, LastCommitDateProbe.KEY };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@

/**
* This probe looks for Dependabot configuration in a plugin.
*
* @see io.jenkins.pluginhealth.scoring.probes.AbstractDependencyBotConfigurationProbe
*/
@Component
@Order(AbstractDependencyBotConfigurationProbe.ORDER)
public class DependabotProbe extends AbstractDependencyBotConfigurationProbe {
public static final String KEY = "dependabot";

DependabotProbe() {
super(KEY);
@Override
protected String getBotName() {
return KEY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import org.springframework.stereotype.Component;

/**
* Looks for Renovate bot configuration in a plugin.
*
* @see io.jenkins.pluginhealth.scoring.probes.AbstractDependencyBotConfigurationProbe
*/
* Looks for Renovate bot configuration in a plugin.
*/
@Component
@Order(AbstractDependencyBotConfigurationProbe.ORDER)
public class RenovateProbe extends AbstractDependencyBotConfigurationProbe {
public static final String KEY = "renovate";

RenovateProbe() {
super(KEY);
@Override
protected String getBotName() {
return KEY;
}

@Override
Expand Down

0 comments on commit a4d1c53

Please sign in to comment.