Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of open issue probe #353

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2773dcf
Fetched issue tracker from update center
Jagrutiti Jul 23, 2023
68aa505
Removed issueTracker from models
Jagrutiti Jul 24, 2023
54a82a3
Modified the existing test cases that were affected and updated then …
Jagrutiti Jul 24, 2023
abb1001
Fixing checkstyle issues
Jagrutiti Jul 24, 2023
4d8ae5d
Fixing checkstyle issues
Jagrutiti Jul 24, 2023
c4c1605
Updated probe names and added java docs
Jagrutiti Jul 24, 2023
99d9cf5
Added test and code to count open GitHub issues
Jagrutiti Jul 29, 2023
719c57d
Added test code and completed the test case
Jagrutiti Jul 30, 2023
925afa3
Removed conficting dependencies
Jagrutiti Jul 30, 2023
58b135a
Fixed incorrect artifact name
Jagrutiti Jul 30, 2023
c71a32a
Merge branch 'main' into feature/open-issue-probe
Jagrutiti Jul 30, 2023
5fd8b2d
Fixed JIRA API calling
Jagrutiti Aug 1, 2023
6f9ede3
Merge branch 'main' into feature/open-issue-probe
Jagrutiti Aug 1, 2023
1a54932
Added IssueTrackerDetectionProbe
Jagrutiti Aug 2, 2023
4a144e5
Update IssueTrackerDetectionProbe and added a test for the same
Jagrutiti Aug 5, 2023
d3fd18b
Added abstract probe class and jira and github issues count probe
Jagrutiti Aug 5, 2023
d960448
Fixing checkstyle issues
Jagrutiti Aug 5, 2023
eda1b13
Fixed the test case for open jira issues count
Jagrutiti Aug 6, 2023
97aed28
Removing the issueTracker field from update center
Jagrutiti Aug 6, 2023
528ab43
Added a narrowed depedency in pom file and removed unwanted mock in …
Jagrutiti Aug 6, 2023
5f22f38
Added more test case for IssueTrackerDetectionProbe
Jagrutiti Aug 6, 2023
e13f3a8
Fixed checkstyle issues
Jagrutiti Aug 6, 2023
9bcb49e
Adding more test case for jira open issues
Jagrutiti Aug 6, 2023
4989e81
Apply suggestions from code review
Jagrutiti Aug 8, 2023
7db7e7a
Fixed the abstract class and updated test cases
Jagrutiti Aug 9, 2023
e45ce77
Updated the test cases
Jagrutiti Aug 9, 2023
510d340
Modifying the abstract class to make it better
Jagrutiti Aug 9, 2023
3cf7406
Refactored code in GitHub open issues probe
Jagrutiti Aug 12, 2023
b9cda9c
Restructured IssueTrackerDetectionProbe and improved its readability
Jagrutiti Aug 13, 2023
37884d5
Added a new test case for IssueTrackerDertectionProbe
Jagrutiti Aug 13, 2023
898c86c
Refactored code, test cases, fixed border cases
Jagrutiti Aug 13, 2023
fdd1a4e
Updating IssueTrackerDetectionProbe ORDER
Jagrutiti Aug 13, 2023
1940e67
Fixed method names
Jagrutiti Aug 14, 2023
151df0d
Merge branch 'main' into feature/open-issue-probe
Jagrutiti Aug 14, 2023
12ef4aa
Removed unused imports
Jagrutiti Aug 14, 2023
7f6cb04
Merge branch 'feature/open-issue-probe' of https://github.com/Jagruti…
Jagrutiti Aug 14, 2023
6a7214a
Fixed JavaDocs
Jagrutiti Aug 15, 2023
8e0f12a
Update core/src/main/java/io/jenkins/pluginhealth/scoring/probes/GitH…
Jagrutiti Aug 19, 2023
12db24b
Removed unwanted dependencies and fixed log statements
Jagrutiti Aug 19, 2023
793114b
Adding a comment
Jagrutiti Aug 22, 2023
e13b17e
Update core/src/test/java/io/jenkins/pluginhealth/scoring/probes/GitH…
Jagrutiti Aug 23, 2023
f4ef76e
Made minor changes based on code review
Jagrutiti Aug 23, 2023
1e194e9
Merge branch 'feature/open-issue-probe' of https://github.com/Jagruti…
Jagrutiti Aug 23, 2023
d9fad0c
Adding null checks
Jagrutiti Aug 24, 2023
663282c
Apply suggestions from code review
Jagrutiti Sep 6, 2023
c099e40
Fixed foramatting, updated library uses based on code review
Jagrutiti Sep 6, 2023
ec28408
Updated syntax for null check
Jagrutiti Sep 6, 2023
6a740d2
Merge branch 'main' into feature/open-issue-probe
Jagrutiti Sep 7, 2023
9244d60
Fixing merge issues
Jagrutiti Sep 7, 2023
b722a87
Fixing checkstyle issues
Jagrutiti Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -61,18 +62,26 @@ public class Plugin {
@Column(name = "release_timestamp")
private ZonedDateTime releaseTimestamp;

public List<Map<String, String>> getIssueTracker() {
return issueTracker;
}

@Column(name = "issue_tracker")
private List<Map<String, String>> issueTracker;

@Column(columnDefinition = "jsonb")
@Type(value = JsonType.class)
private final Map<String, ProbeResult> details = new HashMap<>();

public Plugin() {
}

public Plugin(String name, VersionNumber version, String scm, ZonedDateTime releaseTimestamp) {
public Plugin(String name, VersionNumber version, String scm, ZonedDateTime releaseTimestamp, List<Map<String, String>> issueTrackers) {
this.name = name;
this.version = version;
this.scm = scm;
this.releaseTimestamp = releaseTimestamp;
this.issueTracker = issueTrackers;
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;

import hudson.util.VersionNumber;

public record Plugin(String name, VersionNumber version, String scm,
ZonedDateTime releaseTimestamp, List<String> labels,
int popularity, String requiredCore, String defaultBranch) {
int popularity, String requiredCore, String defaultBranch, List<Map<String, String>> issueTrackers) {
public io.jenkins.pluginhealth.scoring.model.Plugin toPlugin() {
return new io.jenkins.pluginhealth.scoring.model.Plugin(this.name(), this.version(), this.scm(), this.releaseTimestamp());
return new io.jenkins.pluginhealth.scoring.model.Plugin(this.name(), this.version(), this.scm(), this.releaseTimestamp(), this.issueTrackers());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.jenkins.pluginhealth.scoring.probes;

import java.util.*;
import java.util.stream.Collectors;

import io.jenkins.pluginhealth.scoring.model.Plugin;
import io.jenkins.pluginhealth.scoring.model.ProbeResult;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value = OpenIssuesProbe.ORDER)
public class OpenIssuesProbe extends Probe {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenIssuesProbe.class);

public static final String KEY = "open-issue";
public static final int ORDER = UpdateCenterPluginPublicationProbe.ORDER + 100;

@Override
protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
List<String> issueTracker = getIssueTracker(plugin, context);
for (String type: issueTracker) {
if(type.equals("jira")) {
return ProbeResult.success(key(), String.format("%d open issues found", getJiraIssues()));
}
else if (type.equals("github")) {
return ProbeResult.success(key(), String.format("%d open issues found", getGitHubIssues()));
}
}
return ProbeResult.failure(key(), String.format("Update center issue tracker could not be found"));
}

private static List<String> getIssueTracker(Plugin plugin, ProbeContext context) {
return context.getUpdateCenter().plugins()
.get(plugin.getIssueTracker())
.issueTrackers().stream()
.flatMap(map -> map.entrySet().stream())
.filter(entry -> entry.getKey().equals("type"))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
}

private static int getJiraIssues() {
return 0;
}

private static int getGitHubIssues() {
return 0;
}


@Override
public String key() {
return KEY;
}

@Override
public String getDescription() {
return "Returns the number of issues open in a plugin";
}

@Override
public String[] getProbeResultRequirement() {
return new String[]{UpdateCenterPluginPublicationProbe.KEY};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.jenkins.pluginhealth.scoring.probes;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import java.util.Map;

import io.jenkins.pluginhealth.scoring.model.Plugin;
import io.jenkins.pluginhealth.scoring.model.ProbeResult;

import org.junit.jupiter.api.Test;

public class OpenIssuesProbeTest extends AbstractProbeTest<OpenIssuesProbe> {
@Override
OpenIssuesProbe getSpy() {
return spy(OpenIssuesProbe.class);
}

@Test
void shouldNotRunWithInvalidUpdateCenter() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getDetails()).thenReturn(
Map.of(),
Map.of(
UpdateCenterPluginPublicationProbe.KEY, ProbeResult.failure(UpdateCenterPluginPublicationProbe.KEY, "")
)
);

final OpenIssuesProbe probe = getSpy();
for (int i = 0; i < 2; i++) {
assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "status")
.isEqualTo(ProbeResult.error(OpenIssuesProbe.KEY, ""));
verify(probe, never()).doApply(plugin, ctx);
}

}

@Test
void shouldBeAbleToFindOpenIssuesInBothJiraGH() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getDetails()).thenReturn(
Map.of(
UpdateCenterPluginPublicationProbe.KEY, ProbeResult.success(UpdateCenterPluginPublicationProbe.KEY, "")
)
);

final OpenIssuesProbe probe = getSpy();
when(plugin.getScm()).thenReturn("https://github.com/jenkinsci/accurev-plugin");

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "status", "message")
.isEqualTo(ProbeResult.error(DocumentationMigrationProbe.KEY, "0 open issues found"));
}

