merge main & build

This commit is contained in:
Evgenii Korolevskii 2022-09-28 15:30:56 +02:00
parent 4ca3c96b49
commit cf081e76a2
2 changed files with 37 additions and 49 deletions

40
dist/index.js vendored
View File

@ -55,6 +55,7 @@ function getExistingNugetConfig(processRoot) {
return defaultConfigName; return defaultConfigName;
} }
function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
var _a, _b;
core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`);
let xml; let xml;
let sourceKeys = []; let sourceKeys = [];
@ -73,31 +74,26 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
if (typeof json.configuration === 'undefined') { if (typeof json.configuration === 'undefined') {
throw new Error(`The provided NuGet.config seems invalid.`); throw new Error(`The provided NuGet.config seems invalid.`);
} }
if (typeof json.configuration.packageSources != 'undefined') { if ((_b = (_a = json.configuration) === null || _a === void 0 ? void 0 : _a.packageSources) === null || _b === void 0 ? void 0 : _b.add) {
if (typeof json.configuration.packageSources.add != 'undefined') { const packageSources = json.configuration.packageSources.add;
// file has at least one <add> if (Array.isArray(packageSources)) {
if (typeof json.configuration.packageSources.add[0] === 'undefined') { packageSources.forEach(source => {
// file has only one <add> const value = source['@_value'];
if (json.configuration.packageSources.add['@_value'] core.debug(`source '${value}'`);
.toLowerCase() if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
.includes(feedUrl.toLowerCase())) { const key = source['@_key'];
const key = json.configuration.packageSources.add['@_key'];
sourceKeys.push(key); sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`); core.debug(`Found a URL with key ${key}`);
} }
} });
else { }
// file has 2+ <add> else {
for (let i = 0; i < json.configuration.packageSources.add.length; i++) { if (packageSources['@_value']
const source = json.configuration.packageSources.add[i]; .toLowerCase()
const value = source['@_value']; .includes(feedUrl.toLowerCase())) {
core.debug(`source '${value}'`); const key = packageSources['@_key'];
if (value.toLowerCase().includes(feedUrl.toLowerCase())) { sourceKeys.push(key);
const key = source['@_key']; core.debug(`Found a URL with key ${key}`);
sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`);
}
}
} }
} }
} }

View File

@ -71,36 +71,28 @@ function writeFeedToFile(
if (typeof json.configuration === 'undefined') { if (typeof json.configuration === 'undefined') {
throw new Error(`The provided NuGet.config seems invalid.`); throw new Error(`The provided NuGet.config seems invalid.`);
} }
if (typeof json.configuration.packageSources != 'undefined') { if (json.configuration?.packageSources?.add) {
if (typeof json.configuration.packageSources.add != 'undefined') { const packageSources = json.configuration.packageSources.add;
// file has at least one <add>
if (typeof json.configuration.packageSources.add[0] === 'undefined') { if (Array.isArray(packageSources)) {
// file has only one <add> packageSources.forEach(source => {
if ( const value = source['@_value'];
json.configuration.packageSources.add['@_value'] core.debug(`source '${value}'`);
.toLowerCase() if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
.includes(feedUrl.toLowerCase()) const key = source['@_key'];
) {
const key = json.configuration.packageSources.add['@_key'];
sourceKeys.push(key); sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`); core.debug(`Found a URL with key ${key}`);
} }
} else { });
// file has 2+ <add> } else {
for ( if (
let i = 0; packageSources['@_value']
i < json.configuration.packageSources.add.length; .toLowerCase()
i++ .includes(feedUrl.toLowerCase())
) { ) {
const source = json.configuration.packageSources.add[i]; const key = packageSources['@_key'];
const value = source['@_value']; sourceKeys.push(key);
core.debug(`source '${value}'`); core.debug(`Found a URL with key ${key}`);
if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
const key = source['@_key'];
sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`);
}
}
} }
} }
} }