-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from rwth-acis/15-support-github-issues-and-pu…
…ll-requests Support GitHub issues and pull requests
- Loading branch information
Showing
9 changed files
with
595 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
api-testing-bot/src/main/java/i5/las2peer/services/apiTestingBot/chat/GHMessageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package i5.las2peer.services.apiTestingBot.chat; | ||
|
||
import i5.las2peer.services.apiTestingBot.context.TestModelingContext; | ||
|
||
import static i5.las2peer.services.apiTestingBot.chat.Messages.*; | ||
import static i5.las2peer.services.apiTestingBot.context.TestModelingState.*; | ||
|
||
/** | ||
* Handles messages if the bot is used in GitHub. | ||
*/ | ||
public class GHMessageHandler extends MessageHandler { | ||
|
||
/** | ||
* Reacts to the initial message of the user that starts a test modeling conversation. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
@Override | ||
public boolean handleInit(StringBuilder responseMessageSB, TestModelingContext context) { | ||
responseMessageSB.append(MODEL_TEST_CASE_INTRO); | ||
context.setState(NAME_TEST_CASE); | ||
return true; | ||
} | ||
|
||
/** | ||
* Stores the previously entered test case name to the context. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @param message Message sent by the user. | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
@Override | ||
public boolean handleTestCaseName(StringBuilder responseMessageSB, TestModelingContext context, String message) { | ||
context.setState(GH_METHOD_QUESTION); | ||
return super.handleTestCaseName(responseMessageSB, context, message); | ||
} | ||
|
||
/** | ||
* Asks the user to enter the request method. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
public boolean handleMethodQuestion(StringBuilder responseMessageSB, TestModelingContext context) { | ||
responseMessageSB.append(GH_ENTER_REQUEST_METHOD); | ||
context.setState(GH_ENTER_METHOD); | ||
return false; | ||
} | ||
|
||
/** | ||
* Handles the request method entered by the user. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @param intent Intent | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
public boolean handleMethod(StringBuilder responseMessageSB, TestModelingContext context, String intent) { | ||
if(!Intent.REQUEST_METHOD_INTENTS.contains(intent)) { | ||
responseMessageSB.append(ERROR_COULD_NOT_UNDERSTAND); | ||
return false; | ||
} | ||
|
||
// set request method in context | ||
context.setRequestMethod(Intent.toRequestMethod(intent)); | ||
context.setState(GH_PATH_QUESTION); | ||
return true; | ||
} | ||
|
||
/** | ||
* Asks the user to enter the request path. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
public boolean handlePathQuestion(StringBuilder responseMessageSB, TestModelingContext context) { | ||
responseMessageSB.append(GH_ENTER_REQUEST_PATH); | ||
context.setState(GH_ENTER_PATH); | ||
return false; | ||
} | ||
|
||
/** | ||
* Handles the request path entered by the user. | ||
* | ||
* @param responseMessageSB StringBuilder | ||
* @param context Current test modeling context | ||
* @param message Message sent by the user. | ||
* @return Whether the next state should be handled too. | ||
*/ | ||
public boolean handlePath(StringBuilder responseMessageSB, TestModelingContext context, String message) { | ||
context.setRequestPath(message); | ||
responseMessageSB.append(GH_REQUEST_INFO(context.getRequestMethod(), context.getRequestPath())); | ||
context.setState(BODY_QUESTION); | ||
return true; | ||
} | ||
} |
31 changes: 28 additions & 3 deletions
31
api-testing-bot/src/main/java/i5/las2peer/services/apiTestingBot/chat/Intent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
package i5.las2peer.services.apiTestingBot.chat; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Rasa intents related to the API testing bot. | ||
*/ | ||
public class Intent { | ||
public static String MODEL_TEST = "modeltest"; | ||
public static String YES = "yes"; | ||
public static String NO = "no"; | ||
public static final String MODEL_TEST = "modeltest"; | ||
|
||
public static final String YES = "yes"; | ||
public static final String NO = "no"; | ||
|
||
public static final String GET = "request_method_get"; | ||
public static final String POST = "request_method_post"; | ||
public static final String PUT = "request_method_put"; | ||
public static final String DELETE = "request_method_delete"; | ||
|
||
public static final List<String> REQUEST_METHOD_INTENTS = List.of(GET, POST, PUT, DELETE); | ||
|
||
public static String toRequestMethod(String intent) { | ||
switch(intent) { | ||
case Intent.GET: | ||
return "GET"; | ||
case Intent.POST: | ||
return "POST"; | ||
case Intent.PUT: | ||
return "PUT"; | ||
case Intent.DELETE: | ||
return "DELETE"; | ||
default: | ||
return "GET"; | ||
} | ||
} | ||
} |
Oops, something went wrong.