Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sync matching for multi team setup #34

Merged
merged 4 commits into from
Dec 6, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions pages/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
}
});

if (
syncs.length === 0 ||
!syncs.find(
sync => sync.linearUserId === (data.userId ?? data.creatorId)
)
) {
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)
);

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

Expand Down