Skip to content

Commit

Permalink
fix(background-sync): clean up open PRs that are deleted on GitHub
Browse files Browse the repository at this point in the history
Pull requests cannot be deleted via API, only internally by GitHub staff.
This may lead to PR references to be "dangling". The resolution is to
treat all open PRs that could not be fetched as "upstream deleted".

Worst case these PRs will re-appear onto the board on PR activity, or
next background sync.

Closes #216
  • Loading branch information
nikku committed Nov 18, 2024
1 parent f0e0540 commit 6f3a91d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/app/lib/apps/background-sync/BackgroundSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ We automatically synchronize all repositories you granted us access to via the G
response => response.data.filter(issue => !('pull_request' in issue))
),

// open pulls
// open pulls, all
octokit.paginate(
octokit.pulls.list,
{
Expand Down Expand Up @@ -324,12 +324,23 @@ We automatically synchronize all repositories you granted us access to via the G
let expired = false;
let removed = false;

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

removed = true;
}

// if an open pull request was not found (we always
// fetch all), then it must have been deleted
if (issue.pull_request && issue.state === 'open') {
log.debug({ issue: key }, 'cleanup -> pull request deleted');

removed = true;
}

const updatedTime = new Date(updated_at).getTime();

if (updatedTime < expiryTime) {
Expand Down

0 comments on commit 6f3a91d

Please sign in to comment.