Skip to content

Commit 7b1c82f

Browse files
Closes #3: [Enhancement] Add README on the structure of the app and usages
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
1 parent b70bd46 commit 7b1c82f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,39 @@ This repository hosts the source code of an automation app to handle the daily a
1515

1616
The automation app utilizes the [Probot](https://probot.github.io/) framework and [Octokit](https://docs.github.com/en/rest/using-the-rest-api/libraries-for-the-rest-api?apiVersion=2022-11-28) library to perform user-defined operations on top of the resources within GitHub. See [configs](configs/operations/hello-world.yml) yaml for more information.
1717

18+
## Usages
19+
20+
### Service
21+
22+
A **Service** is an instance of the app that manages and manipulates specific `Resources` while performing defined `Operations`.
23+
* **Resource**: Objects or entities the service will manage or modify, such as GitHub organizations, project, repositories, issues, etc.
24+
* **Operation**: A list of **Tasks** triggered by events with the resources.
25+
* **Task**: Executed sequentially within an **Operation** to perform action, such as create comments, update labels, add issue to project, etc.
26+
* **Call**: The callstack that contains the implementation of the aformentioned task action.
27+
28+
### Create a Service
29+
30+
To create a service, you need two configuration files:
31+
* **Resource configuration file**: Defines the resources that the service will manage or modify (`configs/resources/sample-resource.yml`).
32+
* **Operation configuration file**: Defines the operations (tasks) that the service will execute with the resources (`configs/resources/sample-operation.yml`).
33+
34+
### Start the Service
35+
36+
Once you have created the resource and operation configuration files, follow these steps to start the service:
37+
38+
1. Set the `RESOURCE_CONFIG` environment variable to the path of the resource configuration YAML file.
39+
1. Set the `OPERATION_CONFIG` environment variable to the path of the operation configuration YAML file.
40+
1. Run the service using the following command:
41+
42+
```bash
43+
RESOURCE_CONFIG=configs/resources/sample-resource.yml OPERATION_CONFIG=configs/operations/sample-operation.yml npm start
44+
```
45+
46+
When you run the above command, the following takes place:
47+
1. The app starts a **Service** instance based on the specified configurations.
48+
1. Retrieves the **[GitHub Context](https://probot.github.io/api/latest/classes/context.Context.html)** (or any other defined context) for all the resources listed in the resource config file.
49+
1. Registers and listens for events, executes the **Tasks** defined in the operation config. These tasks will be executed sequentially when the corresponding events occur.
50+
1851
## Code of Conduct
1952

2053
This project has adopted [the Open Source Code of Conduct](CODE_OF_CONDUCT.md).

src/app.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ export default async (app: Probot) => {
66
app.log.info('OpenSearch Automation App is starting now......');
77

88
const srvObj = new Service('Hello World Service');
9-
await srvObj.initService(app, 'configs/resources/peterzhu-organization.yml', 'configs/operations/hello-world.yml');
9+
const resourceConfig: string = process.env.RESOURCE_CONFIG || '';
10+
const processConfig: string = process.env.OPERATION_CONFIG || '';
11+
12+
if (resourceConfig === '' || processConfig === '') {
13+
throw new Error(`Invalid config path: RESOURCE_CONFIG=${resourceConfig} or OPERATION_CONFIG=${processConfig}`);
14+
}
15+
await srvObj.initService(app, resourceConfig, processConfig);
1016

1117
app.log.info('All objects initialized, start listening events......');
1218
};

0 commit comments

Comments
 (0)