Skip to content

Commit

Permalink
Closes #3: [Enhancement] Add README on the structure of the app and u…
Browse files Browse the repository at this point in the history
…sages

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon committed Sep 25, 2024
1 parent b70bd46 commit 7b1c82f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ This repository hosts the source code of an automation app to handle the daily a

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.

## Usages

### Service

A **Service** is an instance of the app that manages and manipulates specific `Resources` while performing defined `Operations`.
* **Resource**: Objects or entities the service will manage or modify, such as GitHub organizations, project, repositories, issues, etc.
* **Operation**: A list of **Tasks** triggered by events with the resources.
* **Task**: Executed sequentially within an **Operation** to perform action, such as create comments, update labels, add issue to project, etc.
* **Call**: The callstack that contains the implementation of the aformentioned task action.

### Create a Service

To create a service, you need two configuration files:
* **Resource configuration file**: Defines the resources that the service will manage or modify (`configs/resources/sample-resource.yml`).
* **Operation configuration file**: Defines the operations (tasks) that the service will execute with the resources (`configs/resources/sample-operation.yml`).

### Start the Service

Once you have created the resource and operation configuration files, follow these steps to start the service:

1. Set the `RESOURCE_CONFIG` environment variable to the path of the resource configuration YAML file.
1. Set the `OPERATION_CONFIG` environment variable to the path of the operation configuration YAML file.
1. Run the service using the following command:

```bash
RESOURCE_CONFIG=configs/resources/sample-resource.yml OPERATION_CONFIG=configs/operations/sample-operation.yml npm start
```

When you run the above command, the following takes place:
1. The app starts a **Service** instance based on the specified configurations.
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.
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.

## Code of Conduct

This project has adopted [the Open Source Code of Conduct](CODE_OF_CONDUCT.md).
Expand Down
8 changes: 7 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export default async (app: Probot) => {
app.log.info('OpenSearch Automation App is starting now......');

const srvObj = new Service('Hello World Service');
await srvObj.initService(app, 'configs/resources/peterzhu-organization.yml', 'configs/operations/hello-world.yml');
const resourceConfig: string = process.env.RESOURCE_CONFIG || '';
const processConfig: string = process.env.OPERATION_CONFIG || '';

if (resourceConfig === '' || processConfig === '') {
throw new Error(`Invalid config path: RESOURCE_CONFIG=${resourceConfig} or OPERATION_CONFIG=${processConfig}`);
}
await srvObj.initService(app, resourceConfig, processConfig);

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

0 comments on commit 7b1c82f

Please sign in to comment.