- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
f5abb20
commit f3f8d44
Showing
5 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface WebhookEvent { | ||
timestamp: Date; | ||
name: string; | ||
action: string; | ||
owner: string; | ||
repo: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {MongoClient, MongoClientOptions} from "mongodb"; | ||
import {WebhookEvent} from "../entities/WebhookEvent"; | ||
|
||
export class MongoDbService { | ||
client?: MongoClient = undefined; | ||
|
||
async getDatabase() { | ||
if (!this.client) { | ||
const options: MongoClientOptions = { | ||
authSource: 'admin', | ||
}; | ||
const connectionString = process.env.CREATE_ISSUE_BRANCH_MONGODB; | ||
if (!connectionString) { | ||
throw new Error('Environment variable CREATE_ISSUE_BRANCH_MONGODB not set'); | ||
} else { | ||
this.client = await MongoClient.connect(connectionString, options); | ||
} | ||
} | ||
return this.client.db('create-issue-branch'); | ||
} | ||
|
||
async storeEvent(event: WebhookEvent) { | ||
const db = await this.getDatabase(); | ||
const collection = db.collection<WebhookEvent>('action'); | ||
await collection.insertOne(event); | ||
} | ||
|
||
disconnect() { | ||
this.client?.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters