Skip to content

Commit 760f9b3

Browse files
authored
Merge pull request #25 from rwth-acis/develop
v1.0.0
2 parents c691edc + e775b05 commit 760f9b3

25 files changed

+2814
-314
lines changed

.github/images/logo.png

4.63 KB
Loading

README.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
# api-testing-bot
1+
<h1 align="center">
2+
<img src="https://raw.githubusercontent.com/rwth-acis/api-testing-bot/main/.github/images/logo.png" width="120px"/><br/>
3+
API Testing Bot
4+
</h1>
5+
6+
<p align="center">
7+
<img src="https://github.com/rwth-acis/api-testing-bot/workflows/Java%20CI%20with%20Gradle/badge.svg?branch=main"/>
8+
</p>
9+
10+
## ⚙️ Setup/Usage
11+
12+
First, set up the bot in the [Social-Bot-Framework](https://github.com/rwth-acis/Social-Bot-Framework).
13+
Both the bot model and the NLU training data can be found in the `bot-model` directory.
14+
The bot uses a backend service which is included in this repository.
15+
The easiest way to use the service is to build (or pull) the Docker image and run the service as a container.
16+
The bot can be used in different ways and on different platforms:
17+
18+
### 1. Usage with CAE & RocketChat
19+
20+
If the bot is a member of a RocketChat channel that is linked to a CAE project, test cases can be modeled via chat.
21+
The bot can be triggered by sending a message such as "model a test".
22+
As soon as the modeling is completed, the test case is forwarded to the CAE and proposed there in the Test Editor.
23+
24+
Dependencies:
25+
26+
- [las2peer-project-service](https://github.com/rwth-acis/las2peer-project-service)
27+
- [CAE](https://github.com/rwth-acis/CAE)
28+
29+
### 2. Usage on GitHub
30+
31+
The bot may be used within GitHub repositories by connecting it to a GitHub app.
32+
Therefore, the app id and a private key are required.
33+
Please note that the private key needs to be converted from PKCS#1 to PKCS#8.
34+
In the bot model, the `Authentication Token` of the GitHub issue or pull request messenger needs to be set to `[App Id]:[App Private Key]`.
35+
Use the private key in PKCS#8 format, but remove the first and last line before copying it.
36+
Also, set the webhook URL of the app to `.../apitestingbot/github/webhook/{gitHubAppId}`.
37+
38+
Then, the bot can be triggered within issues/pull requests by sending a message such as "model a test".
39+
Once a test case has been modeled, the bot generates Java JUnit test code and comments it.
40+
41+
In pull requests, the bot may also propose spec-based test cases if it can access the developed service's OpenAPI documentation.
42+
Read the [repository adjustment guide](repo_adjustment_guide.md) for more information.
43+
44+
Dependencies:
45+
46+
- [CAE-Code-Generation-Service](https://github.com/rwth-acis/CAE-Code-Generation-Service)
47+
- [api-test-gen-service](https://github.com/rwth-acis/api-test-gen-service)
48+
49+
50+
## 🐳 Docker Environment Variables
51+
52+
Depending on the use case different environment variables are required:
53+
54+
| Environment Variable | Description | Required? |
55+
|--------------------------|----------------------------------------------------------------------------------------------|---------------------|
56+
| `BOT_MANAGER_URL` | REST API URL of Bot Manager Service ending with `/SBFManager`. | Yes |
57+
| `CODEX_API_TOKEN` | Token for accessing the OpenAI/Codex API. | Yes |
58+
| `CAE_BACKEND_URL` | REST API URL of CAE Model Persistence Service ending with `/CAE`. | Only in 1. Use-case |
59+
| `GITHUB_APP_ID` | Id of GitHub app that the bot should use. | Only in 2. Use-case |
60+
| `GITHUB_APP_PRIVATE_KEY` | Private key of GitHub app that the bot should use (already needs to be converted to PKCS#8). | Only in 2. Use-case |

api-testing-bot/build.gradle

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ dependencies {
2727

2828
implementation "org.openapitools.openapidiff:openapi-diff-core:2.1.0-beta.3"
2929
implementation "com.googlecode.json-simple:json-simple:1.1.1"
30-
implementation "com.konghq:unirest-java:3.13.10"
31-
implementation "i5:las2peer-api-test-model:0.1.6"
30+
implementation "com.konghq:unirest-java:3.13.11"
31+
implementation "i5:las2peer-api-test-model:1.0.0"
32+
33+
// GitHub API
34+
implementation "org.kohsuke:github-api:1.308"
35+
implementation "io.jsonwebtoken:jjwt-impl:0.11.5"
36+
implementation "io.jsonwebtoken:jjwt-jackson:0.11.5"
37+
38+
implementation "com.github.javaparser:javaparser-core:3.24.4"
3239
}
3340

3441
configurations {
@@ -263,4 +270,4 @@ jacocoTestReport {
263270
reports {
264271
xml.enabled true
265272
}
266-
}
273+
}

api-testing-bot/src/main/java/i5/las2peer/services/apiTestingBot/APITestingBot.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public class APITestingBot extends RESTService {
2222
private String botManagerURL;
2323
private String caeBackendURL;
2424

25+
/**
26+
* Id of GitHub app that the bot uses.
27+
*/
28+
private int gitHubAppId;
29+
30+
/**
31+
* Private key of GitHub app that the bot uses.
32+
*/
33+
private String gitHubAppPrivateKey;
34+
35+
private String codexAPIToken;
36+
2537
public APITestingBot() {
2638
setFieldValues();
2739
}
@@ -63,7 +75,7 @@ public void sendAPIDocChangesMessage(String openAPIDocOld, String openAPIDocUpda
6375
* @param webhookPayload Payload of the webhook call
6476
* @return JSONObject that can be used as the content of a monitoring message to trigger a webhook call.
6577
*/
66-
private JSONObject createWebhook(String url, JSONObject webhookPayload) {
78+
public static JSONObject createWebhook(String url, JSONObject webhookPayload) {
6779
JSONObject webhook = new JSONObject();
6880
webhook.put("url", url);
6981
webhook.put("payload", webhookPayload);
@@ -78,7 +90,7 @@ private JSONObject createWebhook(String url, JSONObject webhookPayload) {
7890
* @param channel Channel to which the message should be posted.
7991
* @return JSONObject representing the payload for a webhook call to the SBF that will trigger a chat message.
8092
*/
81-
private JSONObject createWebhookPayload(String message, String messenger, String channel) {
93+
public static JSONObject createWebhookPayload(String message, String messenger, String channel) {
8294
JSONObject webhookPayload = new JSONObject();
8395
webhookPayload.put("event", "chat_message");
8496
webhookPayload.put("message", message);
@@ -90,4 +102,20 @@ private JSONObject createWebhookPayload(String message, String messenger, String
90102
public String getCaeBackendURL() {
91103
return caeBackendURL;
92104
}
105+
106+
public String getBotManagerURL() {
107+
return botManagerURL;
108+
}
109+
110+
public int getGitHubAppId() {
111+
return gitHubAppId;
112+
}
113+
114+
public String getGitHubAppPrivateKey() {
115+
return gitHubAppPrivateKey;
116+
}
117+
118+
public String getCodexAPIToken() {
119+
return codexAPIToken;
120+
}
93121
}

0 commit comments

Comments
 (0)