Skip to content

Commit c106f11

Browse files
authored
feat: update version to 1.23.1 and enhance changelog with security fixes and log regex improvements (#21)
1 parent fea292c commit c106f11

File tree

9 files changed

+194
-42
lines changed

9 files changed

+194
-42
lines changed

.codacy/cli.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env bash
2+
3+
4+
set -e +o pipefail
5+
6+
# Set up paths first
7+
bin_name="codacy-cli-v2"
8+
9+
# Determine OS-specific paths
10+
os_name=$(uname)
11+
arch=$(uname -m)
12+
13+
case "$arch" in
14+
"x86_64")
15+
arch="amd64"
16+
;;
17+
"x86")
18+
arch="386"
19+
;;
20+
"aarch64"|"arm64")
21+
arch="arm64"
22+
;;
23+
esac
24+
25+
if [ -z "$CODACY_CLI_V2_TMP_FOLDER" ]; then
26+
if [ "$(uname)" = "Linux" ]; then
27+
CODACY_CLI_V2_TMP_FOLDER="$HOME/.cache/codacy/codacy-cli-v2"
28+
elif [ "$(uname)" = "Darwin" ]; then
29+
CODACY_CLI_V2_TMP_FOLDER="$HOME/Library/Caches/Codacy/codacy-cli-v2"
30+
else
31+
CODACY_CLI_V2_TMP_FOLDER=".codacy-cli-v2"
32+
fi
33+
fi
34+
35+
version_file="$CODACY_CLI_V2_TMP_FOLDER/version.yaml"
36+
37+
38+
get_version_from_yaml() {
39+
if [ -f "$version_file" ]; then
40+
local version=$(grep -o 'version: *"[^"]*"' "$version_file" | cut -d'"' -f2)
41+
if [ -n "$version" ]; then
42+
echo "$version"
43+
return 0
44+
fi
45+
fi
46+
return 1
47+
}
48+
49+
get_latest_version() {
50+
local response
51+
if [ -n "$GH_TOKEN" ]; then
52+
response=$(curl -Lq --header "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/codacy/codacy-cli-v2/releases/latest" 2>/dev/null)
53+
else
54+
response=$(curl -Lq "https://api.github.com/repos/codacy/codacy-cli-v2/releases/latest" 2>/dev/null)
55+
fi
56+
57+
handle_rate_limit "$response"
58+
local version=$(echo "$response" | grep -m 1 tag_name | cut -d'"' -f4)
59+
echo "$version"
60+
}
61+
62+
handle_rate_limit() {
63+
local response="$1"
64+
if echo "$response" | grep -q "API rate limit exceeded"; then
65+
fatal "Error: GitHub API rate limit exceeded. Please try again later"
66+
fi
67+
}
68+
69+
download_file() {
70+
local url="$1"
71+
72+
echo "Downloading from URL: ${url}"
73+
if command -v curl > /dev/null 2>&1; then
74+
curl -# -LS "$url" -O
75+
elif command -v wget > /dev/null 2>&1; then
76+
wget "$url"
77+
else
78+
fatal "Error: Could not find curl or wget, please install one."
79+
fi
80+
}
81+
82+
download() {
83+
local url="$1"
84+
local output_folder="$2"
85+
86+
( cd "$output_folder" && download_file "$url" )
87+
}
88+
89+
download_cli() {
90+
# OS name lower case
91+
suffix=$(echo "$os_name" | tr '[:upper:]' '[:lower:]')
92+
93+
local bin_folder="$1"
94+
local bin_path="$2"
95+
local version="$3"
96+
97+
if [ ! -f "$bin_path" ]; then
98+
echo "📥 Downloading CLI version $version..."
99+
100+
remote_file="codacy-cli-v2_${version}_${suffix}_${arch}.tar.gz"
101+
url="https://github.com/codacy/codacy-cli-v2/releases/download/${version}/${remote_file}"
102+
103+
download "$url" "$bin_folder"
104+
tar xzfv "${bin_folder}/${remote_file}" -C "${bin_folder}"
105+
fi
106+
}
107+
108+
# Warn if CODACY_CLI_V2_VERSION is set and update is requested
109+
if [ -n "$CODACY_CLI_V2_VERSION" ] && [ "$1" = "update" ]; then
110+
echo "⚠️ Warning: Performing update with forced version $CODACY_CLI_V2_VERSION"
111+
echo " Unset CODACY_CLI_V2_VERSION to use the latest version"
112+
fi
113+
114+
# Ensure version.yaml exists and is up to date
115+
if [ ! -f "$version_file" ] || [ "$1" = "update" ]; then
116+
echo "ℹ️ Fetching latest version..."
117+
version=$(get_latest_version)
118+
mkdir -p "$CODACY_CLI_V2_TMP_FOLDER"
119+
echo "version: \"$version\"" > "$version_file"
120+
fi
121+
122+
# Set the version to use
123+
if [ -n "$CODACY_CLI_V2_VERSION" ]; then
124+
version="$CODACY_CLI_V2_VERSION"
125+
else
126+
version=$(get_version_from_yaml)
127+
fi
128+
129+
130+
# Set up version-specific paths
131+
bin_folder="${CODACY_CLI_V2_TMP_FOLDER}/${version}"
132+
133+
mkdir -p "$bin_folder"
134+
bin_path="$bin_folder"/"$bin_name"
135+
136+
# Download the tool if not already installed
137+
download_cli "$bin_folder" "$bin_path" "$version"
138+
chmod +x "$bin_path"
139+
140+
run_command="$bin_path"
141+
if [ -z "$run_command" ]; then
142+
fatal "Codacy cli v2 binary could not be found."
143+
fi
144+
145+
if [ "$#" -eq 1 ] && [ "$1" = "download" ]; then
146+
echo "Codacy cli v2 download succeeded"
147+
else
148+
eval "$run_command $*"
149+
fi

