generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dbe73b
commit 22c79f0
Showing
5 changed files
with
54 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Context } from "../../../types"; | ||
import { PullRequest } from "../entities/pull-request"; | ||
import { Super } from "./sqlite"; | ||
|
||
export class PullRequestAdapter extends Super { | ||
constructor(sqlite: DataSource, context: Context) { | ||
super(sqlite, context); | ||
} | ||
|
||
public async create(url: string) { | ||
const pullRequest = new PullRequest(); | ||
|
||
pullRequest.url = url; | ||
try { | ||
return await pullRequest.save(); | ||
} catch (e) { | ||
this.context.logger.error(`Failed to save the url ${url} to the DB.`); | ||
return null; | ||
} | ||
} | ||
} |
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,15 @@ | ||
import { Result } from "../proxy"; | ||
import { Context } from "../types"; | ||
|
||
/** | ||
* On pull request opening, we want to add the entry to start watching it. | ||
*/ | ||
export async function handlePullRequestOpened(context: Context): Promise<Result> { | ||
const { | ||
adapters: { | ||
sqlite: { pullRequest }, | ||
}, | ||
} = context; | ||
await pullRequest.create(context.payload.pull_request.html_url); | ||
return { status: "ok" }; | ||
} |
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,23 @@ | ||
import { handlePullRequestOpened } from "../handlers/pull-request-opened"; | ||
import { Context, Env, SupportedEventsU } from "../types"; | ||
|
||
export interface Result { | ||
status: "ok" | "failed" | "skipped"; | ||
content?: string; | ||
reason?: string; | ||
} | ||
|
||
const callbacks: { [k in SupportedEventsU]: (context: Context, env: Env) => Result | Promise<Result> } = { | ||
"pull_request.opened": handlePullRequestOpened, | ||
"pull_request.reopened": handlePullRequestOpened, | ||
}; | ||
|
||
export const proxyCallbacks = new Proxy(callbacks, { | ||
get(target, prop: SupportedEventsU) { | ||
if (!(prop in target)) { | ||
console.warn(`${prop} is not supported, skipping.`); | ||
return async () => ({ status: "skipped", reason: "unsupported_event" }); | ||
} | ||
return target[prop].bind(target); | ||
}, | ||
}); |
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