Skip to content

Commit

Permalink
Added indexing maintainer events operation
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Shien <bshien@amazon.com>
  • Loading branch information
bshien committed Oct 3, 2024
1 parent 1e4060f commit a411eea
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
22 changes: 22 additions & 0 deletions configs/operations/github-maintainer-events-monitor.yml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions src/call/github-maintainer-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 : 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<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-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 a411eea

Please sign in to comment.