-
Notifications
You must be signed in to change notification settings - Fork 139
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
Typescript migration #113
Merged
Merged
Typescript migration #113
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7976676
Initial TS migration
wolfy1339 13f9b8f
TS Migration Pt2
wolfy1339 39d0497
Move createChannel into the class definition
wolfy1339 4caaf78
Convert tests to TypeScript
wolfy1339 64174e4
Add tooling
wolfy1339 3a136b0
Update ignore files
wolfy1339 df81262
Add missing type package for nock
wolfy1339 5d91128
build(package): npm audit fix
gr2m 00ac3ae
types: Add stricter types from Probot for the Client options
wolfy1339 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ logs.json | |
server/public/main.min.* | ||
coverage | ||
.vscode | ||
index.js | ||
*.d.ts | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
index.ts | ||
tsconfig.json | ||
tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
const validator = require('validator') | ||
const EventSource = require('eventsource') | ||
const superagent = require('superagent') | ||
const url = require('url') | ||
const querystring = require('querystring') | ||
import validator = require('validator') | ||
import EventSource = require('eventsource') | ||
import superagent = require('superagent') | ||
import url = require('url') | ||
import querystring = require('querystring') | ||
|
||
type Severity = 'info' | 'error' | ||
|
||
interface Options { | ||
source: string | ||
target: string | ||
logger?: Pick<Console, Severity> | ||
} | ||
|
||
class Client { | ||
constructor ({ source, target, logger = console }) { | ||
source: string; | ||
target: string; | ||
logger: Pick<Console, Severity>; | ||
events!: EventSource; | ||
|
||
constructor ({ source, target, logger = console }: Options) { | ||
this.source = source | ||
this.target = target | ||
this.logger = logger | ||
this.logger = logger! | ||
|
||
if (!validator.isURL(this.source)) { | ||
throw new Error('The provided URL is invalid.') | ||
} | ||
} | ||
|
||
onmessage (msg) { | ||
static async createChannel () { | ||
return superagent.head('https://smee.io/new').redirects(0).catch((err) => { | ||
return err.response.headers.location | ||
}) | ||
} | ||
|
||
onmessage (msg: any) { | ||
const data = JSON.parse(msg.data) | ||
|
||
const target = url.parse(this.target, true) | ||
|
@@ -24,7 +43,7 @@ class Client { | |
|
||
delete data.query | ||
|
||
const req = superagent.post(target).send(data.body) | ||
const req = superagent.post(url.format(target)).send(data.body) | ||
|
||
delete data.body | ||
|
||
|
@@ -36,7 +55,7 @@ class Client { | |
if (err) { | ||
this.logger.error(err) | ||
} else { | ||
this.logger.info(`${req.method} ${req.url} - ${res.statusCode}`) | ||
this.logger.info(`${req.method} ${req.url} - ${res.status}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you recall why you did this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above.
|
||
} | ||
}) | ||
} | ||
|
@@ -45,15 +64,15 @@ class Client { | |
this.logger.info('Connected', this.events.url) | ||
} | ||
|
||
onerror (err) { | ||
onerror (err: any) { | ||
this.logger.error(err) | ||
} | ||
|
||
start () { | ||
const events = new EventSource(this.source) | ||
const events = new EventSource(this.source); | ||
|
||
// Reconnect immediately | ||
events.reconnectInterval = 0 | ||
(events as any).reconnectInterval = 0 // This isn't a valid property of EventSource | ||
|
||
events.addEventListener('message', this.onmessage.bind(this)) | ||
events.addEventListener('open', this.onopen.bind(this)) | ||
|
@@ -66,10 +85,4 @@ class Client { | |
} | ||
} | ||
|
||
Client.createChannel = async () => { | ||
return superagent.head('https://smee.io/new').redirects(0).catch((err, res) => { | ||
return err.response.headers.location | ||
}) | ||
} | ||
|
||
module.exports = Client | ||
export = Client |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you recall why you did this change?
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 don't remember exactly.
But removing it causes errors