Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-weisberg-qz committed Aug 21, 2024
1 parent e209cc9 commit 2ef3b98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
13 changes: 6 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1884,15 +1884,11 @@ function partOfApp(changedFiles, app) {
});
}
function getFirstTwoDirectories(filePath) {
// Normalize the path to handle any inconsistencies
const normalizedPath = path.normalize(filePath);
// Split the path into parts based on the OS-specific separator
const parts = normalizedPath.split(path.sep).filter(Boolean); // filter(Boolean) removes empty strings
// Check if the path has at least two segments
if (parts.length < 2) {
return parts.join(path.sep); // Return the entire path if less than two directories
}
// Join the first two segments
return parts.slice(0, 2).join(path.sep);
}
function asyncForEach(array, callback) {
Expand Down Expand Up @@ -1944,9 +1940,12 @@ function filterDiff(diffText) {
// Split the diff text into sections based on the headers
const sections = diffText.split(/(?=^===== )/m);
const filteredSection = sections.map(section => {
var removedLabels = section.replace(/<\s+argocd\.argoproj\.io\/instance:.*\n---\n>\s+argocd\.argoproj\.io\/instance:.*\n?/g, '').trim();
var removedLabels = removedLabels.replace(/<\s+app.kubernetes.io\/part-of:.*\n?/g, '').trim();
return removedLabels;
let labels = ['argocd.argoproj.io/instance', 'app.kubernetes.io/part-of'];
for (let label of labels) {
let regex = new RegExp(`<\\s+${label}:.*(?:\\n---\\n>\\s+${label}:.*)?\\n?`, 'g');
section = section.replace(regex, '').trim();
}
return section;
}).filter(section => section.trim() !== '');
const removeEmptyHeaders = filteredSection.filter(entry => {
// Remove empty strings and sections that are just headers with line numbers
Expand Down
16 changes: 6 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,11 @@ function partOfApp(changedFiles: string[], app: App): boolean {
}

function getFirstTwoDirectories(filePath: string): string {
// Normalize the path to handle any inconsistencies
const normalizedPath = path.normalize(filePath);

// Split the path into parts based on the OS-specific separator
const parts = normalizedPath.split(path.sep).filter(Boolean); // filter(Boolean) removes empty strings

// Check if the path has at least two segments
if (parts.length < 2) {
return parts.join(path.sep); // Return the entire path if less than two directories
}

// Join the first two segments
return parts.slice(0, 2).join(path.sep);
}

Expand Down Expand Up @@ -319,9 +312,12 @@ function filterDiff(diffText: string) {
const sections = diffText.split(/(?=^===== )/m);

const filteredSection = sections.map(section => {
var removedLabels = section.replace(/<\s+argocd\.argoproj\.io\/instance:.*\n---\n>\s+argocd\.argoproj\.io\/instance:.*\n?/g, '').trim();
var removedLabels = removedLabels.replace(/<\s+app.kubernetes.io\/part-of:.*\n?/g, '').trim();
return removedLabels;
let labels = ['argocd.argoproj.io/instance', 'app.kubernetes.io/part-of'];
for (let label of labels) {
let regex = new RegExp(`<\\s+${label}:.*(?:\\n---\\n>\\s+${label}:.*)?\\n?`, 'g');
section = section.replace(regex, '').trim();
}
return section;
}).filter(section => section.trim() !== '');

const removeEmptyHeaders = filteredSection.filter(entry => {
Expand Down

0 comments on commit 2ef3b98

Please sign in to comment.