Skip to content

Commit e1d6277

Browse files
working locally for demo
1 parent 3a348cc commit e1d6277

File tree

10 files changed

+103
-182
lines changed

10 files changed

+103
-182
lines changed

.codacy/codacy.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
runtimes:
2-
3-
4-
5-
62
73
tools:
8-
9-
10-
114
- license-sim@local

.codacy/codacy2.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtimes:
2+
3+
4+
5+
6+
tools:
7+
8+
9+
10+
- license-sim@local

cmd/analyze.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func runTool(workDirectory string, toolName string, pathsToCheck []string, outpu
432432

433433
var runtime *plugins.RuntimeInfo
434434

435-
if toolName == "codacy-enigma-cli" {
435+
if toolName == "license-sim" {
436436
isToolInstalled = true
437437
}
438438

@@ -506,7 +506,7 @@ Supports API token, provider, and repository flags to automatically fetch tool c
506506
log.Fatalf("Failed to get current working directory: %v", err)
507507
}
508508

509-
cliLocalMode := len(initFlags.ApiToken) == 0
509+
cliLocalMode := true
510510

511511
var toolsToRun map[string]*plugins.ToolInfo
512512

cmd/config.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,33 +199,33 @@ var configDiscoverCmd = &cobra.Command{
199199
log.Fatalf("Error updating .codacy/tools-configs/languages-config.yaml: %v", err)
200200
}
201201
fmt.Println("Updated .codacy/tools-configs/languages-config.yaml")
202-
203-
// For updating codacy.yaml, we need to know the current CLI mode and potentially API creds
204-
currentCliMode, err := config.Config.GetCliMode()
205-
if err != nil {
206-
log.Printf("Warning: Could not determine CLI mode: %v. Assuming local mode for tool enablement.", err)
207-
currentCliMode = "local" // Default to local
208-
}
209-
210-
codacyYAMLPath := config.Config.ProjectConfigFile()
211-
212-
if err := updateCodacyYAMLForTools(detectedTools, codacyYAMLPath, configResetInitFlags, currentCliMode); err != nil {
213-
if strings.Contains(err.Error(), "❌ Fatal:") {
214-
fmt.Println(err)
215-
os.Exit(1)
202+
/*
203+
// For updating codacy.yaml, we need to know the current CLI mode and potentially API creds
204+
currentCliMode, err := config.Config.GetCliMode()
205+
if err != nil {
206+
log.Printf("Warning: Could not determine CLI mode: %v. Assuming local mode for tool enablement.", err)
207+
currentCliMode = "local" // Default to local
216208
}
217-
log.Fatalf("Error updating %s: %v", codacyYAMLPath, err)
218-
}
219-
fmt.Printf("Updated %s with relevant tools.\n", filepath.Base(codacyYAMLPath))
220209
221-
// Create tool configuration files for discovered tools
222-
if len(detectedTools) > 0 {
223-
fmt.Printf("\nCreating tool configurations for discovered tools...\n")
224-
if err := configsetup.CreateConfigurationFilesForDiscoveredTools(detectedTools, toolsConfigDir, configResetInitFlags); err != nil {
225-
log.Printf("Warning: Failed to create some tool configurations: %v", err)
226-
}
227-
}
210+
codacyYAMLPath := config.Config.ProjectConfigFile()
211+
212+
if err := updateCodacyYAMLForTools(detectedTools, codacyYAMLPath, configResetInitFlags, currentCliMode); err != nil {
213+
if strings.Contains(err.Error(), "❌ Fatal:") {
214+
fmt.Println(err)
215+
os.Exit(1)
216+
}
217+
log.Fatalf("Error updating %s: %v", codacyYAMLPath, err)
218+
}
219+
fmt.Printf("Updated %s with relevant tools.\n", filepath.Base(codacyYAMLPath))
228220
221+
// Create tool configuration files for discovered tools
222+
if len(detectedTools) > 0 {
223+
fmt.Printf("\nCreating tool configurations for discovered tools...\n")
224+
if err := configsetup.CreateConfigurationFilesForDiscoveredTools(detectedTools, toolsConfigDir, configResetInitFlags); err != nil {
225+
log.Printf("Warning: Failed to create some tool configurations: %v", err)
226+
}
227+
}
228+
*/
229229
fmt.Println("\n✅ Successfully discovered languages and updated configurations.")
230230
fmt.Println(" Please review the changes in '.codacy/codacy.yaml' and '.codacy/tools-configs/' directory.")
231231
},
@@ -275,7 +275,7 @@ func updateLanguagesConfigForTools(detectedTools map[string]struct{}, toolsConfi
275275

276276
// updateCodacyYAMLForTools updates the codacy.yaml file with detected tools.
277277
func updateCodacyYAMLForTools(detectedTools map[string]struct{}, codacyYAMLPath string, initFlags domain.InitFlags, cliMode string) error {
278-
278+
codacyYAMLPath = "/Users/luia.ventura/Work/Repos/gh/codacy-cli-v2/.codacy/codacy2.yaml"
279279
var configData map[string]interface{}
280280

281281
// Read and parse codacy.yaml (validation is done globally in PersistentPreRun)

cmd/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"codacy/cli-v2/config"
109
"codacy/cli-v2/utils/logger"
1110

1211
"github.com/sirupsen/logrus"
@@ -16,7 +15,8 @@ import (
1615
// validateCodacyYAML validates that codacy.yaml exists and is not empty
1716
// Returns an error if validation fails, nil if validation passes
1817
func validateCodacyYAML() error {
19-
codacyYAMLPath := config.Config.ProjectConfigFile()
18+
//codacyYAMLPath := config.Config.ProjectConfigFile()
19+
codacyYAMLPath := "/Users/luia.ventura/Work/Repos/gh/codacy-cli-v2/.codacy/codacy2.yaml"
2020

2121
// Check if file exists
2222
if _, err := os.Stat(codacyYAMLPath); os.IsNotExist(err) {

codacy-cli-v2

21.3 MB
Binary file not shown.

codacy-cli.sh

Lines changed: 6 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,13 @@
11
#!/usr/bin/env bash
22

3-
43
set -e +o pipefail
54

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"
5+
# Use the locally built codacy-cli-v2 binary
6+
CODACY_CLI_V2_BIN="/Users/luia.ventura/Work/Repos/gh/codacy-cli-v2/codacy-cli-v2"
1397

140-
run_command="$bin_path"
141-
if [ -z "$run_command" ]; then
142-
fatal "Codacy cli v2 binary could not be found."
8+
if [ ! -x "$CODACY_CLI_V2_BIN" ]; then
9+
echo "Error: codacy-cli-v2 binary not found at $CODACY_CLI_V2_BIN. Please build it first."
10+
exit 1
14311
fi
14412

145-
if [ "$#" -eq 1 ] && [ "$1" = "download" ]; then
146-
echo "Codacy cli v2 download succeeded"
147-
else
148-
eval "$run_command $*"
149-
fi
13+
exec "$CODACY_CLI_V2_BIN" "$@"

plugins/tools/license-sim/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ environment:
66
KMP_DUPLICATE_LIB_OK: "TRUE"
77
binaries:
88
- name: duncan
9-
path: "/Users/kendrickcurtis/Documents/GitHub/license-sim/venv/bin/python /Users/kendrickcurtis/Documents/GitHub/license-sim/duncan.py"
9+
path: "/Users/luia.ventura/Work/Repos/gh/license-sim/.venv/bin/python /Users/luia.ventura/Work/Repos/gh/license-sim/duncan.py"

tools/licenseSimRunner.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tools
33
import (
44
"codacy/cli-v2/utils"
55
"fmt"
6+
"log"
67
"os"
78
"os/exec"
89
"path/filepath"
@@ -30,12 +31,13 @@ func RunLicenseSim(workDirectory string, binary string, files []string, outputFi
3031
}
3132

3233
parts := strings.Split(binary, " ")
33-
cmdArgs := append(parts[1:], "search", "-f", fileToCheck, "-e", ext)
34+
cmdArgs := append(parts[1:], "--json", "search", "-f", fileToCheck, "-e", ext)
3435

3536
// Always add --json for machine-readable output
36-
cmdArgs = append(cmdArgs, "--json")
37+
// cmdArgs = append(cmdArgs, "--json")
3738

3839
if outputFormat == "sarif" {
40+
log.Printf("Running license-sim in SARIF mode")
3941
tempFile, err := os.CreateTemp("", "license-sim-*.json")
4042
if err != nil {
4143
return fmt.Errorf("failed to create temporary file: %w", err)
@@ -77,6 +79,7 @@ func RunLicenseSim(workDirectory string, binary string, files []string, outputFi
7779
return nil
7880
}
7981

82+
log.Printf("Running license-sim in non-SARIF mode")
8083
// Non-SARIF output
8184
cmd := exec.Command(parts[0], cmdArgs...)
8285
cmd.Dir = workDirectory
@@ -96,7 +99,7 @@ func RunLicenseSim(workDirectory string, binary string, files []string, outputFi
9699
}
97100

98101
if err := cmd.Run(); err != nil {
99-
return fmt.Errorf("failed to run license-sim: %w", err)
102+
return fmt.Errorf("failed to run license-sim: command: %s, error: %w", cmd.String(), err)
100103
}
101104
return nil
102105
}

wordpress-insert-post-test.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Insert a new blog post into the database.
4+
*
5+
* @global wpdb $wpdb WordPress database abstraction object.
6+
*
7+
* @param string $post_title The post title.
8+
* @param string $post_content The post content.
9+
* @param int $post_author The user ID of the author.
10+
* @param string $post_status The post status (default: 'publish').
11+
* @return int|false The inserted post ID on success, false on failure.
12+
*/
13+
function wp_insert_blog_post( $post_title, $post_content, $post_author, $post_status = 'publish' ) {
14+
global $wpdb;
15+
16+
// Prepare post data array.
17+
$post_data = array(
18+
'post_author' => $post_author,
19+
'post_title' => $post_title,
20+
'post_content' => $post_content,
21+
'post_status' => $post_status,
22+
'post_type' => 'post',
23+
'post_date' => current_time( 'mysql' ),
24+
'post_date_gmt' => current_time( 'mysql', 1 ),
25+
);
26+
27+
// Insert the post into the database.
28+
$inserted = $wpdb->insert(
29+
$wpdb->posts,
30+
$post_data
31+
);
32+
33+
if ( $inserted ) {
34+
return $wpdb->insert_id;
35+
}
36+
37+
return false;
38+
}
39+
40+
// Example usage (for testing):
41+
// This will only work in a WordPress environment.
42+
if ( function_exists( 'current_time' ) && isset( $GLOBALS['wpdb'] ) ) {
43+
$post_id = wp_insert_blog_post( 'Test Post', 'This is the content of the test post.', 1 );
44+
if ( $post_id ) {
45+
echo 'Inserted post with ID: ' . $post_id . "\n";
46+
} else {
47+
echo "Failed to insert post.\n";
48+
}
49+
} else {
50+
echo "This script must be run within a WordPress environment.\n";
51+
}

0 commit comments

Comments
 (0)