-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
h1alexbel
committed
Apr 10, 2024
1 parent
c32b5e8
commit 2bc808f
Showing
8 changed files
with
358 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/git/tracehub/codereview/action/prompt/AnalysisPrompt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package git.tracehub.codereview.action.prompt; | ||
|
||
import java.util.List; | ||
import javax.json.JsonArray; | ||
import javax.json.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.Text; | ||
import org.cactoos.list.ListOf; | ||
|
||
/** | ||
* Analysis prompt. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class AnalysisPrompt implements Text { | ||
|
||
/** | ||
* Pull request. | ||
*/ | ||
private final Scalar<JsonArray> changes; | ||
|
||
/** | ||
* Pull request title. | ||
*/ | ||
private final String title; | ||
|
||
/** | ||
* Pull request reviews. | ||
*/ | ||
private final JsonArray reviews; | ||
|
||
@Override | ||
public String asString() throws Exception { | ||
final List<String> composed = new ListOf<>(); | ||
this.changes.value() | ||
.forEach( | ||
change -> { | ||
final JsonObject json = change.asJsonObject(); | ||
composed.add( | ||
String.join( | ||
"\n", | ||
String.format( | ||
"filename: %s", | ||
json.getString("filename") | ||
), | ||
"patch:", | ||
json.getString("patch"), | ||
String.format( | ||
"additions: %s", | ||
json.getInt("additions") | ||
), | ||
String.format( | ||
"deletions: %s", | ||
json.getInt("deletions") | ||
), | ||
String.format( | ||
"changes: %s", | ||
json.getInt("changes") | ||
) | ||
) | ||
); | ||
}); | ||
return String.join( | ||
"\n", | ||
"Please analyze how thorough the code review was.", | ||
"In the end of analysis suggest a review score, like \"excellent", | ||
" review\", \"poor review\" or something in the middle", | ||
"Pull Request: ", | ||
String.format( | ||
"PR title: %s", | ||
this.title | ||
), | ||
"PR changes:", | ||
composed.toString(), | ||
"Code review: ", | ||
this.reviews.toString() | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/git/tracehub/codereview/action/prompt/SystemPrompt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package git.tracehub.codereview.action.prompt; | ||
|
||
import org.cactoos.Text; | ||
|
||
/** | ||
* System prompt. | ||
* | ||
* @since 0.0.0 | ||
* @checkstyle LineLengthCheck (20 lines) | ||
*/ | ||
public final class SystemPrompt implements Text { | ||
|
||
@Override | ||
public String asString() { | ||
return "You are a software quality analysis expert tasked with reviewing incoming code reviews that developers are submit on GitHub Pull requests platform"; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/git/tracehub/codereview/action/prompt/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Prompts. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.codereview.action.prompt; |
90 changes: 90 additions & 0 deletions
90
src/test/java/git/tracehub/codereview/action/prompt/AnalysisPromptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package git.tracehub.codereview.action.prompt; | ||
|
||
import com.jcabi.github.Pull; | ||
import git.tracehub.codereview.action.extentions.PullFiles; | ||
import git.tracehub.codereview.action.extentions.PullFilesExtension; | ||
import git.tracehub.codereview.action.github.Authored; | ||
import git.tracehub.codereview.action.github.PullChanges; | ||
import java.io.InputStreamReader; | ||
import javax.json.Json; | ||
import org.cactoos.io.ResourceOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* Test case for {@link AnalysisPrompt}. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
final class AnalysisPromptTest { | ||
|
||
@Test | ||
@PullFiles("git/tracehub/codereview/action/github/small.json") | ||
@ExtendWith(PullFilesExtension.class) | ||
void compilesPrompt(final Pull mock) throws Exception { | ||
final String prompt = new AnalysisPrompt( | ||
new PullChanges(mock), | ||
"feat(#1): xsl changes", | ||
new Authored( | ||
() -> Json.createReader( | ||
new InputStreamReader( | ||
new ResourceOf( | ||
"git/tracehub/codereview/action/github/comments.json" | ||
).stream() | ||
) | ||
).readArray() | ||
).value() | ||
).asString(); | ||
final String expected = String.join( | ||
"\n", | ||
"Please analyze how thorough the code review was.", | ||
"In the end of analysis suggest a review score, like \"excellent", | ||
" review\", \"poor review\" or something in the middle", | ||
"Pull Request: ", | ||
"PR title: feat(#1): xsl changes", | ||
"PR changes:", | ||
"[filename: eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl", | ||
"patch:", | ||
"@@ -419,9 +419,6 @@ SOFTWARE.\n <xsl:when test=\"$method='&'\">\n <xsl:text>σ</xsl:text>\n </xsl:when>\n- <xsl:when test=\"$method='<'\">\n- <xsl:text>ν</xsl:text>\n- </xsl:when>\n <xsl:otherwise>\n <xsl:value-of select=\"eo:attr-name($method)\"/>\n </xsl:otherwise>", | ||
"additions: 0", | ||
"deletions: 3", | ||
"changes: 3]", | ||
"Code review: ", | ||
"[\"h1alexbel: @hizmailovich first comment\",\"h1alexbel: @hizmailovich second comment\",\"h1alexbel: @hizmailovich This sentence might be connected with the previous one: \\\"The subject of this article is caching.\\\"\"]" | ||
); | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"Compiled prompt (%s) does not match with expected (%s)", | ||
prompt, | ||
expected | ||
), | ||
prompt, | ||
new IsEqual<>(expected) | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/git/tracehub/codereview/action/prompt/SystemPromptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package git.tracehub.codereview.action.prompt; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test case for {@link SystemPrompt}. | ||
* | ||
* @since 0.0.0 | ||
* @checkstyle LineLengthCheck (20 lines) | ||
*/ | ||
final class SystemPromptTest { | ||
|
||
@Test | ||
void compilesSystemPrompt() { | ||
final String prompt = new SystemPrompt().asString(); | ||
final String expected = "You are a software quality analysis expert tasked with reviewing incoming code reviews that developers are submit on GitHub Pull requests platform"; | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"Compiled prompt %s does not match with expected %s", | ||
prompt, | ||
expected | ||
), | ||
prompt, | ||
new IsEqual<>(expected) | ||
); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/git/tracehub/codereview/action/prompt/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Tests for prompts. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.codereview.action.prompt; |