From 5ad28dad43a56956e9b9f54ebfc90a88148151b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Vladovi=C4=87?= Date: Sun, 8 Nov 2020 03:39:19 +0100 Subject: [PATCH] chore: add `.editorconfig` (#446) Fix whitespace & missing newline issues. --- .editorconfig | 13 +++ .eslintrc.yml | 1 - .github/ISSUE_TEMPLATE.md | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .vscode/settings.json | 2 +- api/badge.ts | 1 - api/cocoapods.ts | 68 ++++++++-------- api/docker.ts | 4 +- api/gitlab.ts | 1 - api/maven.ts | 110 +++++++++++++------------- api/npm.ts | 2 +- api/opam.ts | 2 +- api/winget.ts | 2 +- libs/docker.ts | 4 +- static/sponsors/sentry.svg | 2 +- 15 files changed, 113 insertions(+), 103 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2c5317a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +charset = utf-8 +indent_size = 2 +indent_style = space +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc.yml b/.eslintrc.yml index 77e4008..dadbc3b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -41,4 +41,3 @@ rules: react/no-unused-prop-types: warn react/react-in-jsx-scope: off react/prop-types: off # TODO: open later - diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index cc7d8cd..d359a97 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,2 +1,2 @@ \ No newline at end of file +👉 https://opencollective.com/badgen/donate --> diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e1ad663..d3f2cdb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -47,7 +47,7 @@ jobs: with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. + # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main diff --git a/.vscode/settings.json b/.vscode/settings.json index 3662b37..25fa621 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { "typescript.tsdk": "node_modules/typescript/lib" -} \ No newline at end of file +} diff --git a/api/badge.ts b/api/badge.ts index e62651a..27e40bb 100644 --- a/api/badge.ts +++ b/api/badge.ts @@ -36,4 +36,3 @@ async function handler ({ label, status, color }: PathArgs) { // '/badge/platform/ios,macos,tvos?list=|': 'list (custom seprator)' // } // } - diff --git a/api/cocoapods.ts b/api/cocoapods.ts index 54e6cbb..c4b3a01 100644 --- a/api/cocoapods.ts +++ b/api/cocoapods.ts @@ -1,34 +1,34 @@ -import got from '../libs/got' -import { version as versionName, versionColor } from '../libs/utils' -import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' - -export default createBadgenHandler({ - title: 'Cocoapods', - examples: { - '/cocoapods/v/AFNetworking': 'version', - '/cocoapods/p/AFNetworking': 'platform', - }, - handlers: { - '/cocoapods/:topic/:pod': handler - } -}) - -async function handler ({topic, pod}: PathArgs) { - const endpoint = `https://trunk.cocoapods.org/api/v1/pods/${pod}/specs/latest` - const { version, platforms } = await got(endpoint).json() - - switch (topic) { - case 'v': - return { - subject: 'pod', - status: versionName(version), - color: versionColor(version) - } - case 'p': - return { - subject: 'platform', - status: Object.keys(platforms).join(' | '), - color: 'grey' - } - } -} +import got from '../libs/got' +import { version as versionName, versionColor } from '../libs/utils' +import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' + +export default createBadgenHandler({ + title: 'Cocoapods', + examples: { + '/cocoapods/v/AFNetworking': 'version', + '/cocoapods/p/AFNetworking': 'platform', + }, + handlers: { + '/cocoapods/:topic/:pod': handler + } +}) + +async function handler ({topic, pod}: PathArgs) { + const endpoint = `https://trunk.cocoapods.org/api/v1/pods/${pod}/specs/latest` + const { version, platforms } = await got(endpoint).json() + + switch (topic) { + case 'v': + return { + subject: 'pod', + status: versionName(version), + color: versionColor(version) + } + case 'p': + return { + subject: 'platform', + status: Object.keys(platforms).join(' | '), + color: 'grey' + } + } +} diff --git a/api/docker.ts b/api/docker.ts index c557608..456262a 100644 --- a/api/docker.ts +++ b/api/docker.ts @@ -131,7 +131,7 @@ async function layersHandler ({ scope, name, tag, architecture, variant }: PathA tag = tag ? tag : 'latest' architecture = architecture ? architecture : 'amd64' variant = variant ? variant : '' - + const token = (await getDockerAuthToken(scope, name)).token const manifest_list = await getManifestList(scope, name, tag, architecture, variant, token) @@ -160,7 +160,7 @@ async function metadataHandler ({ type, scope, name, tag, architecture, variant tag = tag ? tag : 'latest' architecture = architecture ? architecture : 'amd64' variant = variant ? variant : '' - + const token = (await getDockerAuthToken(scope, name)).token const manifest_list = await getManifestList(scope, name, tag, architecture, variant, token) diff --git a/api/gitlab.ts b/api/gitlab.ts index 1c2c04d..099ad2e 100644 --- a/api/gitlab.ts +++ b/api/gitlab.ts @@ -262,4 +262,3 @@ const fullResponsePaths = 'tags', 'contributors' ] - diff --git a/api/maven.ts b/api/maven.ts index c0e66ed..570b057 100644 --- a/api/maven.ts +++ b/api/maven.ts @@ -1,55 +1,55 @@ -import cheerio from 'cheerio' -import got from '../libs/got' -import { version as versionName, versionColor } from '../libs/utils' -import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' - -export default createBadgenHandler({ - title: 'Maven', - examples: { - '/maven/v/maven-central/com.google.code.gson/gson': 'version (maven-central)', - '/maven/v/metadata-url/https/repo1.maven.org/maven2/com/google/code/gson/gson/maven-metadata.xml': 'version (maven metadata url)', - }, - handlers: { - '/maven/v/maven-central/:group/:artifact': mavenCentralHandler, - '/maven/v/metadata-url/:path+': mavenUrlHandler, - } -}) - -async function mavenCentralHandler ({group, artifact}: PathArgs) { - group = group.replace(/\./g, '/') - const xml = await got(`https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml`).text() - const version = getLastVersionFromMetadata(xml) - return { - subject: 'maven-central', - status: versionName(version), - color: versionColor(version) - } -} - -async function mavenUrlHandler ({path}: PathArgs) { - if (path.startsWith('http/')) { - path = path.slice(0, 4) + ':/' + path.slice(4) - } else if (path.startsWith('https/')) { - path = path.slice(0, 5) + ':/' + path.slice(5) - } else if (path.startsWith('http:/')) { - path = path.slice(0, 5) + '/' + path.slice(5) - } else if (path.startsWith('https:/')) { - path = path.slice(0, 6) + '/' + path.slice(6) - } - const xml = await got(path).text() - const version = getLastVersionFromMetadata(xml) - return { - subject: 'maven', - status: versionName(version), - color: versionColor(version) - } -} - -const getLastVersionFromMetadata = (xml: string) => { - const $ = cheerio.load(xml, {xmlMode: true}) - const versions = $('metadata').children('versioning').children('versions').children('version') - if (versions.length === 0) { - return 'unknown' - } - return versions.last().text() -} +import cheerio from 'cheerio' +import got from '../libs/got' +import { version as versionName, versionColor } from '../libs/utils' +import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' + +export default createBadgenHandler({ + title: 'Maven', + examples: { + '/maven/v/maven-central/com.google.code.gson/gson': 'version (maven-central)', + '/maven/v/metadata-url/https/repo1.maven.org/maven2/com/google/code/gson/gson/maven-metadata.xml': 'version (maven metadata url)', + }, + handlers: { + '/maven/v/maven-central/:group/:artifact': mavenCentralHandler, + '/maven/v/metadata-url/:path+': mavenUrlHandler, + } +}) + +async function mavenCentralHandler ({group, artifact}: PathArgs) { + group = group.replace(/\./g, '/') + const xml = await got(`https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml`).text() + const version = getLastVersionFromMetadata(xml) + return { + subject: 'maven-central', + status: versionName(version), + color: versionColor(version) + } +} + +async function mavenUrlHandler ({path}: PathArgs) { + if (path.startsWith('http/')) { + path = path.slice(0, 4) + ':/' + path.slice(4) + } else if (path.startsWith('https/')) { + path = path.slice(0, 5) + ':/' + path.slice(5) + } else if (path.startsWith('http:/')) { + path = path.slice(0, 5) + '/' + path.slice(5) + } else if (path.startsWith('https:/')) { + path = path.slice(0, 6) + '/' + path.slice(6) + } + const xml = await got(path).text() + const version = getLastVersionFromMetadata(xml) + return { + subject: 'maven', + status: versionName(version), + color: versionColor(version) + } +} + +const getLastVersionFromMetadata = (xml: string) => { + const $ = cheerio.load(xml, {xmlMode: true}) + const versions = $('metadata').children('versioning').children('versions').children('version') + if (versions.length === 0) { + return 'unknown' + } + return versions.last().text() +} diff --git a/api/npm.ts b/api/npm.ts index ff32193..c20526e 100644 --- a/api/npm.ts +++ b/api/npm.ts @@ -83,7 +83,7 @@ async function npmMetadata (pkg: string, ver = 'latest'): Promise { } const endpoint = `${host}/${pkg}/${ver}` return got(endpoint).json() - + } async function pkgJson (pkg: string, tag = 'latest'): Promise { diff --git a/api/opam.ts b/api/opam.ts index 864c41e..1d7c279 100644 --- a/api/opam.ts +++ b/api/opam.ts @@ -59,7 +59,7 @@ async function handler ({ topic, pkg }: PathArgs) { function getPackageInfo(html: string): PackageInfo { const info: PackageInfo = { version: '', license: '', downloads: NaN } - + const $ = cheerio.load(html) const text = (selector: any) => $(selector).text().trim() diff --git a/api/winget.ts b/api/winget.ts index 9295335..0360edc 100644 --- a/api/winget.ts +++ b/api/winget.ts @@ -110,7 +110,7 @@ async function handler ({ topic, appId }: PathArgs) { case 'v': { const versions = await fetchVersions(appId) const ver = last(versions).toString() - + return { subject: 'winget', status: version(ver), diff --git a/libs/docker.ts b/libs/docker.ts index aa6e18f..3d7ef6b 100644 --- a/libs/docker.ts +++ b/libs/docker.ts @@ -9,7 +9,7 @@ export function getDockerAuthToken(scope: string, name: string) { service: service, scope: `repository:${scope}/${name}:pull` } - + const resp = got.get("token", { prefixUrl, searchParams }).json() if (! resp) { @@ -86,4 +86,4 @@ export async function getImageConfig(scope: string, name: string, diges throw new BadgenError({ status: 'image config error' }) } return image_config -} \ No newline at end of file +} diff --git a/static/sponsors/sentry.svg b/static/sponsors/sentry.svg index 59b79bc..8a8d226 100644 --- a/static/sponsors/sentry.svg +++ b/static/sponsors/sentry.svg @@ -1 +1 @@ -sentry-logo-black \ No newline at end of file +sentry-logo-black