Skip to content

Commit

Permalink
Merge branch 'release-1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oatymart committed Jul 13, 2021
2 parents 59c7738 + 9af5001 commit 6e84158
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-release-notes",
"version": "1.0.1",
"version": "1.1.0",
"description": "Extract release notes from a TAO extension",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/notes/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ module.exports = function requestsFactory() {
*/
async resolveTaoCommunityComposer(version) {
// Try to read composer.json via github tagged commit
log.doing(`Looking up tao-community v${version} on github`);
const fileUrl = `https://raw.githubusercontent.com/oat-sa/tao-community/v${version}/composer.json`;
log.doing(`Looking up tao-community ${version} on github`);
const fileUrl = `https://raw.githubusercontent.com/oat-sa/tao-community/${version}/composer.json`;
try {
const response = await fetch(fileUrl);
const fileData = await response.json();
return fileData.require;
}
catch (err) {
log.error(`Could not resolve tao-community v${version}`);
log.error(`Could not resolve tao-community ${version}`);
log.error(err);
return {};
}
Expand Down
16 changes: 14 additions & 2 deletions src/releaseNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ function setupOutputDir() {
fs.ensureDirSync(outputDir);
}

/**
* @param {String} version with leading `v` or without
* @returns {String}
*/
function normalizeVersion(version) {
//add leading v if missing
if(version[0] !== 'v') {
return `v${version}`;
}
return version;
}

/**
* From 2 lists of composer dependencies, build the data structure which will hold
* the list of all extensions with their name, starting and ending version
Expand Down Expand Up @@ -91,11 +103,11 @@ async function expandTaoCommunity(extensions = {}) {
const community = 'oat-sa/tao-community';

if (Object.keys(extensions).includes(community)) {
const tcVersion = extensions[community];
const tcVersion = normalizeVersion(extensions[community]);
const resolvedExtensions = await requests.resolveTaoCommunityComposer(tcVersion);
Object.assign(extensions, resolvedExtensions);
delete extensions[community];
log.done(`Retrieved ${Object.keys(resolvedExtensions).length} extension versions for tao-community v${tcVersion}.`);
log.done(`Retrieved ${Object.keys(resolvedExtensions).length} extension versions for tao-community ${tcVersion}.`);
}
return extensions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('the module api', t => {

test('returns data from tao-community', async t => {
t.plan(1);
const tcVersion = '0.121.0-alpha';
const tcVersion = 'v0.121.0-alpha';
const res = await requests.resolveTaoCommunityComposer(tcVersion);
t.deepEqual(
res,
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/releaseNotes/normalizeVersion/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2021 Open Assessment Technologies SA;
*/

/**
* Unit test the function normalizeVersion of the module src/releaseNotes.js
*
* @author Andrey Shaveko <[email protected]>
*/

const test = require('tape');
const rewire = require('rewire');
const releaseNotes = rewire('../../../../src/releaseNotes.js');

// Private function under test:
const normalizeVersion = releaseNotes.__get__('normalizeVersion');

test('version normalization', t => {
t.plan(3);
t.ok(typeof normalizeVersion === 'function', 'The normalizeVersion function exists');
t.ok(normalizeVersion('v0.1.1-alpha') === 'v0.1.1-alpha', 'leading `v` is not added if exists');
t.ok(normalizeVersion('0.1.1-alpha') === 'v0.1.1-alpha', 'leading `v` is added if does not exist');
t.end();
});

0 comments on commit 6e84158

Please sign in to comment.