Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
shields
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
shields.io
shields
Commits
9496b6d8
Unverified
Commit
9496b6d8
authored
6 years ago
by
chris48s
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor [githubsize] (#3198)
parent
b0ff851e
Branches
Branches containing commit
Tags
18.2.5
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/github/github-size.service.js
+33
-62
33 additions, 62 deletions
services/github/github-size.service.js
with
33 additions
and
62 deletions
services/github/github-size.service.js
+
33
−
62
View file @
9496b6d8
'
use strict
'
'
use strict
'
const
Joi
=
require
(
'
joi
'
)
const
prettyBytes
=
require
(
'
pretty-bytes
'
)
const
prettyBytes
=
require
(
'
pretty-bytes
'
)
const
LegacyService
=
require
(
'
../legacy-service
'
)
const
{
nonNegativeInteger
}
=
require
(
'
../validators
'
)
const
{
makeBadgeData
:
getBadgeData
}
=
require
(
'
../../lib/badge-data
'
)
const
{
GithubAuthService
}
=
require
(
'
./github-auth-service
'
)
const
{
makeLogo
:
getLogo
}
=
require
(
'
../../lib/logos
'
)
const
{
documentation
,
errorMessagesFor
}
=
require
(
'
./github-helpers
'
)
const
{
const
{
NotFound
}
=
require
(
'
..
'
)
documentation
,
checkErrorResponse
:
githubCheckErrorResponse
,
const
schema
=
Joi
.
alternatives
(
}
=
require
(
'
./github-helpers
'
)
Joi
.
object
({
size
:
nonNegativeInteger
,
}).
required
(),
Joi
.
array
().
required
()
)
// This legacy service should be rewritten to use e.g. BaseJsonService.
module
.
exports
=
class
GithubSize
extends
GithubAuthService
{
//
// Tips for rewriting:
// https://github.com/badges/shields/blob/master/doc/rewriting-services.md
//
// Do not base new services on this code.
module
.
exports
=
class
GithubSize
extends
LegacyService
{
static
get
category
()
{
static
get
category
()
{
return
'
size
'
return
'
size
'
}
}
...
@@ -31,66 +30,38 @@ module.exports = class GithubSize extends LegacyService {
...
@@ -31,66 +30,38 @@ module.exports = class GithubSize extends LegacyService {
return
[
return
[
{
{
title
:
'
GitHub file size in bytes
'
,
title
:
'
GitHub file size in bytes
'
,
pattern
:
'
:user/:repo/:path
'
,
namedParams
:
{
namedParams
:
{
user
:
'
webcaetano
'
,
user
:
'
webcaetano
'
,
repo
:
'
craft
'
,
repo
:
'
craft
'
,
path
:
'
build/phaser-craft.min.js
'
,
path
:
'
build/phaser-craft.min.js
'
,
},
},
staticPreview
:
{
staticPreview
:
this
.
render
({
size
:
9170
}),
label
:
'
size
'
,
message
:
'
9.17 kB
'
,
color
:
'
green
'
,
},
keywords
:
[
'
repo
'
],
keywords
:
[
'
repo
'
],
documentation
,
documentation
,
},
},
]
]
}
}
static
registerLegacyRouteHandler
({
camp
,
cache
,
githubApiProvider
})
{
static
render
({
size
})
{
camp
.
route
(
return
{
/^
\/
github
\/
size
\/([^/]
+
)\/([^/]
+
)\/(
.*
)\.(
svg|png|gif|jpg|json
)
$/
,
message
:
prettyBytes
(
size
),
cache
((
data
,
match
,
sendBadge
,
request
)
=>
{
color
:
'
blue
'
,
const
user
=
match
[
1
]
// eg, mashape
const
repo
=
match
[
2
]
// eg, apistatus
const
path
=
match
[
3
]
const
format
=
match
[
4
]
const
apiUrl
=
`/repos/
${
user
}
/
${
repo
}
/contents/
${
path
}
`
const
badgeData
=
getBadgeData
(
'
size
'
,
data
)
if
(
badgeData
.
template
===
'
social
'
)
{
badgeData
.
logo
=
getLogo
(
'
github
'
,
data
)
}
}
githubApiProvider
.
request
(
request
,
apiUrl
,
{},
(
err
,
res
,
buffer
)
=>
{
if
(
githubCheckErrorResponse
(
badgeData
,
err
,
res
,
'
repo or file not found
'
)
)
{
sendBadge
(
format
,
badgeData
)
return
}
}
try
{
const
body
=
JSON
.
parse
(
buffer
)
async
fetch
({
user
,
repo
,
path
})
{
if
(
body
&&
Number
.
isInteger
(
body
.
size
))
{
return
this
.
_requestJson
({
badgeData
.
text
[
1
]
=
prettyBytes
(
body
.
size
)
url
:
`/repos/
${
user
}
/
${
repo
}
/contents/
${
path
}
`
,
badgeData
.
colorscheme
=
'
green
'
schema
,
sendBadge
(
format
,
badgeData
)
errorMessages
:
errorMessagesFor
(
'
repo or file not found
'
),
}
else
{
})
badgeData
.
text
[
1
]
=
'
not a regular file
'
sendBadge
(
format
,
badgeData
)
}
}
}
catch
(
e
)
{
badgeData
.
text
[
1
]
=
'
invalid
'
async
handle
({
user
,
repo
,
path
})
{
sendBadge
(
format
,
badgeData
)
const
body
=
await
this
.
fetch
({
user
,
repo
,
path
})
if
(
Array
.
isArray
(
body
))
{
throw
new
NotFound
({
prettyMessage
:
'
not a regular file
'
})
}
}
})
return
this
.
constructor
.
render
({
size
:
body
.
size
})
})
)
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment