Skip to content

Commit

Permalink
Fix sync matching for multi team setup (#34)
Browse files Browse the repository at this point in the history
* Fix sync matching for multi team
* Add check for Linear team to all cases of syncs search
* Don't validate team when no teamId been passed
  • Loading branch information
scopsy committed Dec 6, 2022
1 parent 354e36e commit 9d72173
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions pages/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,23 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
}
});

if (
syncs.length === 0 ||
!syncs.find(
sync =>
sync.linearUserId === (data.userId ?? data.creatorId) &&
sync.linearTeamId === data.teamId
)
) {
const sync = syncs.find((sync) => {
// For comment events the teamId property from linear is not passed,
// so we fallback to only match on user
const isTeamMatching = data.teamId ? sync.linearTeamId === data.teamId : true;
const isUserMatching = sync.linearUserId === (data.userId ?? data.creatorId);

return isUserMatching && isTeamMatching;
});

if (syncs.length === 0 || !sync) {
console.log("Could not find Linear user in syncs.");
return res.status(200).send({
success: true,
message: "Could not find Linear user in syncs."
});
}

const sync = syncs.find(
sync =>
sync.linearUserId === (data.userId ?? data.creatorId) &&
sync.linearTeamId === data.teamId
);

if (!sync?.LinearTeam || !sync?.GitHubRepo) {
console.log("Could not find ticket's corresponding repo.");

Expand Down

0 comments on commit 9d72173

Please sign in to comment.