Skip to content

Commit

Permalink
yegor256#960 fixing Javadoc and inefficient regex use found by CR
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Mar 2, 2016
1 parent 964f123 commit ec0efd7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/rultor/agents/github/qtn/QnRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
@EqualsAndHashCode
public final class QnRelease implements Question {

/**
* Pattern matching the version tag of the release enclosed by backticks.
*/
private static final Pattern QUESTION_PATTERN =
Pattern.compile("`(.+)`");

/**
* Message bundle.
*/
Expand All @@ -72,9 +78,9 @@ public Req understand(final Comment.Smart comment,
issue.repo().coordinates(), issue.number(), comment.number()
);
final Req req;
final Matcher matcher = Pattern.compile(".*release.*`(.+)`.*")
final Matcher matcher = QnRelease.QUESTION_PATTERN
.matcher(comment.body());
if (matcher.matches()) {
if (matcher.find()) {
final String name = matcher.group(1);
final ReleaseTag release = new ReleaseTag(issue.repo(), name);
if (release.allowed()) {
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/rultor/agents/github/qtn/ReleaseTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
final class ReleaseTag {

/**
* Pattern matching semantically valid versions.
* Pattern matching semantically valid versions, that also only consist in
* digits and dots.
*/
private static final Pattern VERSION_PATTERN =
Pattern.compile("^(\\d+\\.)*(\\d+)$");
Expand Down Expand Up @@ -77,8 +78,8 @@ final class ReleaseTag {
* Checks if this tag can be released.
* A tag can be released if it is either not named as a semantically
* correct version or has a higher version number than all existing tags.
* @return Boolean
* @throws IOException on error.
* @return True if this tag can be released
* @throws IOException on error
*/
public boolean allowed() throws IOException {
return !ReleaseTag.valid(this.name)
Expand All @@ -87,8 +88,8 @@ public boolean allowed() throws IOException {

/**
* Returns the tag name of the highest version from the repo.
* @return String name of the highest released version.
* @throws IOException on error.
* @return String name of the highest released version
* @throws IOException on error
*/
public String reference() throws IOException {
String tag = "0";
Expand All @@ -107,7 +108,7 @@ public String reference() throws IOException {
* Checks that a tag is newer than a given reference.
* @param reference String
* @param tag String
* @return Boolean true if tag is new than reference.
* @return True if tag is newer than reference
*/
private static boolean newer(final String reference, final String tag) {
return new DefaultArtifactVersion(reference).compareTo(
Expand All @@ -116,9 +117,10 @@ private static boolean newer(final String reference, final String tag) {
}

/**
* Checks tag string format being a valid release version.
* @param identifier String tag name.
* @return Boolean
* Checks that tag is a valid release version, consisting only in digits
* and dots.
* @param identifier String tag name
* @return True if identifier is a valid release version
*/
private static boolean valid(final String identifier) {
return ReleaseTag.VERSION_PATTERN.matcher(identifier).matches();
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class QnReleaseTest {

/**
* QnRelease can build a request.
* @throws Exception In case of error.
* @throws Exception In case of error
*/
@Test
public void buildsRequest() throws Exception {
Expand All @@ -81,7 +81,7 @@ public void buildsRequest() throws Exception {

/**
* QnRelease can deny release when tag is outdated.
* @throws Exception In case of error.
* @throws Exception In case of error
*/
@Test
public void denyOutdatedTag() throws Exception {
Expand All @@ -99,12 +99,11 @@ public void denyOutdatedTag() throws Exception {
new Comment.Smart(issue.comments().get(2)).body(),
Matchers.containsString("There is already a release `1.7`")
);
issue.comments().post("release");
}

/**
* QnRelease can deny release when tag name is not given.
* @throws Exception In case of error.
* @throws Exception In case of error
*/
@Test
public void denyMissingTag() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

/**
* Tests for ${@link ReleaseTag}.
*
* @author Armin Braun ([email protected])
* @version $Id$
* @since 1.62
Expand All @@ -46,7 +45,9 @@ public final class ReleaseTagTest {

/**
* ReleaseTag can deny release for outdated, semantically correct versions.
* @throws Exception In case of error.
* It does however allow any version number, if it contains anything
* other than digits and dots.
* @throws Exception In case of error
*/
@Test
public void validatesReleaseVersion() throws Exception {
Expand All @@ -72,7 +73,7 @@ public void validatesReleaseVersion() throws Exception {

/**
* ReleaseTag can retrieve the latest release version in the repo.
* @throws Exception In case of error.
* @throws Exception In case of error
*/
@Test
public void getsReferenceVersion() throws Exception {
Expand Down

0 comments on commit ec0efd7

Please sign in to comment.