refactor: bundler managerData

This commit is contained in:
Rhys Arkins 2019-07-22 09:07:03 +02:00
parent 4591729a05
commit 236b66fa4e
4 changed files with 234 additions and 64 deletions

View file

@ -88,7 +88,9 @@ async function extractPackageFile(content, fileName) {
groupRes.deps.map(dep => ({ groupRes.deps.map(dep => ({
...dep, ...dep,
depTypes, depTypes,
managerData: {
lineNumber: dep.lineNumber + groupLineNumber + 1, lineNumber: dep.lineNumber + groupLineNumber + 1,
},
})) }))
); );
} }
@ -115,7 +117,9 @@ async function extractPackageFile(content, fileName) {
sourceRes.deps.map(dep => ({ sourceRes.deps.map(dep => ({
...dep, ...dep,
registryUrls: [repositoryUrl], registryUrls: [repositoryUrl],
managerData: {
lineNumber: dep.lineNumber + sourceLineNumber + 1, lineNumber: dep.lineNumber + sourceLineNumber + 1,
},
})) }))
); );
} }
@ -139,7 +143,9 @@ async function extractPackageFile(content, fileName) {
// eslint-disable-next-line no-loop-func // eslint-disable-next-line no-loop-func
platformsRes.deps.map(dep => ({ platformsRes.deps.map(dep => ({
...dep, ...dep,
managerData: {
lineNumber: dep.lineNumber + platformsLineNumber + 1, lineNumber: dep.lineNumber + platformsLineNumber + 1,
},
})) }))
); );
} }
@ -162,7 +168,9 @@ async function extractPackageFile(content, fileName) {
// eslint-disable-next-line no-loop-func // eslint-disable-next-line no-loop-func
ifRes.deps.map(dep => ({ ifRes.deps.map(dep => ({
...dep, ...dep,
managerData: {
lineNumber: dep.lineNumber + ifLineNumber + 1, lineNumber: dep.lineNumber + ifLineNumber + 1,
},
})) }))
); );
} }

View file

