Skip to content

Commit

Permalink
Merge pull request jboss#107 from xstefank/refactor-command
Browse files Browse the repository at this point in the history
Refactor commands into a separate package
  • Loading branch information
xstefank authored Mar 30, 2020
2 parents e37f33d + 9eebd3d commit 2a27df4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.tyr.whitelist;
package org.jboss.tyr.command;

import org.jboss.tyr.Command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.tyr.whitelist;
package org.jboss.tyr.command;

import org.jboss.tyr.CIOperations;
import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.api.GitHubAPI;
import org.jboss.tyr.model.Utils;

import javax.json.JsonObject;

public class AddUserCommand extends AbstractCommand {

@Override
public void process(JsonObject payload, CIOperations operations) throws InvalidPayloadException {
String pullRequestAuthor = WhitelistProcessing.getPRAuthor(payload);
String commentAuthor = WhitelistProcessing.getCommentAuthor(payload);
String pullRequestAuthor = Utils.getPRAuthor(payload);
String commentAuthor = Utils.getCommentAuthor(payload);

if (operations.isUserAdministrator(commentAuthor) &&
!operations.isUserAlreadyWhitelisted(pullRequestAuthor) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.tyr.whitelist;
package org.jboss.tyr.command;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.tyr.whitelist;
package org.jboss.tyr.command;

import org.jboss.tyr.CIOperations;
import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.api.GitHubAPI;
import org.jboss.tyr.model.Utils;

import javax.json.JsonObject;

public class RetestCommand extends AbstractCommand {

@Override
public void process(JsonObject payload, CIOperations operations) throws InvalidPayloadException {
String pullRequestAuthor = WhitelistProcessing.getPRAuthor(payload);
String commentAuthor = WhitelistProcessing.getCommentAuthor(payload);
String pullRequestAuthor = Utils.getPRAuthor(payload);
String commentAuthor = Utils.getCommentAuthor(payload);

if (operations.isUserAlreadyWhitelisted(pullRequestAuthor) &&
operations.isUserEligibleToRunCI(commentAuthor)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.tyr.whitelist;
package org.jboss.tyr.command;

import org.jboss.tyr.CIOperations;
import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.api.GitHubAPI;
import org.jboss.tyr.model.Utils;

import javax.json.JsonObject;

public class RetestFailedCommand extends AbstractCommand {

@Override
public void process(JsonObject payload, CIOperations operations) throws InvalidPayloadException {
String pullRequestAuthor = WhitelistProcessing.getPRAuthor(payload);
String commentAuthor = WhitelistProcessing.getCommentAuthor(payload);
String pullRequestAuthor = Utils.getPRAuthor(payload);
String commentAuthor = Utils.getCommentAuthor(payload);

if (operations.isUserAlreadyWhitelisted(pullRequestAuthor) &&
operations.isUserEligibleToRunCI(commentAuthor)) {
Expand Down
9 changes: 9 additions & 0 deletions tyr-runner/src/main/java/org/jboss/tyr/model/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jboss.tyr.model;

import javax.json.JsonObject;
import java.net.MalformedURLException;
import java.net.URL;

Expand Down Expand Up @@ -72,4 +73,12 @@ public static String getConfigDirectory() {
}
return path;
}

public static String getCommentAuthor(JsonObject issuePayload) {
return issuePayload.getJsonObject(Utils.COMMENT).getJsonObject(Utils.USER).getString(Utils.LOGIN);
}

public static String getPRAuthor(JsonObject issuePayload) {
return issuePayload.getJsonObject(Utils.ISSUE).getJsonObject(Utils.USER).getString(Utils.LOGIN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.ci.CILoader;
import org.jboss.tyr.ci.ContinuousIntegration;
import org.jboss.tyr.command.AbstractCommand;
import org.jboss.tyr.command.CommandsLoader;
import org.jboss.tyr.model.AdditionalResourcesLoader;
import org.jboss.tyr.model.PersistentList;
import org.jboss.tyr.model.TyrProperties;
Expand Down Expand Up @@ -54,14 +56,6 @@ public WhitelistProcessing(FormatYaml config) {
continuousIntegrations = loadCIs(config);
}

static String getCommentAuthor(JsonObject issuePayload) {
return issuePayload.getJsonObject(Utils.COMMENT).getJsonObject(Utils.USER).getString(Utils.LOGIN);
}

static String getPRAuthor(JsonObject issuePayload) {
return issuePayload.getJsonObject(Utils.ISSUE).getJsonObject(Utils.USER).getString(Utils.LOGIN);
}

public void processPRComment(JsonObject issuePayload) throws InvalidPayloadException {
if (!commands.isEmpty() &&
issuePayload.getJsonObject(Utils.ISSUE).getJsonObject(Utils.PULL_REQUEST) != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.TestUtils;
import org.jboss.tyr.command.AddUserCommand;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.TestUtils;
import org.jboss.tyr.command.RetestCommand;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jboss.tyr.InvalidPayloadException;
import org.jboss.tyr.TestUtils;
import org.jboss.tyr.command.RetestFailedCommand;
import org.junit.Assert;
import org.junit.Test;

Expand Down

0 comments on commit 2a27df4

Please sign in to comment.