Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@

![Commit Karma Logo](./assets/logo.png)

# commit-karma

Give one to get one!

This app tracks Code Reviews and Pull Requests across all projects with Commit Karma installed. It adds a failed Check to a Pull Request if the user who submitted the request does not have a positive Review to Request ratio.
This app tracks Code Reviews and Pull Requests across all projects with Commit
Karma installed. It adds a successful Check to a Pull Request if the user who
submitted the request has a positive Review to Request ratio.

## Install

Go to the Apps Marketplace page to configure installation

https://github.com/apps/commit-karma


## Setup

```sh
# Install dependencies
npm install

# Run the bot
npm start
deno run -A mod.ts
```

## License
Expand Down
2 changes: 2 additions & 0 deletions deps/oak.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "https://deno.land/x/oak@v10.2.0/mod.ts";
export { accepts } from "https://deno.land/x/oak_commons@0.1.1/negotiation.ts";
21 changes: 11 additions & 10 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { serve } from "https://deno.land/std@0.125.0/http/server.ts";

console.log("Listening on http://localhost:8000");
serve((req: Request) => {
console.log(req)
return new Response("Hello World!", {
status: 200,
headers: { "content-type": "text/plain" },
});
});
if (import.meta.main) {
try {
console.log("starting...");
const { start } = await import("./src/mod.ts");
await start();
} catch (err) {
console.log({ ...err });
console.log(err);
}
console.log("done.");
}
3 changes: 3 additions & 0 deletions src/controllers/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IContext {
secret?: string
}
6 changes: 6 additions & 0 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Application } from "../../deps/oak.ts";
import { IContext } from "./context.ts";

export abstract class Controller {
public abstract use(app: Application<IContext>): Promise<void>;
}
7 changes: 7 additions & 0 deletions src/controllers/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Application } from '../../deps/oak.ts';
import { WebhookController } from "./webhook.controller.ts";

export async function initControllers(app: Application) {
const webhook = new WebhookController();
await webhook.use(app);
}
22 changes: 22 additions & 0 deletions src/controllers/webhook.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Application, Status, Router, Request, Response } from '../../deps/oak.ts';
import { Controller } from "./controller.ts";

export class WebhookController extends Controller {

public async use(app: Application): Promise<void> {
const router = new Router()
router.post('/webhook', async (ctx, _next) => await this.handler(ctx.request, ctx.response));
app.use(router.allowedMethods());
app.use(router.routes());
await undefined;
}

private async handler(req: Request, res: Response) {
console.log(req)
res.status = Status.OK;
res.body = { ok: true };
res.headers.set('Content-Type', 'application/json');
await undefined;
}

}
12 changes: 12 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Application } from "../deps/oak.ts";
import { IContext } from "./controllers/context.ts";
import { initControllers } from "./controllers/mod.ts";

export async function start() {
const app = new Application<IContext>();
await initControllers(app);
app.addEventListener("listen", (e) => {
console.log(`Listening on http://localhost:${e.port}`);
});
await app.listen({ port: 8000 });
}