From a411eea13265c995846980689a10b1bbafc5ddde Mon Sep 17 00:00:00 2001 From: Brandon Shien Date: Thu, 3 Oct 2024 10:47:36 -0700 Subject: [PATCH] Added indexing maintainer events operation Signed-off-by: Brandon Shien --- .../github-maintainer-events-monitor.yml | 22 +++++++++ src/call/github-maintainer-events-monitor.ts | 47 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 configs/operations/github-maintainer-events-monitor.yml create mode 100644 src/call/github-maintainer-events-monitor.ts diff --git a/configs/operations/github-maintainer-events-monitor.yml b/configs/operations/github-maintainer-events-monitor.yml new file mode 100644 index 0000000..3d499a8 --- /dev/null +++ b/configs/operations/github-maintainer-events-monitor.yml @@ -0,0 +1,22 @@ +--- +name: Maintainer Events Monitor + +events: + - issues + - issue_comment + - label + - push + - pull_request + - gollum + - release + - package + - project + - project_card + - project_column + - projects_v2_item + - milestone + - deployment + +tasks: + - name: Maintainer Events Monitor Operation + call: github-maintainer-events-monitor@default diff --git a/src/call/github-maintainer-events-monitor.ts b/src/call/github-maintainer-events-monitor.ts new file mode 100644 index 0000000..b6ed218 --- /dev/null +++ b/src/call/github-maintainer-events-monitor.ts @@ -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 : githubMaintainerEventsMonitor +// Description : Indexes events pertaining to maintainer 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 githubMaintainerEventsMonitor(app: Probot, context: any, resource: Resource): Promise { + 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-events-${month}-${year}`, + body: logData, + }); + app.log.info('Log data indexed successfully.'); + } catch (error) { + app.log.error(`Error indexing log data: ${error}`); + } +}