Skip to content

Commit

Permalink
Add GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Jan 27, 2024
1 parent 4da0cc6 commit 4f5bc9a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 35 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CodeQL"

on:
workflow_dispatch:
pull_request:

jobs:
analyze:
name: CodeQL Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
25 changes: 25 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ESLint

on:
pull_request:
push:

jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v4

- name: "🔧 setup node"
uses: actions/setup-node@v4
with:
node-version: 21
cache: "npm"

- name: "🛸 install eslint plugins"
run: npm i --omit=optional --include=dev --no-fund --progress=false

- name: "🔍 lint code"
run: npm run lint
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/src/**/*.js"
Expand Down
12 changes: 5 additions & 7 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.vscode/**
.vscode-test/**
out/test/**
test/**
src/**
**/*.map
.github/**/*.yml
.vscode/*.json
src/*.ts
out/src/*.js.map

.gitignore
tsconfig.json
vsc-extension-quickstart.md
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"version": "1.0.0",
"publisher": "tomatocake",
"license": "MIT",
"main": "./out/src/extension",
"browser": "./out/web/extension",
"extensionKind": [
"workspace"
],
"repository": {
"type": "git",
"url": "https://github.com/TomatoCake/Pterodactyl-vsc.git"
Expand All @@ -23,14 +28,14 @@
"ptero",
"file-system-provider"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "pterodactyl.init",
"title": "Connect to panel",
"category": "Pterodactyl"
},{
},
{
"command": "pterodactyl.reset",
"title": "Reset workspace config",
"category": "Pterodactyl"
Expand All @@ -41,7 +46,8 @@
{
"command": "pterodactyl.init",
"when": "workbenchState != workspace"
},{
},
{
"command": "pterodactyl.reset",
"when": "workbenchState == workspace"
}
Expand All @@ -59,13 +65,17 @@
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"lint": "eslint \"src/**/*.ts\"",
"watch": "tsc -watch -p ./"
"watch": "tsc -watch -p ./",
"ls": "vsce ls",
"pack": "vsce pack -o ./out/vsix -t web",
"publish": "vsce publish",
},
"devDependencies": {
"@types/node": "^20.11.7",
"@types/vscode": "^1.85.0",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vscode/vsce": "^2.23.0",
"eslint": "^8.56.0",
"eslint-plugin-sonarjs": "^0.23.0",
"eslint-plugin-unicorn": "^50.0.1",
Expand Down
40 changes: 19 additions & 21 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand("pterodactyl.reset", _ => {
vscode.workspace.updateWorkspaceFolders(0, vscode.workspace.workspaceFolders?.length || 0)

state.update("panelUrl", undefined)
state.update("serverId", undefined)
state.update("apiKey", undefined)
state.update("panelUrl", void 0)
state.update("serverId", void 0)
state.update("apiKey", void 0)

serverApiUrl = ""
authHeader = ""
Expand All @@ -47,53 +47,51 @@ export function activate(context: vscode.ExtensionContext) {
}))
}

// Modified by TompatoCake from https://github.com/kowd/vscode-webdav/blob/12a5f44d60ccf81430d70f3e50b04259524a403f/src/extension.ts#L147
function validatePanelURL(value: string): string | undefined {
// Modified by TomatoCake from https://github.com/kowd/vscode-webdav/blob/12a5f44d60ccf81430d70f3e50b04259524a403f/src/extension.ts#L147
const validatePanelURL = (value: string): string | undefined => {
if (value) {
try {
let uri = vscode.Uri.parse(value.trim())
if (!["http", "https"].some(s => s == uri.scheme.toLowerCase())) return `Unsupported protocol: ${uri.scheme}`
const uri = vscode.Uri.parse(value.trim())
if (uri.scheme != "http" && uri.scheme != "https") return "Unsupported protocol: " + uri.scheme
} catch {
return "Enter a valid URI"
return "Enter a valid URL"
}
} else return "Enter a valid URI"
} else return "Enter a valid URL"
}

async function addPanel() {
/*const url = await vscode.window.showInputBox({
const url = await vscode.window.showInputBox({
prompt: "Enter the Pterodactyl panel URL",
placeHolder: "Enter the main Pterodactyl panel URL here...",
placeHolder: "Enter a Pterodactyl panel URL here...",
validateInput: validatePanelURL
})
if (!url || validatePanelURL(url)) return*/
const url = "https://panel.chaoshosting.eu/server/49283264"
if (!url || validatePanelURL(url)) return

let panelUrl = vscode.Uri.parse(url.trim())
const panelUrl = vscode.Uri.parse(url.trim())

const apiKey = await vscode.window.showInputBox({
prompt: "Enter your Pterodactyl API key",
placeHolder: "Enter your Pterodactyl API key here...",
validateInput: (value: string) => value ? (value.length == 48 ? undefined : "API keys are 48 characters long") : "Enter a valid API key",
validateInput: (value: string) => value ? (value.length == 48 ? void 0 : "API keys are 48 characters long") : "Enter a valid API key",
password: true
})
if (!apiKey || apiKey.length != 48) return vscode.window.showErrorMessage("Invalid API key, must be 48 characters long")

log("Connecting to " + panelUrl.scheme + "://" + panelUrl.authority + "...")
const req = await fetch(panelUrl.scheme + "://" + panelUrl.authority + "/api/client/", {
headers: {
Accept: "application/json",
Authorization: "Bearer " + apiKey
}
})
log("Connection response: " + req.status + " " + req.statusText)
if (!req.ok) return vscode.window.showErrorMessage("Failed to connect to the Pterodactyl panel: " + req.status + " " + req.statusText)

let json: any = {}
try {
json = await req.json()
} catch (e) {
return vscode.window.showErrorMessage("Failed to connect to the Pterodactyl panel: " + e)
}
const json: any = await req.json()
log(json)
state.update("apiKey", apiKey)

log("Connected successfully, " + json.data.length + " servers found")
const serverId: any = await vscode.window.showQuickPick(json.data.map((server: any) => ({
label: server.attributes.name,
description: server.attributes.identifier,
Expand Down

0 comments on commit 4f5bc9a

Please sign in to comment.