Skip to content

Commit

Permalink
Inheriting contributing guide should not lower score (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp committed Mar 22, 2024
1 parent 5fdf303 commit 3ad8bba
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Jenkins Infra
* Copyright (c) 2022-2024 Jenkins Infra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,7 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.jenkins.pluginhealth.scoring.probes;

import java.io.IOException;
Expand All @@ -48,13 +47,19 @@ protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
}

final Path repository = context.getScmRepository().get();
try (Stream<Path> paths = Files.find(repository, 2,
(file, basicFileAttributes) -> Files.isReadable(file)
&& ("CONTRIBUTING.md".equalsIgnoreCase(file.getFileName().toString())
|| "CONTRIBUTING.adoc".equalsIgnoreCase(file.getFileName().toString())))) {
try (Stream<Path> paths = Files.find(
repository,
2,
(file, basicFileAttributes) -> Files.isReadable(file)
&& ("CONTRIBUTING.md"
.equalsIgnoreCase(file.getFileName().toString())
|| "CONTRIBUTING.adoc"
.equalsIgnoreCase(file.getFileName().toString())))) {
return paths.findAny()
.map(file -> this.success("Contributing guidelines found."))
.orElseGet(() -> this.success("No contributing guidelines found."));
.map(file -> file.toFile().length() != 0
? this.success("Contributing guidelines found.")
: this.success("Contributing guide seems to be empty."))
.orElseGet(() -> this.success("Inherit from organization contributing guide."));
} catch (IOException e) {
return this.error(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024 Jenkins Infra
* Copyright (c) 2022-2024 Jenkins Infra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,7 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.jenkins.pluginhealth.scoring.scores;

import java.util.List;
Expand Down Expand Up @@ -61,145 +60,153 @@ public String description() {
@Override
public List<ScoringComponent> getComponents() {
return List.of(
new ScoringComponent() {
@Override
public String getDescription() {
return "The plugin has a specific contributing guide.";
}

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
ProbeResult probeResult = probeResults.get(ContributingGuidelinesProbe.KEY);
if (probeResult != null && "Contributing guidelines found.".equals(probeResult.message())) {
return new ScoringComponentResult(100, getWeight(), List.of("Plugin has a contributing guide."));
}
return new ScoringComponentResult(
0,
getWeight(),
List.of("The plugin relies on the global contributing guide."),
List.of(new Resolution(
"See why and how to add a contributing guide",
"https://www.jenkins.io/doc/developer/tutorial-improve/add-a-contributing-guide/"
))
);
}

@Override
public int getWeight() {
return 2;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Plugin documentation should be migrated from the wiki.";
}

@Override
public ScoringComponentResult getScore(Plugin $, Map<String, ProbeResult> probeResults) {
final ProbeResult probeResult = probeResults.get(DocumentationMigrationProbe.KEY);
if (probeResult == null || ProbeResult.Status.ERROR.equals(probeResult.status())) {
return new ScoringComponentResult(0, getWeight(), List.of("Cannot confirm or not the documentation migration."));
new ScoringComponent() {
@Override
public String getDescription() {
return "The plugin should have a specific contributing guide.";
}
return switch (probeResult.message()) {
case "Documentation is located in the plugin repository." ->
new ScoringComponentResult(100, getWeight(), List.of("Documentation is in plugin repository."));
case "Documentation is not located in the plugin repository." -> new ScoringComponentResult(
0,
getWeight(),
List.of("Documentation should be migrated in plugin repository."),
List.of(
new Resolution("https://www.jenkins.io/doc/developer/tutorial-improve/migrate-documentation-to-github/")
)
);
default ->
new ScoringComponentResult(0, getWeight(), List.of("Cannot confirm or not the documentation migration.", probeResult.message()));
};
}

@Override
public int getWeight() {
return 4;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Recommend to setup Release Drafter on the plugin repository.";
}

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
ProbeResult cdProbe = probeResults.get(ContinuousDeliveryProbe.KEY);
if (cdProbe != null && "JEP-229 workflow definition found.".equals(cdProbe.message())) {

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
ProbeResult probeResult = probeResults.get(ContributingGuidelinesProbe.KEY);
if (probeResult == null || ProbeResult.Status.ERROR.equals(probeResult.status())) {
return new ScoringComponentResult(
0, getWeight(), List.of("Cannot determine if the plugin has contributing guide."));
}
if ("Inherit from organization contributing guide.".equals(probeResult.message())) {
return new ScoringComponentResult(
100, 0, List.of("Plugin is inheriting the organization contributing guide."));
}
if ("Contributing guidelines found.".equals(probeResult.message())) {
return new ScoringComponentResult(
100, getWeight(), List.of("Plugin seems to have a dedicated contributing guide."));
}
return new ScoringComponentResult(
100,
getWeight(),
List.of("Plugin using Release Drafter because it has CD configured.")
);
0,
getWeight(),
List.of("The plugin relies on the global contributing guide."),
List.of(
new Resolution(
"See why and how to add a contributing guide",
"https://www.jenkins.io/doc/developer/tutorial-improve/add-a-contributing-guide/")));
}

@Override
public int getWeight() {
return 2;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Plugin documentation should be migrated from the wiki.";
}

@Override
public ScoringComponentResult getScore(Plugin $, Map<String, ProbeResult> probeResults) {
final ProbeResult probeResult = probeResults.get(DocumentationMigrationProbe.KEY);
if (probeResult == null || ProbeResult.Status.ERROR.equals(probeResult.status())) {
return new ScoringComponentResult(
0, getWeight(), List.of("Cannot confirm or not the documentation migration."));
}
return switch (probeResult.message()) {
case "Documentation is located in the plugin repository." -> new ScoringComponentResult(
100, getWeight(), List.of("Documentation is in plugin repository."));
case "Documentation is not located in the plugin repository." -> new ScoringComponentResult(
0,
getWeight(),
List.of("Documentation should be migrated in plugin repository."),
List.of(
new Resolution(
"https://www.jenkins.io/doc/developer/tutorial-improve/migrate-documentation-to-github/")));
default -> new ScoringComponentResult(
0,
getWeight(),
List.of(
"Cannot confirm or not the documentation migration.",
probeResult.message()));
};
}
ProbeResult result = probeResults.get(ReleaseDrafterProbe.KEY);
if (result != null && "Release Drafter is configured.".equals(result.message())) {

@Override
public int getWeight() {
return 4;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Recommend to setup Release Drafter on the plugin repository.";
}

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
ProbeResult cdProbe = probeResults.get(ContinuousDeliveryProbe.KEY);
if (cdProbe != null && "JEP-229 workflow definition found.".equals(cdProbe.message())) {
return new ScoringComponentResult(
100,
getWeight(),
List.of("Plugin using Release Drafter because it has CD configured."));
}
ProbeResult result = probeResults.get(ReleaseDrafterProbe.KEY);
if (result != null && "Release Drafter is configured.".equals(result.message())) {
return new ScoringComponentResult(
100, getWeight(), List.of("Plugin is using Release Drafter."));
}
return new ScoringComponentResult(
100,
getWeight(),
List.of("Plugin is using Release Drafter.")
);
0,
0,
List.of("Plugin is not using Release Drafter to manage its changelog."),
List.of(
new Resolution(
"Plugin could benefit from using Release Drafter.",
"https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc")));
}
return new ScoringComponentResult(
0,
0,
List.of("Plugin is not using Release Drafter to manage its changelog."),
List.of(new Resolution(
"Plugin could benefit from using Release Drafter.",
"https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc"
))
);
}

@Override
public int getWeight() {
return 0;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Plugin description should be located in the index.jelly file.";
}

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
final ProbeResult result = probeResults.get(PluginDescriptionMigrationProbe.KEY);
if (result == null || ProbeResult.Status.ERROR.equals(result.status())) {

@Override
public int getWeight() {
return 0;
}
},
new ScoringComponent() {
@Override
public String getDescription() {
return "Plugin description should be located in the index.jelly file.";
}

@Override
public ScoringComponentResult getScore(Plugin plugin, Map<String, ProbeResult> probeResults) {
final ProbeResult result = probeResults.get(PluginDescriptionMigrationProbe.KEY);
if (result == null || ProbeResult.Status.ERROR.equals(result.status())) {
return new ScoringComponentResult(
0,
getWeight(),
List.of("Cannot determine if the plugin description was correctly migrated."));
}

final String message = result.message();
if ("Plugin seems to have a correct description.".equals(message)) {
return new ScoringComponentResult(100, getWeight(), List.of(message));
}
return new ScoringComponentResult(
0,
getWeight(),
List.of("Cannot determine if the plugin description was correctly migrated.")
);
0,
getWeight(),
List.of(message),
List.of(
new Resolution(
"Please see how to migrate the plugin description for the plugin.",
"https://www.jenkins.io/doc/developer/tutorial-improve/move-description-to-index/")));
}

final String message = result.message();
if ("Plugin seems to have a correct description.".equals(message)) {
return new ScoringComponentResult(100, getWeight(), List.of(message));
@Override
public int getWeight() {
return 4;
}
return new ScoringComponentResult(0, getWeight(), List.of(message),
List.of(new Resolution(
"Please see how to migrate the plugin description for the plugin.",
"https://www.jenkins.io/doc/developer/tutorial-improve/move-description-to-index/"
)));
}

@Override
public int getWeight() {
return 4;
}
}
);
});
}

@Override
public int version() {
return 2;
return 3;
}
}
Loading

0 comments on commit 3ad8bba

Please sign in to comment.