Skip to content

Commit

Permalink
feat(events-sync): support issue transfer
Browse files Browse the repository at this point in the history
Closes #92
  • Loading branch information
nikku committed Nov 18, 2020
1 parent ef992ec commit f8cff49
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions packages/app/lib/apps/events-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ const {
*
* @param {import("./webhook-events/WebhookEvents")} webhookEvents
* @param {import("../store")} store
* @param {import("../types").Logger} logger
*/
module.exports = function EventsSync(webhookEvents, store) {
module.exports = function EventsSync(webhookEvents, store, logger) {

const log = logger.child({
name: 'wuffle:user-access'
});

// issues /////////////////////

Expand Down Expand Up @@ -195,12 +200,49 @@ module.exports = function EventsSync(webhookEvents, store) {

// https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#issues

// issue transfer is mapped to the following GitHub events
//
// -> issues.opened (new issue is being opened by GitHub)
// -> issues.transferred (old issue was deleted by GitHub)
//
// Labels are not taken over during the transfer, thus we cannot retain
// the column mapping. We do, however retain the order.
//
webhookEvents.on([
'issues.transferred'
], async ({ payload }) => {

// rename issue reference, update issue links
// _if_ transferred org is on the board, otherwise delete issue
const {
issue,
repository,
changes
} = payload;

const {
new_issue: newIssue,
new_repository: newRepository
} = changes;

const storedIssue = store.getIssueById(getIdentifier(issue, repository));

if (!storedIssue) {
log.warn({ issue: issue.id }, 'stored original issue not found');

return;
}

const newStoredIssue = store.getIssueById(getIdentifier(newIssue, newRepository));

if (newStoredIssue) {
await store.updateIssue({
id: newStoredIssue.id,
order: storedIssue.order
});
} else {
log.warn({ issue: newIssue.id }, 'stored transferred issue not found');
}

return store.removeIssueById(storedIssue.id);
});

};

0 comments on commit f8cff49

Please sign in to comment.