MCPcopy Create free account
hub / github.com/EndBug/version-check / checkDiff

Function checkDiff

src/main.ts:330–395  ·  view source on GitHub ↗
(sha: string, version: string)

Source from the content-addressed store, hash-verified

328}
329
330async function checkDiff(sha: string, version: string) {
331 try {
332 const commit = await getCommit(sha)
333 const pkg = commit.files.find((f) => f.filename == packageFileName)
334 if (!pkg) {
335 info(`- ${sha.substr(0, 7)}: no changes to the package file`)
336 return false
337 }
338
339 const versionLines: {
340 added?: string
341 deleted?: string
342 } = {}
343
344 const rawLines = pkg.patch
345 .split('\n')
346 .filter(
347 (line) => line.includes('"version":') && ['+', '-'].includes(line[0])
348 )
349 if (rawLines.length > 2) {
350 info(`- ${sha.substr(0, 7)}: too many version lines`)
351 return false
352 }
353
354 for (const line of rawLines)
355 versionLines[line.startsWith('+') ? 'added' : 'deleted'] = line
356 if (!versionLines.added) {
357 info(`- ${sha.substr(0, 7)}: no "+ version" line`)
358 return false
359 }
360
361 const versions = {
362 added:
363 assumeSameVersion == 'new'
364 ? version
365 : parseVersionLine(versionLines.added),
366 deleted:
367 assumeSameVersion == 'old'
368 ? version
369 : !!versionLines.deleted && parseVersionLine(versionLines.deleted)
370 }
371 if (versions.added != version && !assumeSameVersion) {
372 info(
373 `- ${sha.substr(
374 0,
375 7
376 )}: added version doesn't match current one (added: "${
377 versions.added
378 }"; current: "${version}")`
379 )
380 return false
381 }
382
383 output('changed', true)
384 output('version', version)
385 if (versions.deleted)
386 output('type', semverDiff(versions.deleted, versions.added as string))
387 output('commit', commit.sha)

Callers 1

checkCommitsFunction · 0.70

Calls 6

infoFunction · 0.85
semverDiffFunction · 0.85
errorFunction · 0.85
getCommitFunction · 0.70
parseVersionLineFunction · 0.70
outputFunction · 0.70

Tested by

no test coverage detected