Skip to content

Commit e6797cc

Browse files
committed
fix(background-sync): clean up open PRs that are deleted on GitHub
Pull requests cannot be deleted via API, only internally by GitHub staff. This may lead to PR references to be "dangling". Closes #216
1 parent 6b72771 commit e6797cc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/app/lib/apps/background-sync/BackgroundSync.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ We automatically synchronize all repositories you granted us access to via the G
171171
response => response.data.filter(issue => !('pull_request' in issue))
172172
),
173173

174-
// open pulls
174+
// open pulls, all
175175
octokit.paginate(
176176
octokit.pulls.list,
177177
{
@@ -324,12 +324,23 @@ We automatically synchronize all repositories you granted us access to via the G
324324
let expired = false;
325325
let removed = false;
326326

327+
// if an open issue or pull request links to
328+
// a non-existing repository, then it must have been
329+
// removed
327330
if (!repositories[issue.repository.id]) {
328331
log.debug({ issue: key }, 'cleanup -> repository removed');
329332

330333
removed = true;
331334
}
332335

336+
// if an open pull request was not found (we always
337+
// fetch all), then it must have been deleted
338+
if (issue.pull_request && issue.state === 'open') {
339+
log.debug({ issue: key }, 'cleanup -> pull request deleted');
340+
341+
removed = true;
342+
}
343+
333344
const updatedTime = new Date(updated_at).getTime();
334345

335346
if (updatedTime < expiryTime) {

0 commit comments

Comments
 (0)