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

🚧 Third party repository detection probe #323

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8d74f5c
Started with writing test cases for the probe
Jagrutiti Jun 1, 2023
7d62076
Removing unwanted details from test pom file.
Jagrutiti Jun 2, 2023
4286ff4
Adding dummy to pom test files
Jagrutiti Jun 2, 2023
f412657
Adding dummy values to pom test files
Jagrutiti Jun 2, 2023
537d68a
Restoring valuable test data
Jagrutiti Jun 2, 2023
491d16d
Updating the code and test cases
Jagrutiti Jun 3, 2023
3f593a4
Removing unused imports
Jagrutiti Jun 3, 2023
365db47
Fixing code
Jagrutiti Jun 3, 2023
3bb27f5
Undid irrelevant change
Jagrutiti Jun 3, 2023
99a1379
Apply suggestions from code review
Jagrutiti Jun 3, 2023
e050c24
Restoring .gitignore
Jagrutiti Jun 3, 2023
d830b63
Merge branch 'third-party-repository-detection' of https://github.com…
Jagrutiti Jun 3, 2023
fda43ae
Updated the code and the test case
Jagrutiti Jun 3, 2023
c5c3530
Updating the test case
Jagrutiti Jun 3, 2023
5dfd1ed
updating the code and revamping the test cases
Jagrutiti Jun 4, 2023
9b246d4
Updating the test cases
Jagrutiti Jun 4, 2023
00340f8
Updated the success to be parameterized
Jagrutiti Jun 4, 2023
a39e24e
Apply suggestions from code review
Jagrutiti Jun 4, 2023
008065d
Fixed the test cases
Jagrutiti Jun 4, 2023
c565cb4
Updated the test cases
Jagrutiti Jun 4, 2023
ec9b627
Merge branch 'main' into third-party-repository-detection
Jagrutiti Jun 5, 2023
d30ec44
Merge branch 'main' of https://github.com/Jagrutiti/plugin-health-sco…
Jagrutiti Jun 5, 2023
643f599
Merge branch 'third-party-repository-detection' of https://github.com…
Jagrutiti Jun 5, 2023
2cb3048
Updating code and tests to check for pluginRespositories
Jagrutiti Jun 5, 2023
b1b5257
Removing unused import
Jagrutiti Jun 5, 2023
d812c81
FIxing minor syntaxes
Jagrutiti Jun 5, 2023
355d923
Fixed minor syntaxes
Jagrutiti Jun 5, 2023
6d7b31c
Apply suggestions from code review
Jagrutiti Jun 6, 2023
1b3ad71
Apply suggestions from code review
Jagrutiti Jun 6, 2023
dbdfe6f
Adding pom test files
Jagrutiti Jun 6, 2023
53fb134
Apply suggestions from code review
Jagrutiti Jun 6, 2023
ed123c5
Updating code for the tests to fail when no repositories detected
Jagrutiti Jun 6, 2023
e273093
Merge branch 'third-party-repository-detection' of https://github.com…
Jagrutiti Jun 6, 2023
9f7ab30
Updated test case and test files
Jagrutiti Jun 6, 2023
eba72e7
Upating test case and test pom files
Jagrutiti Jun 7, 2023
d5f4070
Fixing checkstyle issues
Jagrutiti Jun 7, 2023
4833c9b
Modifying test cases and code
Jagrutiti Jun 10, 2023
24c911b
Merge branch 'main' into third-party-repository-detection
Jagrutiti Jun 10, 2023
039362e
Undoing editorconfig change
Jagrutiti Jun 10, 2023
2f1638e
Adding additional test files
Jagrutiti Jun 10, 2023
5560353
Fixed code and checkstyle
Jagrutiti Jun 10, 2023
ce97eb0
Removing the effective-pom file
Jagrutiti Jun 13, 2023
148d4dd
Added spotbugs fixes
Jagrutiti Jun 13, 2023
dbe70d5
Added spotbugs fixes
Jagrutiti Jun 13, 2023
276968c
Merge branch 'main' into third-party-repository-detection
Jagrutiti Jun 13, 2023
0be6114
Added spotbugs fixes
Jagrutiti Jun 13, 2023
9343f56
Merge branch 'third-party-repository-detection' of https://github.com…
Jagrutiti Jun 13, 2023
9d43283
Removing unused imports
Jagrutiti Jun 13, 2023
6d42558
Apply suggestions from code review
Jagrutiti Jun 14, 2023
3659137
Fixed missing symbols error
Jagrutiti Jun 14, 2023
58ba0b1
Fixing checkstyle issues
Jagrutiti Jun 14, 2023
da55c4d
Merge branch 'main' into third-party-repository-detection
Jagrutiti Jun 14, 2023
fc8ec3b
Adding code for effective-pom generation and updated the test cases:
Jagrutiti Sep 3, 2023
d77baf1
Adding comments
Jagrutiti Sep 3, 2023
9b23f07
Merge branch 'main' into third-party-repository-detection
Jagrutiti Sep 3, 2023
85c10f3
Merge branch 'main' into third-party-repository-detection
Jagrutiti Sep 7, 2023
1fa7c2b
Fixed merge 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
alecharp marked this conversation as resolved.
Show resolved Hide resolved
alecharp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.jenkins.pluginhealth.scoring.probes;

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 = ThirdPartyRepositoryDetectionProbe.ORDER)
public class ThirdPartyRepositoryDetectionProbe extends Probe{

private static final Logger LOGGER = LoggerFactory.getLogger(ThirdPartyRepositoryDetectionProbe.class);
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved
public static final int ORDER = SCMLinkValidationProbe.ORDER + 100;
public static final String KEY = "third-party-repository-detection-probe";

@Override
protected ProbeResult doApply(Plugin plugin, ProbeContext context) {
return null;
}

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

@Override
public String getDescription() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.jenkins.pluginhealth.scoring.probes;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import java.io.File;

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

import org.junit.jupiter.api.Test;

public class ThirdPartyRepositoryDetectionProbeTest extends AbstractProbeTest<ThirdPartyRepositoryDetectionProbe> {
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved
@Override
ThirdPartyRepositoryDetectionProbe getSpy() {
return spy(ThirdPartyRepositoryDetectionProbe.class);
}

@Test
void shouldFailIfThirdPartRepositoriesDetected() {

final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);
final ThirdPartyRepositoryDetectionProbe probe = getSpy();

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fake-test-directory/pom.xml").getFile());

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "message", "status")
.isEqualTo(ProbeResult.failure(ThirdPartyRepositoryDetectionProbe.KEY, "Third party repository detected in the plugin"));
verify(probe).doApply(any(Plugin.class), any(ProbeContext.class));

}

