mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Add EventsConsumer
This commit is contained in:
parent
08d33f6e5e
commit
e5fd15ba40
1 changed files with 37 additions and 0 deletions
37
src/events/consumer.ts
Normal file
37
src/events/consumer.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import GithubClient from "src/github/client";
|
||||
import { type Event } from "./types";
|
||||
import MetadataStore from "src/metadata-store";
|
||||
|
||||
export default class EventsConsumer {
|
||||
constructor(
|
||||
private readonly client: GithubClient,
|
||||
private readonly metadataStore: MetadataStore,
|
||||
private readonly owner: string,
|
||||
private readonly repo: string,
|
||||
private readonly branch: string,
|
||||
) {}
|
||||
|
||||
async process(event: Event): Promise<void> {
|
||||
if (event.type == "create" || event.type == "modify") {
|
||||
const res = await this.client.uploadFile(
|
||||
this.owner,
|
||||
this.repo,
|
||||
this.branch,
|
||||
event.filePath,
|
||||
);
|
||||
// Reset dirty state
|
||||
this.metadataStore.data[event.filePath].dirty = false;
|
||||
this.metadataStore.save();
|
||||
} else if (event.type == "delete") {
|
||||
const res = await this.client.deleteFile(
|
||||
this.owner,
|
||||
this.repo,
|
||||
this.branch,
|
||||
event.filePath,
|
||||
);
|
||||
// File has been deleted, no need to keep track of it anymore
|
||||
delete this.metadataStore.data[event.filePath];
|
||||
this.metadataStore.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue