Skip to content

Commit

Permalink
feat: Implement a publish method
Browse files Browse the repository at this point in the history
Allows for controlling where new events go from the automatic
deployments.
  • Loading branch information
colinjfw committed Dec 18, 2019
1 parent fac961f commit 036dc49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { prDeploy } from "./pr-deploy";
import { auto } from "./auto";
import { Application } from "probot";
import { LockStore, WatchStore } from "./store";
import Webhooks from "@octokit/webhooks";

/**
* Instantiates all the components of the app with it's dependencies.
*/
export function app(
application: Application,
lockStore: LockStore,
watchStore: WatchStore
watchStore: WatchStore,
publish: (event: Webhooks.WebhookEvent<any>) => Promise<any>
) {
prClose(application);
prDeploy(application, lockStore);
auto(application, lockStore, watchStore);
auto(application, lockStore, watchStore, publish);
}
9 changes: 6 additions & 3 deletions src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { config, deploy } from "./deploy";
import { hash } from "./util";
import { v4 as uuid } from "uuid";
import { PayloadRepository } from "@octokit/webhooks";
import Webhooks from "@octokit/webhooks";

export function match(auto: string | undefined, ref: string) {
if (!auto) return false;
Expand All @@ -22,7 +23,8 @@ export function match(auto: string | undefined, ref: string) {
export function auto(
app: Application,
lockStore: LockStore,
watchStore: WatchStore
watchStore: WatchStore,
publish: (event: Webhooks.WebhookEvent<any>) => Promise<any>
) {
/**
* Add watch adds a watch on a specific ref, sha and repository.
Expand Down Expand Up @@ -214,6 +216,7 @@ export function auto(
repoId,
sha,
watches: watches.map(w => ({
target: w.target,
id: w.id,
ref: w.ref,
sha: w.sha,
Expand All @@ -224,8 +227,8 @@ export function auto(
);
await Promise.all(
watches.map(watch =>
app.receive({
id: context.id,
publish({
id: uuid(),
name: "push_watch",
payload: {
...watch,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { app } from "./app";

export = (application: Application) => {
const store = new InMemStore();
app(application, store, store);
app(application, store, store, application.receive.bind(application));
};
2 changes: 1 addition & 1 deletion test/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const deliverybot = (application: Application) => {
// Assign plain octokit to remove the plugins (like retries) the GitHub adds
// by default.
application['Octokit'] = Octokit;
app(application, store, store);
app(application, store, store, application.receive.bind(application));
};


Expand Down

0 comments on commit 036dc49

Please sign in to comment.