@Test
void shouldPassIfNoThirdPartyRepositoriesDetected() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);
final ThirdPartyRepositoryDetectionProbe probe = getSpy();

assertThat(probe.apply(plugin, ctx))
.usingRecursiveComparison()
.comparingOnlyFields("id", "message", "status")
.isEqualTo(ProbeResult.failure(ThirdPartyRepositoryDetectionProbe.KEY, "The plugin has no third party repositories"));
verify(probe).doApply(any(Plugin.class), any(ProbeContext.class));

}


}
174 changes: 174 additions & 0 deletions core/src/test/resources/fake-test-directory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is a fake pom used for test cases
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.58</version>
<relativePath />
</parent>

<properties>
<changelist>9999-SNAPSHOT</changelist>
<jenkins.version>2.361.4</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<no-test-jar>false</no-test-jar>
<!-- Use the same configuration than before. -->
<spotbugs.failOnError>false</spotbugs.failOnError>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved
</properties>


<artifactId>confluence-publisher</artifactId>
<name>Confluence Publisher</name>
<description>Publish build artifacts to an Atlassian Confluence wiki</description>
<version>${changelist}</version>
<packaging>hpi</packaging>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>

<organization>
<name>MeetMe, Inc.</name>
<url>http://www.meetme.com/</url>
</organization>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>manual</distribution>
<comments>
Copyright 2011-2012 Insider Guides, Inc.
Copyright 2012 MeetMe, Inc.
</comments>
</license>
</licenses>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved

<developers>
<developer>
<id>jhansche</id>
<name>Joe Hansche</name>
<email>jhansche@myyearbook.com</email>
<roles>
<role>author</role>
</roles>
</developer>
<developer>
<id>jetersen</id>
<name>Joseph Petersen</name>
<email>jetersen@github</email>
<roles>
<role>maintainer</role>
</roles>
</developer>
</developers>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.361.x</artifactId>
<version>1968.vb_14a_29e76128</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-core</artifactId>
<version>7.1.6</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>com.atlassian.confluence</groupId>
<artifactId>confluence-rest-client</artifactId>
<version>7.14.0</version>
<exclusions>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>jaxb</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved

<scm>
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>
Jagrutiti marked this conversation as resolved.
Show resolved Hide resolved

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
<repository>
<id>releases-repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases/</url>
</repository>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>