Skip to content

Commit

Permalink
fix: remove database items for deleted installation
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jun 12, 2018
1 parent af55558 commit 5b4510f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
31 changes: 18 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,30 @@ module.exports = robot => {
});

robot.on('installation.deleted', async context => {
await removeRepositories(context.payload.repositories);
await removeInstallation(context.payload.installation.id);
});

robot.on('installation_repositories.removed', async context => {
await removeRepositories(context.payload.repositories_removed);
await removeRepositories(
context.payload.installation.id,
context.payload.repositories_removed
);
});

async function removeRepositories(repos) {
if (repos.length) {
repos.forEach(item => scheduler.stop(item));
async function removeInstallation(installationId) {
await App.getStorageStatic(db, `comments/${installationId}`).remove();
}

await App.getStorageStatic(db, 'comments').update(
Object.assign(
...repos.map(function(item) {
return {[item.id]: null};
})
)
);
}
async function removeRepositories(installationId, repos) {
repos.forEach(item => scheduler.stop(item));

await App.getStorageStatic(db, `comments/${installationId}`).update(
Object.assign(
...repos.map(function(item) {
return {[item.id]: null};
})
)
);
}

async function getApp(context) {
Expand Down
8 changes: 6 additions & 2 deletions src/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ ${commentBody}
GhResource.editComment({...commentParams, body: editedComment})
);

await this.getStorage(`comments/${payload.repository.id}`).push({
await this.getStorage(
`comments/${payload.installation.id}/${payload.repository.id}`
).push({
dt: Date.now(),
isReviewComment,
commentId,
Expand All @@ -97,7 +99,9 @@ ${commentBody}
const {only: type} = this.config;
const {payload, github} = this.context;

const commentsRef = this.getStorage(`comments/${payload.repository.id}`);
const commentsRef = this.getStorage(
`comments/${payload.installation.id}/${payload.repository.id}`
);
const comments = await commentsRef.limitToFirst(100).once('value');

const outdatedComments = [];
Expand Down

0 comments on commit 5b4510f

Please sign in to comment.