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

Commit

Permalink
Added the rest of the Knowledges
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 16, 2017
1 parent 92a9632 commit 20980ef
Show file tree
Hide file tree
Showing 14 changed files with 822 additions and 383 deletions.
32 changes: 25 additions & 7 deletions architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@ went fine)
A notification contains only the repo and the issue where the bot has been mentioned. To find the command, the bot searches for the **last** (most recent) comment in the issue
where it's been mentioned. Only the last mentioning comment will be treated as a command, in order to avoid spamming.

The bot has a [Brain](https://github.com/opencharles/charles-rest/blob/master/src/main/java/com/amihaiemil/charles/github/Brain.java) and at the beginning of each Action, it tries to **understand** the command.
Understanding a command means building up the [Step](https://github.com/opencharles/charles-rest/blob/master/src/main/java/com/amihaiemil/charles/github/Step.java)s to be executed in order to fulfill the command.

If you look inside class Brain you will see that Steps are instantiated one on top of the other, like an umbrella. Basically, for each command a tree-like structure of steps is built.

Please note that currently class **Brain** has grown quite big and needs to be refactored and broken down in smaller pieces.
There is an issue for that [here](https://github.com/opencharles/charles-rest/issues/155).
The bot has a set of knowledges (implementations of Knowledge), which it uses in order to try and "understand" a command.
Understanding a command means building the tree of steps which are to be executed in order to fulfil the command.

First, the bot puts together all its knowledges, then it uses them to find the proper steps. The last Knowledge in the chain is Confused, which means
the bot didn't manage to categorize the command and it will leave a Github reply informing the commander about the sitiuation:

```java
final Knowledge knowledge = new Conversation(//it can have a convesation
new Hello(//it can say hello
new IndexSiteKn(//it can index a site
this.logs,
new IndexSitemapKn(//it can index a site via a sitemap.xml
this.logs,
new IndexPageKn(//it can index a single page
this.logs,
new DeleteIndexKn(//it can delete the idnex
this.logs,
new Confused()//it can be confused (not understand the command)
)
)
)
)
)
)
```


## Steps
Expand Down
55 changes: 40 additions & 15 deletions src/main/java/com/amihaiemil/charles/github/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public class Action {
*/
private Issue issue;

/**
* Brain of the github agent.
*/
private Brain br;

/**
* Location of the logs.
*/
Expand All @@ -85,24 +80,54 @@ public Action(Issue issue) throws IOException {
this.logs = new LogsOnServer(
System.getProperty("charles.rest.logs.endpoint"), this.id + ".log"
);
this.br = new Brain(this.logger, this.logs);
}


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

final Knowledge knowledge = new Conversation(
new Hello(
new IndexSiteKn(
this.logs,
new IndexSitemapKn(
this.logs,
new IndexPageKn(
this.logs,
new DeleteIndexKn(
this.logs,
new Confused()
)
)
)
)
)
);

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.")
)
);
steps.perform(command, logger);
} catch (IllegalArgumentException e) {
logger.warn("No command found in the issue or the agent has already replied to the last command!");
} catch (IOException e) {
logger.error("Action failed entirely with exception: ", e);
} 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) {
this.logger.error("Action failed entirely with exception: ", e);
this.sendReply(
new ErrorReply(logs.address(), this.issue)
);
Expand All @@ -117,7 +142,7 @@ private void sendReply(Reply reply) {
try {
reply.send();
} catch (IOException e) {
logger.error("FAILED TO REPLY!", e);
this.logger.error("FAILED TO REPLY!", e);
}
}

Expand Down
Loading

1 comment on commit 20980ef

@0pdd
Copy link

@0pdd 0pdd commented on 20980ef Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 222-903f585c disappeared in src/main/java/com/amihaiemil/charles/github/Conversation.java, that's why I closed #237.

Please sign in to comment.