Skip to content

Commit

Permalink
Empty reasons for code ownership scoring (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp authored Apr 8, 2024
1 parent 31d220f commit 96b9dfd
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public String getDescription() {

@Override
public long getVersion() {
return 1;
return 2;
}

@Override
protected boolean isSourceCodeRelated() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public int getWeight() {
return 10;
}
},
new ScoringComponent() {
new ScoringComponent() { // CodeOwnership
@Override
public String getDescription() {
return "Plugin should have a valid CODEOWNERS file.";
Expand All @@ -207,14 +207,41 @@ public String getDescription() {
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
final ProbeResult result = probeResults.get(CodeOwnershipProbe.KEY);
if (result == null || ProbeResult.Status.ERROR.equals(result.status())) {
return new ScoringComponentResult(0, getWeight(), List.of());
return new ScoringComponentResult(
0,
getWeight(),
List.of("Could not determine the plugins code ownership."),
List.of(
new Resolution(
"Please open a bug on plugin-health-scoring project.",
"https://github.com/jenkins-infra/plugin-health-scoring/issues/new/choose")));
}

return switch (result.message()) {
case "CODEOWNERS file is valid." -> new ScoringComponentResult(100, getWeight(), List.of());
case "CODEOWNERS file is valid." -> new ScoringComponentResult(
100, getWeight(), List.of("Code Ownership definition found and is valid."));
case "CODEOWNERS file is not set correctly." -> new ScoringComponentResult(
50, getWeight(), List.of());
default -> new ScoringComponentResult(0, getWeight(), List.of());
50,
getWeight(),
List.of("Code Ownership is not set properly."),
List.of(
new Resolution(
"Learn about code owners",
"https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners"),
new Resolution(
"See OpenRewrite recipe to fix this.",
"https://docs.openrewrite.org/recipes/jenkins/github/addteamtocodeowners")));
default -> new ScoringComponentResult(
0,
getWeight(),
List.of("Repository would benefit from defining the code ownership."),
List.of(
new Resolution(
"Learn about code owners",
"https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners"),
new Resolution(
"See OpenRewrite recipe to fix this.",
"https://docs.openrewrite.org/recipes/jenkins/github/addteamtocodeowners")));
};
}

Expand Down Expand Up @@ -244,6 +271,6 @@ public String description() {

@Override
public int version() {
return 4;
return 5;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ CodeOwnershipProbe getSpy() {
return spy(CodeOwnershipProbe.class);
}

@Test
void shouldRequiresCodeModifications() {
assertThat(getSpy().isSourceCodeRelated()).isTrue();
}

@Test
void shouldDetectMissingCodeOwnershipFile() throws IOException {
final Plugin plugin = mock(Plugin.class);
Expand Down
Loading

0 comments on commit 96b9dfd

Please sign in to comment.