Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency parsing from Renovate dependency dashboard #32

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions utils/renovate/dependencyDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export class Dependency {
// Matches CR LF or CR or LF.
const LINE_SEPARATOR_REGEX = /\r?\n|\r|\n/g;

// Matches the part of the Dependency Dashboard body text between the header and the horizontal rule,
// without capturing the header or the horizontal rule itself.
//
// This will prevent false positives from being detected in the preamble.
const DETECTED_DEPENDENCIES_SECTION_REGEX = /(?<=## Detected dependencies)(.*)(?=---)/s;

// Matches text in backticks separated by a space.
// Group 1 is interpreted as the name, and group 2 the version.
// Examples:
Expand All @@ -28,11 +34,22 @@ const DEPENDENCY_NAME_AND_VERSION_REGEX = /`(\S+?) (.*)`/;
const issueIsRenovateDependencyDashboard = (issue) =>
issue.user.login === "renovate[bot]" && issue.pull_request === undefined;

const getDetectedDependencies = (issue) => {
const match = issue.body.match(DETECTED_DEPENDENCIES_SECTION_REGEX);

if (match === null) {
return null;
}

return match[0];
}

const parseDependenciesFromDashboard = (issue) =>
issue.body
.split(LINE_SEPARATOR_REGEX)
.map(parseDependencyFromLine)
.filter((dependency) => dependency !== null);
getDetectedDependencies(issue)
?.split(LINE_SEPARATOR_REGEX)
?.map(parseDependencyFromLine)
?.filter((dependency) => dependency !== null)
?? [];

const parseDependencyFromLine = (line) => {
const match = line.match(DEPENDENCY_NAME_AND_VERSION_REGEX);
Expand Down
12 changes: 11 additions & 1 deletion utils/renovate/dependencyDashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ describe("handleIssuesApiResponse", () => {
user: {
login: "renovate[bot]",
},
body: '# Dependency Dashboard\nList of dependencies:\n- `libquux v4.1.1.rc4`\n- `@xyzzy/utils "~> 22.04 Questing Quokka"`\n\nHere\'s some more:\n- `baz-framework ^0.1`',
body: '# Dependency Dashboard\n'
+ 'Here\'s some things in the preamble that should not be picked up:\n'
+ '`fake-dependency`, `another-fake-dependency`\n'
+ '\n'
+ '## Detected dependencies\n'
+ '- `libquux v4.1.1.rc4`\n'
+ '- `@xyzzy/utils "~> 22.04 Questing Quokka"`\n'
+ '\n'
+ 'Here\'s some more:\n'
+ '- `baz-framework ^0.1`\n'
+ '---',
},
],
};
Expand Down
Loading