Skip to content

Commit

Permalink
AddTeamToCodeowners DocumentExample
Browse files Browse the repository at this point in the history
  • Loading branch information
sghill committed Aug 18, 2023
1 parent c99f3f5 commit 7b652fc
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 105 deletions.
204 changes: 103 additions & 101 deletions src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

Expand All @@ -29,133 +30,134 @@ class AddTeamToCodeownersTest implements RewriteTest {
@Language("xml")
// language=xml
private static final String POM = """
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>sample</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent();
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>sample</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent();

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new AddTeamToCodeowners());
}

@Test
@DocumentExample
void shouldAddFileIfMissing() {
rewriteRun(
pomXml(POM),
text(null,
"""
* @jenkinsci/sample-plugin-developers
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
)
pomXml(POM),
text(null,
"""
* @jenkinsci/sample-plugin-developers
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
)
);
}

@Test
void shouldAddLineIfTeamNotDefinedForAll() {
rewriteRun(
pomXml(POM),
text(
"""
# This is a comment.
* @global-owner1 @global-owner2
*.js @js-owner #This is an inline comment.
/build/logs/ @doctocat
""".stripIndent(),
"""
# This is a comment.
* @jenkinsci/sample-plugin-developers
* @global-owner1 @global-owner2
*.js @js-owner #This is an inline comment.
/build/logs/ @doctocat
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
)
pomXml(POM),
text(
"""
# This is a comment.
* @global-owner1 @global-owner2
*.js @js-owner #This is an inline comment.
/build/logs/ @doctocat
""".stripIndent(),
"""
# This is a comment.
* @jenkinsci/sample-plugin-developers
* @global-owner1 @global-owner2
*.js @js-owner #This is an inline comment.
/build/logs/ @doctocat
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
)
);
}

@Test
void shouldHandleMultiModule() {
rewriteRun(
mavenProject("sample-parent",
pomXml("""
<project>
<groupId>org.example</groupId>
<artifactId>sample-parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<modules>
<module>plugin</module>
<module>different-plugin</module>
</modules>
</project>
""".stripIndent()),
mavenProject("plugin",
pomXml("""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>my-plugin</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent())),
mavenProject("different-plugin",
pomXml("""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>different-plugin</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent()))),
text(
null,
"""
* @jenkinsci/sample-plugin-developers
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
));
mavenProject("sample-parent",
pomXml("""
<project>
<groupId>org.example</groupId>
<artifactId>sample-parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<modules>
<module>plugin</module>
<module>different-plugin</module>
</modules>
</project>
""".stripIndent()),
mavenProject("plugin",
pomXml("""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>my-plugin</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent())),
mavenProject("different-plugin",
pomXml("""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>different-plugin</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent()))),
text(
null,
"""
* @jenkinsci/sample-plugin-developers
""".stripIndent(),
s -> s.path(".github/CODEOWNERS")
));
}

@Test
void shouldNoOpIfTeamAlreadyDefinedForAll() {
rewriteRun(
pomXml(POM),
text(
"* @jenkinsci/sample-plugin-developers",
s -> s.path(".github/CODEOWNERS")
)
pomXml(POM),
text(
"* @jenkinsci/sample-plugin-developers",
s -> s.path(".github/CODEOWNERS")
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class ArtifactIdTeamNameGeneratorTest {

@ParameterizedTest
@CsvSource({
"commons-text-api,@jenkinsci/commons-text-api-plugin-developers",
"stashNotifier,@jenkinsci/stashnotifier-plugin-developers",
"aws-java-sdk-parent,@jenkinsci/aws-java-sdk-plugin-developers",
"warnings-ng-parent,@jenkinsci/warnings-ng-plugin-developers",
"commons-text-api,@jenkinsci/commons-text-api-plugin-developers",
"stashNotifier,@jenkinsci/stashnotifier-plugin-developers",
"aws-java-sdk-parent,@jenkinsci/aws-java-sdk-plugin-developers",
"warnings-ng-parent,@jenkinsci/warnings-ng-plugin-developers",
})
void shouldGenerateExpectedTeamName(String artifactId, String expected) {
String actual = generator.generate(new TeamNameInput(artifactId));
Expand Down

0 comments on commit 7b652fc

Please sign in to comment.