.codacy/codacy.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtimes:
2+
- java@17.0.10
3+
- node@22.2.0
4+
- python@3.11.11
5+
tools:
6+
- eslint@8.57.0
7+
- lizard@1.17.31
8+
- pmd@6.55.0
9+
- semgrep@1.78.0
10+
- trivy@0.66.0

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ build/
2020
# Miscellaneous
2121
.DS_Store
2222
Thumbs.db
23+
24+
25+
#Ignore insiders AI rules
26+
.github/instructions/codacy.instructions.md

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22

33
All notable changes to the "magento-log-viewer" extension will be documented in this file.
44

5-
65
## Next release
76

7+
### [1.23.1] - 2025-12-08
8+
9+
- fix: Enhanced log level detection pattern to support both uppercase and lowercase formats (.WARN:, .warn:, .INFO:, .info: etc.)
10+
- fix: WARN entries now properly appear in `*.log` file listing and categorization
11+
- fix: Improved regex pattern matching from `\.(\w+):` to `\.([A-Za-z]+):` for more reliable log parsing
12+
- fix: Resolved issue where certain log level formats were not being recognized during file analysis
13+
- fix: Enhanced badge counting accuracy for all log level variations
14+
- fix: Null safety improvements for status bar item to prevent potential crashes
15+
- refactor: Removed unused functions and improved code
16+
- refactor: Cleaned up method signatures by removing unnecessary parameters
17+
- fix: Updated test interfaces to match current implementation
818

919
---
1020

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento-log-viewer",
33
"displayName": "Magento Log Viewer",
44
"description": "A Visual Studio Code extension to view and manage Magento log files.",
5-
"version": "1.23.0",
5+
"version": "1.23.1",
66
"publisher": "MathiasElle",
77
"icon": "resources/logo.png",
88
"repository": {

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath, deleteReportFile, clearFileContentCache, selectMagentoRootFolder, selectMagentoRootFolderDirect, getEffectiveMagentoRoot, selectMagentoRootFromSettings, autoCleanupOldLogFiles, stopPeriodicCleanup } from './helpers';
2+
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath, deleteReportFile, clearFileContentCache, selectMagentoRootFolderDirect, getEffectiveMagentoRoot, selectMagentoRootFromSettings, autoCleanupOldLogFiles, stopPeriodicCleanup } from './helpers';
33
import { LogItem, ReportViewerProvider } from './logViewer';
44
import { showUpdateNotification } from './updateNotifier';
55

src/helpers.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ export function updateBadge(treeView: vscode.TreeView<unknown>, logViewerProvide
455455
vscode.commands.executeCommand('setContext', 'magentoLogViewer.hasLogFiles', totalEntries > 0);
456456

457457
// Update status bar item
458-
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
458+
if (LogViewerProvider.statusBarItem) {
459+
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
460+
}
459461
};
460462

461463
// Debounced event handler
@@ -497,30 +499,6 @@ function countFilesInDirectory(dir: string): number {
497499
return count;
498500
}
499501