@ -18,7 +18,7 @@ function updateDependency(currentFileContent, upgrade) {
? '"' ? '"'
: "'"; : "'";
const lines = currentFileContent.split('\n'); const lines = currentFileContent.split('\n');
const lineToChange = lines[upgrade.lineNumber]; const lineToChange = lines[upgrade.managerData.lineNumber];
if (!lineToChange.includes(upgrade.depName)) { if (!lineToChange.includes(upgrade.depName)) {
logger.debug('No gem match on line'); logger.debug('No gem match on line');
return null; return null;
@ -37,7 +37,7 @@ function updateDependency(currentFileContent, upgrade) {
logger.debug('No changes necessary'); logger.debug('No changes necessary');
return currentFileContent; return currentFileContent;
} }
lines[upgrade.lineNumber] = newLine; lines[upgrade.managerData.lineNumber] = newLine;
return lines.join('\n'); return lines.join('\n');
} catch (err) { } catch (err) {
logger.info({ err }, 'Error setting new Gemfile value'); logger.info({ err }, 'Error setting new Gemfile value');

View file

@ -71,8 +71,11 @@ Object {
"depTypes": Array [ "depTypes": Array [
"doc", "doc",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 32, "lineNumber": 32,
}, },
},
Object { Object {
"currentValue": "~> 3.2.3", "currentValue": "~> 3.2.3",
"datasource": "rubygems", "datasource": "rubygems",
@ -80,14 +83,20 @@ Object {
"depTypes": Array [ "depTypes": Array [
"doc", "doc",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 33, "lineNumber": 33,
}, },
},
Object { Object {
"depName": "w3c_validators", "depName": "w3c_validators",
"depTypes": Array [ "depTypes": Array [
"doc", "doc",
], ],
"lineNumber": 2,
"managerData": Object {
"lineNumber": 34, "lineNumber": 34,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -97,8 +106,11 @@ Object {
"depTypes": Array [ "depTypes": Array [
"doc", "doc",
], ],
"lineNumber": 3,
"managerData": Object {
"lineNumber": 35, "lineNumber": 35,
}, },
},
Object { Object {
"depName": "dalli", "depName": "dalli",
"lineNumber": 39, "lineNumber": 39,
@ -131,7 +143,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 49, "lineNumber": 49,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -139,7 +154,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 50, "lineNumber": 50,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -147,7 +165,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 2,
"managerData": Object {
"lineNumber": 51, "lineNumber": 51,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -155,7 +176,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 3,
"managerData": Object {
"lineNumber": 52, "lineNumber": 52,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -163,7 +187,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 4,
"managerData": Object {
"lineNumber": 53, "lineNumber": 53,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -171,7 +198,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 5,
"managerData": Object {
"lineNumber": 54, "lineNumber": 54,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -179,7 +209,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 6,
"managerData": Object {
"lineNumber": 55, "lineNumber": 55,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -187,7 +220,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 7,
"managerData": Object {
"lineNumber": 56, "lineNumber": 56,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -195,7 +231,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 8,
"managerData": Object {
"lineNumber": 57, "lineNumber": 57,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -203,7 +242,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 9,
"managerData": Object {
"lineNumber": 58, "lineNumber": 58,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -211,7 +253,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"job", "job",
], ],
"lineNumber": 10,
"managerData": Object {
"lineNumber": 59, "lineNumber": 59,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -219,7 +264,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 64, "lineNumber": 64,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -227,7 +275,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 2,
"managerData": Object {
"lineNumber": 66, "lineNumber": 66,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -237,14 +288,20 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 3,
"managerData": Object {
"lineNumber": 67, "lineNumber": 67,
}, },
},
Object { Object {
"depName": "redis-namespace", "depName": "redis-namespace",
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 5,
"managerData": Object {
"lineNumber": 69, "lineNumber": 69,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -252,7 +309,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 7,
"managerData": Object {
"lineNumber": 71, "lineNumber": 71,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -260,7 +320,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 9,
"managerData": Object {
"lineNumber": 73, "lineNumber": 73,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -268,7 +331,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 10,
"managerData": Object {
"lineNumber": 74, "lineNumber": 74,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -276,7 +342,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"cable", "cable",
], ],
"lineNumber": 11,
"managerData": Object {
"lineNumber": 75, "lineNumber": 75,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -284,7 +353,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"storage", "storage",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 80, "lineNumber": 80,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -294,14 +366,20 @@ Object {
"depTypes": Array [ "depTypes": Array [
"storage", "storage",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 81, "lineNumber": 81,
}, },
},
Object { Object {
"depName": "azure-storage", "depName": "azure-storage",
"depTypes": Array [ "depTypes": Array [
"storage", "storage",
], ],
"lineNumber": 2,
"managerData": Object {
"lineNumber": 82, "lineNumber": 82,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -311,8 +389,11 @@ Object {
"depTypes": Array [ "depTypes": Array [
"storage", "storage",
], ],
"lineNumber": 4,
"managerData": Object {
"lineNumber": 84, "lineNumber": 84,
}, },
},
Object { Object {
"depName": "aws-sdk-sns", "depName": "aws-sdk-sns",
"lineNumber": 88, "lineNumber": 88,
@ -328,7 +409,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"ujs", "ujs",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 92, "lineNumber": 92,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -336,7 +420,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"ujs", "ujs",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 93, "lineNumber": 93,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -344,7 +431,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"test", "test",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 101, "lineNumber": 101,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -352,7 +442,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"test", "test",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 102, "lineNumber": 102,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -360,7 +453,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"test", "test",
], ],
"lineNumber": 105, "lineNumber": 0,
"managerData": Object {
"lineNumber": 101,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -368,7 +464,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"test", "test",
], ],
"lineNumber": 106, "lineNumber": 1,
"managerData": Object {
"lineNumber": 102,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -376,27 +475,39 @@ Object {
"depTypes": Array [ "depTypes": Array [
"test", "test",
], ],
"lineNumber": 8,
"managerData": Object {
"lineNumber": 109, "lineNumber": 109,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
"currentValue": ">= 1.8.1", "currentValue": ">= 1.8.1",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "nokogiri", "depName": "nokogiri",
"lineNumber": 0,
"managerData": Object {
"lineNumber": 113, "lineNumber": 113,
}, },
},
Object { Object {
"currentValue": ">=1.4.6", "currentValue": ">=1.4.6",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "racc", "depName": "racc",
"lineNumber": 3,
"managerData": Object {
"lineNumber": 116, "lineNumber": 116,
}, },
},
Object { Object {
"currentValue": "~> 1.3.6", "currentValue": "~> 1.3.6",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "sqlite3", "depName": "sqlite3",
"lineNumber": 6,
"managerData": Object {
"lineNumber": 119, "lineNumber": 119,
}, },
},
Object { Object {
"currentValue": ">= 0.18.0", "currentValue": ">= 0.18.0",
"datasource": "rubygems", "datasource": "rubygems",
@ -404,7 +515,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"db", "db",
], ],
"lineNumber": 122, "lineNumber": 0,
"managerData": Object {
"lineNumber": 113,
},
}, },
Object { Object {
"currentValue": ">= 0.4.10", "currentValue": ">= 0.4.10",
@ -413,34 +527,49 @@ Object {
"depTypes": Array [ "depTypes": Array [
"db", "db",
], ],
"lineNumber": 123, "lineNumber": 1,
"managerData": Object {
"lineNumber": 114,
},
}, },
Object { Object {
"depName": "activerecord-jdbcsqlite3-adapter", "depName": "activerecord-jdbcsqlite3-adapter",
"lineNumber": 0,
"managerData": Object {
"lineNumber": 128,
},
"skipReason": "no-version",
},
Object {
"depName": "activerecord-jdbcmysql-adapter",
"depTypes": Array [
"db",
],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 128,
},
"skipReason": "no-version",
},
Object {
"depName": "activerecord-jdbcpostgresql-adapter",
"depTypes": Array [
"db",
],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 129, "lineNumber": 129,
"skipReason": "no-version",
}, },
Object {
"depName": "activerecord-jdbcmysql-adapter",
"depTypes": Array [
"db",
],
"lineNumber": 131,
"skipReason": "no-version",
},
Object {
"depName": "activerecord-jdbcpostgresql-adapter",
"depTypes": Array [
"db",
],
"lineNumber": 132,
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
"currentValue": ">= 1.3.0", "currentValue": ">= 1.3.0",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "activerecord-jdbcsqlite3-adapter", "depName": "activerecord-jdbcsqlite3-adapter",
"lineNumber": 135, "lineNumber": 6,
"managerData": Object {
"lineNumber": 134,
},
}, },
Object { Object {
"currentValue": ">= 1.3.0", "currentValue": ">= 1.3.0",
@ -449,7 +578,10 @@ Object {
"depTypes": Array [ "depTypes": Array [
"db", "db",
], ],
"lineNumber": 137, "lineNumber": 0,
"managerData": Object {
"lineNumber": 128,
},
}, },
Object { Object {
"currentValue": ">= 1.3.0", "currentValue": ">= 1.3.0",
@ -458,23 +590,35 @@ Object {
"depTypes": Array [ "depTypes": Array [
"db", "db",
], ],
"lineNumber": 138, "lineNumber": 1,
"managerData": Object {
"lineNumber": 129,
},
}, },
Object { Object {
"currentValue": "~> 3.0", "currentValue": "~> 3.0",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "psych", "depName": "psych",
"lineNumber": 2,
"managerData": Object {
"lineNumber": 146, "lineNumber": 146,
}, },
},
Object { Object {
"currentValue": "~> 2.2", "currentValue": "~> 2.2",
"datasource": "rubygems", "datasource": "rubygems",
"depName": "ruby-oci8", "depName": "ruby-oci8",
"lineNumber": 152, "lineNumber": 0,
"managerData": Object {
"lineNumber": 151,
},
}, },
Object { Object {
"depName": "activerecord-oracle_enhanced-adapter", "depName": "activerecord-oracle_enhanced-adapter",
"lineNumber": 3,
"managerData": Object {
"lineNumber": 154, "lineNumber": 154,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -508,7 +652,10 @@ Object {
"deps": Array [ "deps": Array [
Object { Object {
"depName": "some_internal_gem", "depName": "some_internal_gem",
"lineNumber": 0,
"managerData": Object {
"lineNumber": 4, "lineNumber": 4,
},
"registryUrls": Array [ "registryUrls": Array [
"https://gems.example.com", "https://gems.example.com",
], ],
@ -516,7 +663,10 @@ Object {
}, },
Object { Object {
"depName": "another_internal_gem", "depName": "another_internal_gem",
"lineNumber": 1,
"managerData": Object {
"lineNumber": 5, "lineNumber": 5,
},
"registryUrls": Array [ "registryUrls": Array [
"https://gems.example.com", "https://gems.example.com",
], ],
@ -525,12 +675,18 @@ Object {
Object { Object {
"currentValue": "latest", "currentValue": "latest",
"depName": "ruby-debug", "depName": "ruby-debug",
"lineNumber": 0,
"managerData": Object {
"lineNumber": 9, "lineNumber": 9,
},
"skipReason": "invalid-value", "skipReason": "invalid-value",
}, },
Object { Object {
"depName": "sqlite3", "depName": "sqlite3",
"lineNumber": 1,
"managerData": Object {
"lineNumber": 10, "lineNumber": 10,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -539,7 +695,10 @@ Object {
"development", "development",
"optional => true", "optional => true",
], ],
"lineNumber": 0,
"managerData": Object {
"lineNumber": 14, "lineNumber": 14,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
Object { Object {
@ -548,7 +707,10 @@ Object {
"development", "development",
"optional => true", "optional => true",
], ],
"lineNumber": 1,
"managerData": Object {
"lineNumber": 15, "lineNumber": 15,
},
"skipReason": "no-version", "skipReason": "no-version",
}, },
], ],

View file

@ -11,7 +11,7 @@ describe('manager/docker-compose/update', () => {
it('replaces existing value', () => { it('replaces existing value', () => {
// gem "rack-cache", "~> 1.2" // gem "rack-cache", "~> 1.2"
const upgrade = { const upgrade = {
lineNumber: 13, managerData: { lineNumber: 13 },
depName: 'rack-cache', depName: 'rack-cache',
newValue: '~> 1.3', newValue: '~> 1.3',
}; };
@ -22,7 +22,7 @@ describe('manager/docker-compose/update', () => {
it('returns same', () => { it('returns same', () => {
// gem "rack-cache", "~> 1.2" // gem "rack-cache", "~> 1.2"
const upgrade = { const upgrade = {
lineNumber: 13, managerData: { lineNumber: 13 },
depName: 'rack-cache', depName: 'rack-cache',
newValue: '~> 1.2', newValue: '~> 1.2',
}; };
@ -32,7 +32,7 @@ describe('manager/docker-compose/update', () => {
it('returns null if mismatch', () => { it('returns null if mismatch', () => {
// gem "rack-cache", "~> 1.2" // gem "rack-cache", "~> 1.2"
const upgrade = { const upgrade = {
lineNumber: 13, managerData: { lineNumber: 13 },
depName: 'wrong', depName: 'wrong',
newValue: '~> 1.3', newValue: '~> 1.3',
}; };
@ -41,7 +41,7 @@ describe('manager/docker-compose/update', () => {
}); });
it('uses single quotes', () => { it('uses single quotes', () => {
const upgrade = { const upgrade = {
lineNumber: 0, managerData: { lineNumber: 0 },
depName: 'rack-cache', depName: 'rack-cache',
newValue: '~> 1.3', newValue: '~> 1.3',
}; };