-
Notifications
You must be signed in to change notification settings - Fork 13
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
Automatically generate JIRA issue links to Pull Request description #108
Conversation
Please review @xstefank |
ff3fb9a
to
374a25d
Compare
.append("\n"); | ||
|
||
for (String jira : jiraIssues) { | ||
sb.appendQuote(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, jira, jira)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n can go into format template
} | ||
} | ||
|
||
private Set<String> collectJiraIssues(GHPullRequest pullRequest, Pattern jiraPattern) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend parseJiraIssues
} | ||
|
||
private Set<String> collectJiraIssues(GHPullRequest pullRequest, Pattern jiraPattern) { | ||
Set<String> jiras = retrieveJirasFromString(pullRequest.getTitle(), jiraPattern); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly parse
@@ -0,0 +1,23 @@ | |||
package io.xstefank.wildfly.bot.util; | |||
|
|||
public class CustomStringBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can find a better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if the appendQuote is worth a new class
@@ -298,7 +296,6 @@ void testDirectoriesMentionsNewFileInDiff() throws IOException { | |||
Mockito.verify(mockedPR, Mockito.times(2)).listFiles(); | |||
Mockito.verify(mockedPR).comment("/cc @7125767235"); | |||
Mockito.verify(mockedPR, Mockito.times(1)).listComments(); | |||
Mockito.verifyNoMoreInteractions(mockedPR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to list individual invocations since we test them all here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There would be quite a lot of them and it is possible, that it will grow in the future as well. I think at some point point we will no longer know, where all those invocations were called and adjust the tests to failures.
GHPullRequestCommitDetail.Commit mockCommit = Mockito.mock(GHPullRequestCommitDetail.Commit.class); | ||
Mockito.when(mockCommitDetail.getCommit()).thenReturn(mockCommit); | ||
for (String commitMessage : commitMessages) { | ||
Mockito.when(mockCommit.getMessage()).thenReturn(commitMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this overriding one single commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so. At least in chained calls such as Mockito.when(...).thenReturn("1").thenReturn("2")
will return at first 1
and on second invocation 2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushing latest updates
@@ -298,7 +296,6 @@ void testDirectoriesMentionsNewFileInDiff() throws IOException { | |||
Mockito.verify(mockedPR, Mockito.times(2)).listFiles(); | |||
Mockito.verify(mockedPR).comment("/cc @7125767235"); | |||
Mockito.verify(mockedPR, Mockito.times(1)).listComments(); | |||
Mockito.verifyNoMoreInteractions(mockedPR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There would be quite a lot of them and it is possible, that it will grow in the future as well. I think at some point point we will no longer know, where all those invocations were called and adjust the tests to failures.
GHPullRequestCommitDetail.Commit mockCommit = Mockito.mock(GHPullRequestCommitDetail.Commit.class); | ||
Mockito.when(mockCommitDetail.getCommit()).thenReturn(mockCommit); | ||
for (String commitMessage : commitMessages) { | ||
Mockito.when(mockCommit.getMessage()).thenReturn(commitMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so. At least in chained calls such as Mockito.when(...).thenReturn("1").thenReturn("2")
will return at first 1
and on second invocation 2
.
374a25d
to
c813b23
Compare
@@ -75,6 +84,63 @@ void onPullRequestEdited(@PullRequest.Edited @PullRequest.Opened @PullRequest.Sy | |||
|
|||
} | |||
|
|||
/** | |||
* Originally from https://github.com/hibernate/hibernate-github-bot | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can probably drop this as it doesn't add value
|
||
public List<WildFlyRule> rules; | ||
|
||
public Format format = new Format(); | ||
|
||
public void setProjectKey(String name) { | ||
projectPattern = Pattern.compile(String.format("\\[%s-\\d+]\\s+.*|%s-\\d+\\s+.*", name, name)); | ||
issuePattern = Pattern.compile(String.format("%s-\\d+", name)); | ||
checkPattern = Pattern.compile(String.format("(\\[%1$s-\\d+(,%1$s-\\d+)*\\]|%1$s-\\d+(,%1$s-\\d+)*)(?!%1$s-\\d+)", name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regexes should be also constants if they are the same, easy to make mistakes
return this; | ||
} | ||
|
||
public DescriptionStringBuilder appendQuote(String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a Quote and I still don't understand why we need a separate class for this override
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will rename it to appendBlockQuote
, as that is what it is called in markdown. which we are using it's syntax for writing comments / editing descriptions. Also it might be easier for future expansion. Currently it is also used in tests and makes the, more readable.
|
||
private String appendedMessage = String.format(""" | ||
%s\n | ||
> %s%s""" + RuntimeConstants.BOT_MESSAGE_FOOTER, RuntimeConstants.BOT_MESSAGE_HEADER, RuntimeConstants.BOT_JIRA_LINKS_HEADER, "%s"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the %s argument at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise we lose the %s, which is used again. This appendMessage
is further used for String.format
and the %s
contains the body for individual tests.
public void testNonEmptyBodyAppendMessage() throws IOException { | ||
String body = """ | ||
This is my | ||
testing\n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just why do you use \n in multiline string? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I replace \n with just an enter
key hit and try to compile the wildfly-checkstyle plugin complains
Mockito.when(mockCommit.getMessage()).thenReturn(commitMessage); | ||
|
||
processEmptyPullRequestMock(mocks.pullRequest(1352150111)); | ||
// We still need to manually mock this commit, as we retrieve the sha as well | ||
processPullRequestMock(mocks.pullRequest(1352150111), mockEmptyFileDetails(), mockEmptyComments(), mockCommitDetails); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have helper methods for commits. Also the comment seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a comment, why it is needed
|
||
GitHubAppTesting.given() | ||
.github(mocks -> { | ||
mocks.configFileFromString("wildfly-bot.yml", wildflyConfigFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config name should be pulled from constants also in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's just most of the test are not doing it anyways.
} | ||
|
||
@Test | ||
void incorrectTitleCheckFailMultipleJirasBracketsSecondTest() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? same as previous one?
I will also update other tests |
0be76be
to
c6880f5
Compare
|
||
sb.append(RuntimeConstants.BOT_MESSAGE_HEADER) | ||
.append("\n\n") | ||
.append(blockQuoted(RuntimeConstants.BOT_JIRA_LINKS_HEADER)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
header should also be "> " ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted it to be the only one with normal font to explain, what is below in blockquotes. Just as some kind of a title.
public static final String CHECK_PATTERN = "\\[%1$s-\\d+(,%1$s-\\d+)*\\]|%1$s-\\d+(,%1$s-\\d+)*"; | ||
|
||
public static final String BOT_MESSAGE_HEADER = """ | ||
____ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary if you have the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one adds a small little deliminer between the section automatically generated. A thin grey line.
private String appendedMessage = String.format(""" | ||
%s | ||
|
||
%s%%s%s""", RuntimeConstants.BOT_MESSAGE_HEADER, blockQuoted(RuntimeConstants.BOT_JIRA_LINKS_HEADER), RuntimeConstants.BOT_MESSAGE_FOOTER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of fun we should write this as "%s\n\n%s%%s%s". (Joke :))
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(body + "\n\n" + appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00000")).toString()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need SB here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be consistent with all the tests, rather then save on this one
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00001"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00002")).toString()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it makes sense
9077033
to
c32e4b0
Compare
We should now link only jiras, which are not in the description and omit updating description fully if all jiras are linked |
0562db3
to
229b387
Compare
229b387
to
f4c28ea
Compare
f4c28ea
to
e229ecd
Compare
e229ecd
to
e2ba997
Compare
e2ba997
to
632f08b
Compare
Example can be found here: The-Huginn#19