|
1 | 1 | /** |
2 | 2 | * @module extractDependabotVersionBump |
3 | | - * @description Extract version bump information from Dependabot PRs description |
| 3 | + * @description Extract version bump information from Dependabot PRs description. |
| 4 | + * Handles both "Bumps" and "Updates" patterns. |
4 | 5 | * @param {string} description - the PR description |
5 | | - * @returns {string[]} V1 (to) and V2 (from) |
| 6 | + * @returns {string[]} An array with [to, from] versions, or null if no version info found |
6 | 7 | * @example {{ pr.description | extractDependabotVersionBump | compareSemver }} |
7 | 8 | * @license MIT |
8 | 9 | **/ |
9 | 10 |
|
10 | 11 |
|
11 | 12 | module.exports = (desc) => { |
12 | | - if (desc && desc !== '""' && desc !== "''" ) { |
13 | | - const matches = /Bumps.*from ([\d\.]+[A-Za-zαß]*) to ([\d\.]+[A-Za-zαß]*)/.exec(desc); |
14 | | - if (matches && matches.length == 3) { |
15 | | - var [_, from, to] = matches; |
16 | | - // remove trailing dot on to |
17 | | - if (to[to.length - 1] === ".") { |
| 13 | + if (desc && desc !== '""' && desc !== "''" ) { |
| 14 | + // Match both "Bumps" and "Updates" patterns with version numbers |
| 15 | + // The regex captures version numbers that follow "from" and "to" keywords |
| 16 | + const regex = /(Bumps|Updates).*?from ([\d\.]+[A-Za-zαß]*) to ([\d\.]+[A-Za-zαß]*)/; |
| 17 | + const matches = regex.exec(desc); |
| 18 | + if (matches && matches.length == 4) { |
| 19 | + var [_, action, from, to] = matches; |
| 20 | + // Remove trailing dot on the "to" version if present |
| 21 | + if (to && to.length > 0 && to[to.length - 1] === ".") { |
18 | 22 | to = to.slice(0, -1); |
19 | 23 | } |
| 24 | + // Return [to, from] format to be compatible with compareSemver |
20 | 25 | return [to, from]; |
21 | 26 | } |
22 | 27 | } |
|
0 commit comments