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
Refactor webhook handlers #36
Conversation
Fixes a problem when same users part of multiple linear teams would always choose first sync
export class ApiError extends Error { | ||
constructor(public message: string, public statusCode: number) { | ||
super(message); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New exception class used by the handlers, so they can throw instead of calling res.status
directly.
import { linearQuery } from "../apollo"; | ||
import { ApiError } from "../errors"; | ||
|
||
export async function githubWebhookHandler( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contents of this function are the contents of the github
if statement previously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you replaced early res.send()
calls with return
s / throw
s?
Fix/multi team bug
Refactor pettitio to got
Refactor created issue to got
Update petitio types for got
}); | ||
} | ||
} | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this - really clean
Monumental effort @scopsy - this will make the codebase much easier to navigate. Happy to review when ready. |
Will wait until we merge the petitio PR, because will have a lot of conflicts here. After some tests we could merge it aswell 🎉 |
Webhooks refactor internal
Fix sync teamId condition
@tedspare merged conflicts now 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@scopsy ready to merge? |
Good on my end, we have this deployed internally for the last few days already. |
Summary
Refactored the main POST route contents to use 2 handlers for webhook parsing. The file was really long, and it made testing and maintaining the codebase very hard. This refactor includes:
if
statement to a new fileutils/webhook/linear.handler.ts
if
statement to a new fileutils/webhook/github.handler.ts
req
object inside the handlers (body and headers passed as params)res.send
inside the handlers, the handlers exit in 2 ways:I hope these changes are the first step to further refactor the handler functions as they contain more duplicated code.