Refactor route functions in BaseService (#2860)
The route helper functions are fairly well isolated from the rest of BaseService, with a few convenient entry points. They are easier to test in isolation. The way the code was written before, `pathToRegexp` was invoked once for every request, which seems inefficient. `route` was validated when it was used, though it seems more helpful to validate it up front. This breaks out `_makeFullUrl`, `_regex`, `_regexFromPath` into new helper functions `makeFullUrl`, `assertValidRoute`, `prepareRoute`, and `namedParamsForMatch`. It adds validation to route, and updates the services without patterns to include one, in order to pass the new validation rules.
This commit is contained in:
@@ -23,6 +23,7 @@ module.exports = class GithubCommitActivity extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/commit-activity',
|
||||
pattern: ':interval(y|4w|w)/:user/:repo',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ module.exports = class GithubCommitStatus extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/commit-status',
|
||||
pattern: ':user/:repo/:branch/:commit',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +29,6 @@ module.exports = class GithubCommitStatus extends LegacyService {
|
||||
return [
|
||||
{
|
||||
title: 'GitHub commit merge status',
|
||||
pattern: ':user/:repo/:branch/:commit',
|
||||
namedParams: {
|
||||
user: 'badges',
|
||||
repo: 'shields',
|
||||
|
||||
@@ -23,6 +23,7 @@ module.exports = class GithubDownloads extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github',
|
||||
pattern: '',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ module.exports = class GithubFollowers extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/followers',
|
||||
pattern: ':user',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +30,6 @@ module.exports = class GithubFollowers extends LegacyService {
|
||||
return [
|
||||
{
|
||||
title: 'GitHub followers',
|
||||
pattern: ':user',
|
||||
previewUrl: 'espadrine',
|
||||
// https://github.com/badges/shields/issues/2479
|
||||
// namedParams: {
|
||||
|
||||
@@ -22,6 +22,7 @@ module.exports = class GithubForks extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/forks',
|
||||
pattern: ':user/:repo',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ module.exports = class GithubStars extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/stars',
|
||||
pattern: ':user/:repo',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ module.exports = class GithubWatchers extends LegacyService {
|
||||
static get route() {
|
||||
return {
|
||||
base: 'github/watchers',
|
||||
pattern: ':user/:repo',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user