500-
function getAllReportFiles(dir: string): LogItem[] {
501-
if (!pathExists(dir)) {
502-
return [];
503-
}
504-
505-
const items: LogItem[] = [];
506-
const files = fs.readdirSync(dir);
507-
508-
files.forEach(file => {
509-
const filePath = path.join(dir, file);
510-
if (fs.lstatSync(filePath).isDirectory()) {
511-
items.push(...getAllReportFiles(filePath));
512-
} else if (fs.lstatSync(filePath).isFile()) {
513-
items.push(new LogItem(file, vscode.TreeItemCollapsibleState.None, {
514-
command: 'magento-log-viewer.openFile',
515-
title: 'Open Log File',
516-
arguments: [filePath]
517-
}));
518-
}
519-
});
520-
521-
return items;
522-
}
523-
524502
// Checks if the given path is a valid directory.
525503
export function isValidPath(filePath: string): boolean {
526504
try {

src/logViewer.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { pathExists, pathExistsAsync, getLineCount, getIconForLogLevel, getLogIt
77
export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vscode.Disposable {
88
private _onDidChangeTreeData: vscode.EventEmitter<LogItem | undefined | void> = new vscode.EventEmitter<LogItem | undefined | void>();
99
readonly onDidChangeTreeData: vscode.Event<LogItem | undefined | void> = this._onDidChangeTreeData.event;
10-
public static statusBarItem: vscode.StatusBarItem;
10+
public static statusBarItem: vscode.StatusBarItem | undefined;
1111
private groupByMessage: boolean;
1212
private disposables: vscode.Disposable[] = [];
1313
private isInitialized: boolean = false;
@@ -243,7 +243,7 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
243243
return normalizedDir === normalizedLogPath;
244244
}
245245

246-
private getLogItems(dir: string, label: string): LogItem[] {
246+
private getLogItems(dir: string): LogItem[] {
247247
if (!pathExists(dir)) {
248248
return [new LogItem(`No items found`, vscode.TreeItemCollapsibleState.None)];
249249
}
@@ -303,14 +303,13 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
303303
const groupedByType = new Map<string, { message: string, line: string, lineNumber: number }[]>();
304304

305305
console.log(`[DEBUG] Processing ${lines.length} lines for ${filePath}`);
306-
let matchCount = 0;
307306

308307
lines.forEach((line, index) => {
309-
const match = line.match(/\.(\w+):/);
308+
// Enhanced regex to match both formats: .level: and .LEVEL:
309+
const match = line.match(/\.([A-Za-z]+):/);
310310
if (match) {
311-
matchCount++;
312311
const level = match[1].toUpperCase();
313-
const message = line.replace(/^\[.*?\]\s*\.\w+:\s*/, '');
312+
const message = line.replace(/^\[.*?\]\s*\.[A-Za-z]+:\s*/, '');
314313

315314
// Apply search filter
316315
if (this.matchesSearchTerm(line) || this.matchesSearchTerm(message)) {
@@ -413,9 +412,9 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
413412
if (fileContent) {
414413
const lines = fileContent.split('\n');
415414

416-
// Only count valid log entries matching the expected pattern
415+
// Only count valid log entries matching the expected pattern (enhanced for both formats)
417416
lines.forEach(line => {
418-
if (line.match(/\.(\w+):/)) { // The pattern for log entries
417+
if (line.match(/\.([A-Za-z]+):/)) { // Updated pattern to match both .level: and .LEVEL:
419418
logEntryCount++;
420419
}
421420
});
@@ -441,7 +440,9 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
441440
const totalEntries = logFiles.reduce((count, file) => count + parseInt(file.description?.match(/\d+/)?.[0] || '0', 10), 0);
442441

443442
const searchInfo = this.searchTerm ? ` | Search: "${this.searchTerm}"` : '';
444-
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}${searchInfo}`;
443+
if (LogViewerProvider.statusBarItem) {
444+
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}${searchInfo}`;
445+
}
445446
}
446447

447448
/**
@@ -522,7 +523,7 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
522523
this._onDidChangeTreeData.dispose();
523524
if (LogViewerProvider.statusBarItem) {
524525
LogViewerProvider.statusBarItem.dispose();
525-
LogViewerProvider.statusBarItem = null as any;
526+
LogViewerProvider.statusBarItem = undefined;
526527
}
527528
// Clear regex cache to prevent memory leaks
528529
this.cachedSearchRegex = null;
@@ -678,7 +679,7 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
678679
setTimeout(() => {
679680
try {
680681
const reportPath = path.join(this.workspaceRoot, 'var', 'report');
681-
const reportItems = this.getLogItems(reportPath, 'Reports');
682+
const reportItems = this.getLogItems(reportPath);
682683
if (reportItems.length === 0) {
683684
resolve([new LogItem('No report files found', vscode.TreeItemCollapsibleState.None)]);
684685
} else {
@@ -693,7 +694,7 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
693694
}
694695
}
695696

696-
private getLogItems(dir: string, label: string): LogItem[] {
697+
private getLogItems(dir: string): LogItem[] {
697698
const allItems = getLogItems(dir, parseReportTitle, getIconForReport);
698699

699700
// Apply search filter

src/test/reportReader.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ suite('Report Reader Test Suite', () => {
5353

5454
// Interface for accessing private methods for testing
5555
interface ReportViewerInternals {
56-
getLogItems(dir: string, label: string): LogItem[];
56+
getLogItems(dir: string): LogItem[];
5757
}
5858

5959
// Access the provider's internal methods
6060
const provider = reportProvider as unknown as ReportViewerInternals;
6161

6262
// Get report items from the directory
63-
const reportItems = provider.getLogItems(tempDir, 'Reports');
63+
const reportItems = provider.getLogItems(tempDir);
6464

6565
// Basic validation that reports were found
6666
assert.ok(reportItems.length > 0, 'Should find report entries');

0 commit comments

Comments
 (0)