diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml index 9b10ab5..6180f58 100644 --- a/.github/workflows/check-version-bump.yml +++ b/.github/workflows/check-version-bump.yml @@ -14,11 +14,11 @@ jobs: uses: EndBug/version-check@v2 with: diff-search: true - + - name: Log when changed if: steps.check.outputs.changed == 'true' run: 'echo "Version change found in commit ${{ steps.check.outputs.commit }}! New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"' - + - name: Log when unchanged if: steps.check.outputs.changed == 'false' run: 'echo "No version change! Please bump the version in package.json!" && exit 1' diff --git a/README.md b/README.md index ef16f11..06c4554 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,14 @@ When you run the above command, the following takes place: 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. #### List of Environment Variables (You can use them directly in the startup command, export them, or add them to the `.env` file): + | Name | Type | Default | Description | Example | -|-----------------------------|---------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------| +| --------------------------- | ------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | --- | | RESOURCE_CONFIG | String | '' | Path to resource config yaml file. | 'configs/resources/sample-resource.yml' | | OPERATION_CONFIG | String | '' | Path to operation config yaml file. | 'configs/operations/sample-operation.yml' | | INSTALLATION_ID | String | '' | Installation Id of your GitHub App, must install the App to repositories before retrieving the id. | '1234567890' | | ADDITIONAL_RESOURCE_CONTEXT | Boolean | false | Setting true will let each resource defined in RESOURCE_CONFIG to call GitHub Rest API and GraphQL for more detailed context (ex: node_id). Increase startup time. | true / false | -| SERVICE_NAME | String | 'default' | Set Service Name | 'My Service' |' +| SERVICE_NAME | String | 'default' | Set Service Name | 'My Service' | ' | #### Start the Service with Docker diff --git a/configs/operations/github-activity-events-monitor.yml b/configs/operations/github-activity-events-monitor.yml index bfcea22..54e9c54 100644 --- a/configs/operations/github-activity-events-monitor.yml +++ b/configs/operations/github-activity-events-monitor.yml @@ -16,6 +16,7 @@ events: - pull_request.unlabeled - pull_request.assigned - pull_request_review.submitted + - pull_request_review_comment.created - gollum - release.released - project.edited diff --git a/docker/README.md b/docker/README.md index dd42737..4d92e0e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -31,12 +31,10 @@ The `docker-compose.yml` is configured to use a Node.js image and to run the app The [Dockerfile](Dockerfile) is used to create a Docker image for the app. - ### Docker Compose File The [compose.yml](compose.yaml) file sets up a service (automation-app) to run the app: - ### Run multiple Services This allows to run multiple instances of the service with different configurations and ports. diff --git a/src/call/github-activity-events-monitor.ts b/src/call/github-activity-events-monitor.ts index 6a7492b..fc3d705 100644 --- a/src/call/github-activity-events-monitor.ts +++ b/src/call/github-activity-events-monitor.ts @@ -21,7 +21,7 @@ export default async function githubActivityEventsMonitor(app: Probot, context: const repoName = context.payload.repository?.name; const orgName = context.payload.organization?.login || context.payload.repository?.owner?.login; - const logData = { + const event = { id: context.id, organization: orgName, repository: repoName, @@ -38,10 +38,10 @@ export default async function githubActivityEventsMonitor(app: Probot, context: try { await client.index({ index: `github-activity-events-${month}-${year}`, - body: logData, + body: event, }); - app.log.info('Log data indexed successfully.'); + app.log.info('Event indexed successfully.'); } catch (error) { - app.log.error(`Error indexing log data: ${error}`); + app.log.error(`Error indexing event: ${error}`); } } diff --git a/test/call/github-activity-events-monitor.test.ts b/test/call/github-activity-events-monitor.test.ts new file mode 100644 index 0000000..863e518 --- /dev/null +++ b/test/call/github-activity-events-monitor.test.ts @@ -0,0 +1,87 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +import { Logger, Probot } from 'probot'; +import { OpensearchClient } from '../../src/utility/opensearch/opensearch-client'; +import githubActivityEventsMonitor from '../../src/call/github-activity-events-monitor'; + +jest.mock('../../src/utility/opensearch/opensearch-client'); + +describe('githubActivityEventsMonitor', () => { + let app: Probot; + let context: any; + let resource: any; + + beforeEach(() => { + app = new Probot({ appId: 1, secret: 'test', privateKey: 'test' }); + app.log = { + info: jest.fn(), + error: jest.fn(), + } as unknown as Logger; + context = { + name: 'eventType', + id: 'id', + payload: { + repository: { + name: 'repo', + owner: { login: 'org' }, + }, + action: 'action', + sender: { + login: 'sender', + }, + }, + }; + resource = { + organizations: new Map([ + [ + 'org', + { + repositories: new Map([['repo', 'repo object']]), + }, + ], + ]), + }; + }); + + it('should index events', async () => { + const mockClient = { + index: jest.fn().mockResolvedValue({}), + }; + (OpensearchClient as jest.Mock).mockImplementation(() => { + return { getClient: jest.fn().mockResolvedValue(mockClient) }; + }); + jest.spyOn(Date.prototype, 'toISOString').mockReturnValue('2024-10-04T21:00:06.875Z'); + await githubActivityEventsMonitor(app, context, resource); + expect(mockClient.index).toHaveBeenCalledWith({ + index: expect.stringMatching(/^github-activity-events-\d{2}-\d{4}$/), + body: expect.objectContaining({ + id: 'id', + organization: 'org', + repository: 'repo', + type: 'eventType', + action: 'action', + sender: 'sender', + created_at: '2024-10-04T21:00:06.875Z', + }), + }); + expect(app.log.info).toHaveBeenCalledWith('Event indexed successfully.'); + }); + + it('should log an error if indexing fails', async () => { + const mockClient = { + index: jest.fn().mockRejectedValue(new Error('Indexing failed')), + }; + (OpensearchClient as jest.Mock).mockImplementation(() => { + return { getClient: jest.fn().mockResolvedValue(mockClient) }; + }); + await githubActivityEventsMonitor(app, context, resource); + expect(app.log.error).toHaveBeenCalledWith('Error indexing event: Error: Indexing failed'); + }); +});