Skip to content

Commit

Permalink
Better detect dependency bot configuration file in plugin repository (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp authored Jan 16, 2024
1 parent 31fa5e4 commit f1d9d9c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
}

try (Stream<Path> paths = Files.find(githubConfig, 1, (path, $) ->
Files.isRegularFile(path) && path.getFileName().toString().startsWith(getBotName()))) {
Files.isRegularFile(path) && isPathBotConfigFile(path.getFileName().toString()))) {
return paths.findFirst()
.map(file -> this.success(String.format("%s is configured.", capitalize(getBotName()))))
.orElseGet(() -> this.success(String.format("%s is not configured.", capitalize(getBotName()))));
Expand All @@ -77,6 +77,14 @@ private String capitalize(String str) {
*/
protected abstract String getBotName();

/**
* Tests if the provided filename is the same as the bot configuration filename.
*
* @param filename the path
* @return true if the filename is the same as the required bot configuration filename.
*/
protected abstract boolean isPathBotConfigFile(String filename);

@Override
protected boolean isSourceCodeRelated() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected String getBotName() {
return KEY;
}

@Override
protected boolean isPathBotConfigFile(String filename) {
return "dependabot.yml".equals(filename) || "dependabot.yaml".equals(filename);
}

@Override
public String key() {
return KEY;
Expand All @@ -52,6 +57,6 @@ public String getDescription() {

@Override
public long getVersion() {
return 1;
return 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected String getBotName() {
return KEY;
}

@Override
protected boolean isPathBotConfigFile(String filename) {
return "renovate.json".equals(filename);
}

@Override
public String key() {
return KEY;
Expand All @@ -28,6 +33,6 @@ public String getDescription() {

@Override
public long getVersion() {
return 1;
return 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ public String description() {

@Override
public int version() {
return 1;
return 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,23 @@ void shouldDetectDependabotFile() throws Exception {
.isEqualTo(ProbeResult.success(DependabotProbe.KEY, "Dependabot is configured.", probe.getVersion()));
verify(probe).doApply(any(Plugin.class), any(ProbeContext.class));
}

@Test
void shouldDetectDependabotFileWithFullFileExtension() throws Exception {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);
final DependabotProbe probe = getSpy();

final Path repo = Files.createTempDirectory("foo");
final Path github = Files.createDirectories(repo.resolve(".github"));

Files.createFile(github.resolve("dependabot.yaml"));
when(ctx.getScmRepository()).thenReturn(Optional.of(repo));

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "message", "status")
.isEqualTo(ProbeResult.success(DependabotProbe.KEY, "Dependabot is configured.", probe.getVersion()));
verify(probe).doApply(any(Plugin.class), any(ProbeContext.class));
}
}

0 comments on commit f1d9d9c

Please sign in to comment.