Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
Added Steps and StepsTree to fix bug no. 244
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 22, 2017
1 parent 52bb227 commit f4e0b9f
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 261 deletions.
27 changes: 6 additions & 21 deletions src/main/java/com/amihaiemil/charles/github/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,8 @@ public Action(Issue issue) throws IOException {


public void perform() {
ValidCommand command;
try {
this.logger.info("Started action " + this.id);
final LastComment lc = new LastComment(issue);
command = new ValidCommand(lc);
String commandBody = command.json().getString("body");
this.logger.info("Received command: " + commandBody);

final Knowledge knowledge = new Conversation(
new Hello(
new IndexSiteKn(
Expand All @@ -102,28 +96,19 @@ public void perform() {
this.logs,
new DeleteIndexKn(
this.logs,
new Confused()
new Confused(this.logs)
)
)
)
)
), this.logs
)
);

final Steps steps = new Steps(
knowledge.handle(command),
new SendReply(
new TextReply(
command,
String.format(
command.language().response("step.failure.comment"),
command.authorLogin(), this.logs.address()
)
),
new Step.FinalStep("[ERROR] Some step didn't execute properly.")
final Steps steps = knowledge.handle(
new ValidCommand(
new LastComment(this.issue)
)
);
steps.perform(command, logger);
steps.perform(this.logger);
} catch (final IllegalArgumentException e) {
this.logger.warn("No command found in the issue or the agent has already replied to the last command!");
} catch (final IOException e) {
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/amihaiemil/charles/github/Confused.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,29 @@
*/
public class Confused implements Knowledge {

/**
* Location of the log file.
*/
private LogsLocation logsLoc;

public Confused(LogsLocation logsLoc) {
this.logsLoc = logsLoc;
}

@Override
public Step handle(Command com) throws IOException {
return new SendReply(
new TextReply(
com,
String.format(
com.language().response("unknown.comment"),
com.authorLogin()
)
),
new Step.FinalStep()
public Steps handle(Command com) throws IOException {
return new StepsTree(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("unknown.comment"),
com.authorLogin()
)
), new Step.FinalStep()
), com, this.logsLoc//TODO #246:30min LogsLocation should be passed down as method param of Knowledge.handle()
);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Conversation(final Knowledge followup, final Language... langs) {
}

@Override
public Step handle(final Command com) throws IOException {
public Steps handle(final Command com) throws IOException {
String type = "unknown";
Command understood = new Understood(com, type, this.languages[0]);
for(Language lang : this.languages) {
Expand Down
84 changes: 44 additions & 40 deletions src/main/java/com/amihaiemil/charles/github/DeleteIndexKn.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,51 @@ public DeleteIndexKn(final LogsLocation logsLoc, final Knowledge notDelete) {
}

@Override
public Step handle(final Command com) throws IOException {
public Steps handle(final Command com) throws IOException {
if("deleteindex".equalsIgnoreCase(com.type())) {
return new DeleteIndexCommandCheck(
new IndexExistsCheck(
com.indexName(),
new GeneralPreconditionsCheck(
new DeleteIndex(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("deleteindex.finished.comment"),
com.authorLogin(), com.repo().name(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.missing.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Step.FinalStep()
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("denied.deleteindex.comment"),
com.authorLogin(), com.agentLogin(), com.repo().name()
)
),
new Step.FinalStep()
)
);
return new StepsTree(
new DeleteIndexCommandCheck(
new IndexExistsCheck(
com.indexName(),
new GeneralPreconditionsCheck(
new DeleteIndex(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("deleteindex.finished.comment"),
com.authorLogin(), com.repo().name(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.missing.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Step.FinalStep()
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("denied.deleteindex.comment"),
com.authorLogin(), com.agentLogin(), com.repo().name()
)
),
new Step.FinalStep()
)
),
com,
this.logsLoc
);
}
return this.notDelete.handle(com);
}
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/amihaiemil/charles/github/Hello.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,31 @@ public final class Hello implements Knowledge {
*/
private Knowledge notHello;

private LogsLocation logsLoc;

/**
* Ctor.
* @param notHello What do we do if it's not a 'hello' command?
*/
public Hello(final Knowledge notHello) {
public Hello(final Knowledge notHello, final LogsLocation logs) {
this.notHello = notHello;
this.logsLoc = logs;
}

@Override
public Step handle(final Command com) throws IOException {
public Steps handle(final Command com) throws IOException {
if("hello".equalsIgnoreCase(com.type())) {
String hello = String.format(
com.language().response("hello.comment"),
com.authorLogin()
);
return new SendReply(
new TextReply(com, hello),
new Step.FinalStep()
return new StepsTree(
new SendReply(
new TextReply(com, hello),
new Step.FinalStep()
),
com,
this.logsLoc
);
}
return this.notHello.handle(com);
Expand Down
78 changes: 41 additions & 37 deletions src/main/java/com/amihaiemil/charles/github/IndexPageKn.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,49 @@ public IndexPageKn(final LogsLocation logsLoc, final Knowledge notIdxPage) {
}

@Override
public Step handle(final Command com) throws IOException {
public Steps handle(final Command com) throws IOException {
if("indexpage".equalsIgnoreCase(com.type())) {
return new PageHostedOnGithubCheck(
new GeneralPreconditionsCheck(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.start.comment"),
com.authorLogin(),
this.logsLoc.address()
)
),
new IndexPage(
new StarRepo(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.finished.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
)
)
return new StepsTree(
new PageHostedOnGithubCheck(
new GeneralPreconditionsCheck(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.start.comment"),
com.authorLogin(),
this.logsLoc.address()
)
),
new IndexPage(
new StarRepo(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.finished.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
)
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("denied.badlink.comment"),
com.authorLogin()
)
),
new Step.FinalStep()
)
),
new SendReply(
new TextReply(
com,
String.format(
com.language().response("denied.badlink.comment"),
com.authorLogin()
)
),
new Step.FinalStep()
)
com,
this.logsLoc
);
}
return this.notIdxPage.handle(com);
Expand Down
56 changes: 30 additions & 26 deletions src/main/java/com/amihaiemil/charles/github/IndexSiteKn.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,37 @@ public IndexSiteKn(final LogsLocation logsLoc, final Knowledge notIdxSite) {
}

@Override
public Step handle(final Command com) throws IOException {
public Steps handle(final Command com) throws IOException {
if("indexsite".equalsIgnoreCase(com.type())) {
return new GeneralPreconditionsCheck(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.start.comment"),
com.authorLogin(),
this.logsLoc.address()
)
),
new IndexSite(
new StarRepo(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.finished.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
)
)
return new StepsTree(
new GeneralPreconditionsCheck(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.start.comment"),
com.authorLogin(),
this.logsLoc.address()
)
),
new IndexSite(
new StarRepo(
new SendReply(
new TextReply(
com,
String.format(
com.language().response("index.finished.comment"),
com.authorLogin(), this.logsLoc.address()
)
),
new Tweet(new Step.FinalStep())
)
)
)
)
),
com,
this.logsLoc
);
}
return this.notIdxSite.handle(com);
Expand Down
Loading

0 comments on commit f4e0b9f

Please sign in to comment.