-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat/REUSE compliance Co-authored-by: chris48s <chris48s@users.noreply.github.com>
- Loading branch information
1 parent
a662e36
commit 1eba958
Showing
3 changed files
with
143 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
|
||
const COLOR_MAP = { | ||
checking: 'brightgreen', | ||
compliant: 'green', | ||
'non-compliant': 'red', | ||
unregistered: 'red', | ||
} | ||
|
||
const isReuseCompliance = Joi.string() | ||
.valid('compliant', 'non-compliant', 'checking', 'unregistered') | ||
.required() | ||
|
||
module.exports = { | ||
isReuseCompliance, | ||
COLOR_MAP, | ||
} |
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,55 @@ | ||
'use strict' | ||
const Joi = require('joi') | ||
const { BaseJsonService } = require('..') | ||
const { isReuseCompliance, COLOR_MAP } = require('./reuse-compliance-helper') | ||
|
||
const responseSchema = Joi.object({ | ||
status: isReuseCompliance, | ||
}).required() | ||
|
||
module.exports = class Reuse extends BaseJsonService { | ||
static category = 'license' | ||
|
||
static route = { | ||
base: 'reuse/compliance', | ||
pattern: ':remote+', | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'REUSE Compliance', | ||
namedParams: { | ||
remote: 'github.com/fsfe/reuse-tool', | ||
}, | ||
staticPreview: this.render({ status: 'compliant' }), | ||
keywords: ['license'], | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { | ||
label: 'reuse', | ||
} | ||
|
||
static render({ status }) { | ||
return { | ||
label: 'reuse', | ||
message: status, | ||
color: COLOR_MAP[status], | ||
} | ||
} | ||
|
||
async fetch({ remote }) { | ||
return await this._requestJson({ | ||
schema: responseSchema, | ||
url: `https://api.reuse.software/status/${remote}`, | ||
errorMessages: { | ||
400: 'Not a Git repository', | ||
}, | ||
}) | ||
} | ||
|
||
async handle({ remote }) { | ||
const { status } = await this.fetch({ remote }) | ||
return this.constructor.render({ status }) | ||
} | ||
} |
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,69 @@ | ||
'use strict' | ||
|
||
const t = (module.exports = require('../tester').createServiceTester()) | ||
const { isReuseCompliance, COLOR_MAP } = require('./reuse-compliance-helper') | ||
|
||
t.create('valid repo -- live') | ||
.get('/github.com/fsfe/reuse-tool.json') | ||
.expectBadge({ | ||
label: 'reuse', | ||
message: isReuseCompliance, | ||
color: COLOR_MAP[isReuseCompliance], | ||
}) | ||
|
||
t.create('valid repo -- compliant') | ||
.get('/github.com/username/repo.json') | ||
.intercept(nock => | ||
nock('https://api.reuse.software/status') | ||
.get('/github.com/username/repo') | ||
.reply(200, { status: 'compliant' }) | ||
) | ||
.expectBadge({ | ||
label: 'reuse', | ||
message: 'compliant', | ||
color: COLOR_MAP.compliant, | ||
}) | ||
|
||
t.create('valid repo -- non-compliant') | ||
.get('/github.com/username/repo.json') | ||
.intercept(nock => | ||
nock('https://api.reuse.software/status') | ||
.get('/github.com/username/repo') | ||
.reply(200, { status: 'non-compliant' }) | ||
) | ||
.expectBadge({ | ||
label: 'reuse', | ||
message: 'non-compliant', | ||
color: COLOR_MAP['non-compliant'], | ||
}) | ||
|
||
t.create('valid repo -- checking') | ||
.get('/github.com/username/repo.json') | ||
.intercept(nock => | ||
nock('https://api.reuse.software/status') | ||
.get('/github.com/username/repo') | ||
.reply(200, { status: 'checking' }) | ||
) | ||
.expectBadge({ | ||
label: 'reuse', | ||
message: 'checking', | ||
color: COLOR_MAP.checking, | ||
}) | ||
|
||
t.create('valid repo -- unregistered') | ||
.get('/github.com/username/repo.json') | ||
.intercept(nock => | ||
nock('https://api.reuse.software/status') | ||
.get('/github.com/username/repo') | ||
.reply(200, { status: 'unregistered' }) | ||
) | ||
.expectBadge({ | ||
label: 'reuse', | ||
message: 'unregistered', | ||
color: COLOR_MAP.unregistered, | ||
}) | ||
|
||
t.create('invalid repo').get('/github.com/repo/invalid-repo.json').expectBadge({ | ||
label: 'reuse', | ||
message: 'Not a Git repository', | ||
}) |