Skip to content
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

TypeError when GitHub URL is not defined #52 #53

Merged
merged 9 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/plugins/archive.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const { createError } = require('../lib/result');
const { stringBuilder, success, failure } = require('../lib/format');
const { createError, createWarning } = require('../lib/result');
const { stringBuilder, success, failure, warning } = require('../lib/format');
const { fetchGithub } = require('../lib/fetch');

const archivePlugin = async (pkg, _, options) => {

const output = stringBuilder(
'Checking if github repository is archived'
).withPadding(65);

if (!pkg?.repository?.url) {
warning(output.get());
return createWarning(`The module "${pkg.name}" does not specify its GitHub repository.`);
}

const githubTarget = pkg.repository.url
.split('github.com/')[1]
.replace('.git', '');

const repo = await fetchGithub(`/repos/${githubTarget}`, options.githubToken);

const output = stringBuilder(
'Checking if github repository is archived'
).withPadding(65);

if (repo.deprecated) {
failure(output.get());
return createError(
Expand Down
25 changes: 24 additions & 1 deletion test/plugins/archive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jest.mock('../../src/lib/fetch');
jest.mock('../../src/lib/format', () => ({
...jest.requireActual('../../src/lib/format'),
failure: jest.fn(),
success: jest.fn()
success: jest.fn(),
warning: jest.fn()
}));

afterEach(() => {
Expand Down Expand Up @@ -95,3 +96,25 @@ it('should log failure message when module is archived', async () => {

expect(format.failure).toHaveBeenCalled();
});

it('should log warning message when module does not specify its GitHub repository url', async () => {

const pkg = {
repository: {
}
};

const result = await archivePlugin(pkg, null, {});

expect(result.type).toBe('warning');
expect(format.warning).toHaveBeenCalled();
});

it('should log warning message when module does not specify its GitHub repository', async () => {

const pkg = {};
const result = await archivePlugin(pkg, null, {});

expect(result.type).toBe('warning');
expect(format.warning).toHaveBeenCalled();
});