@Test
void shouldBeAbleToFindOpenIssuesInJira() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getDetails()).thenReturn(
Map.of(
UpdateCenterPluginPublicationProbe.KEY, ProbeResult.success(UpdateCenterPluginPublicationProbe.KEY, "")
)
);

final OpenIssuesProbe probe = getSpy();
when(plugin.getScm()).thenReturn("https://github.com/jenkinsci/active-directory-plugin");

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "status", "message")
.isEqualTo(ProbeResult.error(DocumentationMigrationProbe.KEY, "0 open issues found"));

}

@Test
void shouldBeAbleToFindOpenIssuesInGH() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getDetails()).thenReturn(
Map.of(
UpdateCenterPluginPublicationProbe.KEY, ProbeResult.success(UpdateCenterPluginPublicationProbe.KEY, "")
)
);

final OpenIssuesProbe probe = getSpy();
when(plugin.getScm()).thenReturn("https://github.com/jenkinsci/advanced-installer-msi-builder-plugin");

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "status", "message")
.isEqualTo(ProbeResult.error(DocumentationMigrationProbe.KEY, "0 open issues found"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void shouldSucceedIfPluginIsInUpdateCenterMap() {
when(plugin.getName()).thenReturn(pluginName);
when(ctx.getUpdateCenter()).thenReturn(new UpdateCenter(
Map.of(pluginName, new io.jenkins.pluginhealth.scoring.model.updatecenter.Plugin(
pluginName, null, null, null, List.of(), 0, "2.361.1", "main"
pluginName, null, null, null, List.of(), 0, "2.361.1", "main", null
)),
Map.of(),
List.of()
Expand Down