Skip to content

Commit

Permalink
Added indexing user activity events operation
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Shien <[email protected]>
  • Loading branch information
bshien committed Oct 3, 2024
1 parent 8b9662b commit 4fde209
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
25 changes: 25 additions & 0 deletions configs/operations/github-activity-events-monitor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Activity Events Monitor

events:
- issues.opened
- issues.closed
- issues.labeled
- issues.unlabeled
- issues.transferred
- issues.assigned
- issue_comment.created
- push
- pull_request.closed
- pull_request.opened
- pull_request.labeled
- pull_request.unlabeled
- pull_request.assigned
- pull_request_review.submitted
- gollum
- release.released
- project.edited

tasks:
- name: Activity Events Monitor Operation
call: github-activity-events-monitor@default
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensearch-automation-app",
"version": "0.1.6",
"version": "0.1.7",
"description": "An Automation App that handles all your GitHub Repository Activities",
"author": "Peter Zhu",
"homepage": "https://github.com/opensearch-project/automation-app",
Expand Down
47 changes: 47 additions & 0 deletions src/call/github-activity-events-monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*/

// Name : githubActivityEventsMonitor
// Description : Indexes events pertaining to user activity to OpenSearch

import { Probot } from 'probot';
import { Resource } from '../service/resource/resource';
import { validateResourceConfig } from '../utility/verification/verify-resource';
import { OpensearchClient } from '../utility/opensearch/opensearch-client';

export default async function githubActivityEventsMonitor(app: Probot, context: any, resource: Resource): Promise<void> {
if (!(await validateResourceConfig(app, context, resource))) return;

const repoName = context.payload.repository?.name;
const orgName = context.payload.organization?.login || context.payload.repository?.owner?.login;

const logData = {
id: context.id,
organization: orgName,
repository: repoName,
type: context.name,
action: context.payload.action,
sender: context.payload.sender?.login,
created_at: new Date().toISOString(),
};

const client = await new OpensearchClient().getClient();

const [month, year] = [new Date().getMonth() + 1, new Date().getFullYear()].map((num) => String(num).padStart(2, '0'));

try {
await client.index({
index: `github-activity-events-${month}-${year}`,
body: logData,
});
app.log.info('Log data indexed successfully.');
} catch (error) {
app.log.error(`Error indexing log data: ${error}`);
}
}

0 comments on commit 4fde209

Please sign in to comment.