Skip to content

Commit 158fdbf

Browse files
authored
Merge pull request #1 from vibe-ideas/feat/chaosblade-plugin
feat: Implement vfox chaosblade plugin
2 parents 12e9c9d + 2b091ac commit 158fdbf

11 files changed

Lines changed: 133 additions & 156 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
issues: write
17+
actions: read
18+
19+
jobs:
20+
claude:
21+
if: |
22+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
23+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
24+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
25+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
pull-requests: read
30+
issues: read
31+
id-token: write
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 1
37+
- name: Run Claude Code
38+
id: claude
39+
uses: anthropics/claude-code-action@main
40+
env:
41+
ANTHROPIC_BASE_URL: "${{ secrets.ANTHROPIC_BASE_URL }}"
42+
with:
43+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

Injection.lua

Lines changed: 0 additions & 17 deletions
This file was deleted.

hooks/available.lua

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,5 @@ local util = require("util")
44
--- @param ctx table Empty table used as context, for future extension
55
--- @return table Descriptions of available versions and accompanying tool descriptions
66
function PLUGIN:Available(ctx)
7-
util:DoSomeThing()
8-
return {
9-
{
10-
version = "xxxx",
11-
note = "LTS",
12-
addition = {
13-
{
14-
name = "npm",
15-
version = "8.8.8",
16-
}
17-
}
18-
}
19-
}
20-
end
7+
return util:Available()
8+
end

hooks/env_keys.lua

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1-
--- Each SDK may have different environment variable configurations.
2-
--- This allows plugins to define custom environment variables (including PATH settings)
3-
--- Note: Be sure to distinguish between environment variable settings for different platforms!
4-
--- @param ctx table Context information
5-
--- @field ctx.path string SDK installation directory
1+
--- Returns some environment variables that need to be set.
2+
--- @param ctx table
3+
--- @field ctx.version string The version of the tool currently in use
4+
--- @field ctx.rootPath string The root path of the tool currently in use
5+
--- @return table Environment variables to be set
66
function PLUGIN:EnvKeys(ctx)
7-
--- this variable is same as ctx.sdkInfo['plugin-name'].path
8-
local mainPath = ctx.path
9-
local mainSdkInfo = ctx.main
10-
local mpath = mainSdkInfo.path
11-
local mversion = mainSdkInfo.version
12-
local mname = mainSdkInfo.name
13-
local sdkInfo = ctx.sdkInfo['sdk-name']
14-
local path = sdkInfo.path
15-
local version = sdkInfo.version
16-
local name = sdkInfo.name
177
return {
188
{
19-
key = "JAVA_HOME",
20-
value = mainPath
9+
key = "CHAOSBLADE_HOME",
10+
value = ctx.rootPath
2111
},
2212
{
2313
key = "PATH",
24-
value = mainPath .. "/bin"
25-
},
26-
{
27-
key = "PATH",
28-
value = mainPath .. "/bin2"
29-
},
30-
14+
value = ctx.rootPath .. "/bin"
15+
}
3116
}
32-
33-
end
17+
end

hooks/parse_legacy_file.lua

Lines changed: 0 additions & 12 deletions
This file was deleted.

hooks/post_install.lua

Lines changed: 0 additions & 12 deletions
This file was deleted.

hooks/pre_install.lua

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,19 @@
1+
local util = require("util")
2+
13
--- Returns some pre-installed information, such as version number, download address, local files, etc.
24
--- If checksum is provided, vfox will automatically check it for you.
35
--- @param ctx table
46
--- @field ctx.version string User-input version
57
--- @return table Version information
68
function PLUGIN:PreInstall(ctx)
79
local version = ctx.version
10+
local info, err = util:GetDownloadInfo(version)
11+
if err then
12+
error(err)
13+
end
814
return {
9-
--- Version number
10-
version = "xxx",
11-
--- remote URL or local file path [optional]
12-
url = "xxx",
13-
--- SHA256 checksum [optional]
14-
sha256 = "xxx",
15-
--- md5 checksum [optional]
16-
md5 = "xxx",
17-
--- sha1 checksum [optional]
18-
sha1 = "xxx",
19-
--- sha512 checksum [optional]
20-
sha512 = "xx",
21-
--- additional need files [optional]
22-
addition = {
23-
{
24-
--- additional file name !
25-
name = "xxx",
26-
--- remote URL or local file path [optional]
27-
url = "xxx",
28-
--- SHA256 checksum [optional]
29-
sha256 = "xxx",
30-
--- md5 checksum [optional]
31-
md5 = "xxx",
32-
--- sha1 checksum [optional]
33-
sha1 = "xxx",
34-
--- sha512 checksum [optional]
35-
sha512 = "xx",
36-
}
37-
}
15+
version = version,
16+
url = info.url,
17+
sha256 = info.sha256
3818
}
39-
end
19+
end

hooks/pre_uninstall.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

hooks/pre_use.lua

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/util.lua

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,65 @@
1-
1+
local http = require("http")
2+
local json = require("json")
3+
local os = require("os")
24
local util = {}
35

4-
function util:DoSomeThing()
5-
print("Do some thing")
6+
local GITHUB_API_URL = "https://api.github.com/repos/chaosblade-io/chaosblade/releases"
7+
8+
function util:Available()
9+
local code, body = http.get(GITHUB_API_URL)
10+
if code ~= 200 then
11+
return nil, "Failed to fetch releases from GitHub API."
12+
end
13+
local releases = json.decode(body)
14+
local versions = {}
15+
for _, release in ipairs(releases) do
16+
table.insert(versions, {
17+
version = release.tag_name,
18+
note = release.prerelease and "prerelease" or ""
19+
})
20+
end
21+
return versions
22+
end
23+
24+
function util:GetDownloadInfo(version)
25+
local arch = os.arch()
26+
if arch == "x86_64" then
27+
arch = "amd64"
28+
end
29+
local os_type = os.type()
30+
if os_type == "Darwin" then
31+
os_type = "darwin"
32+
elseif os_type == "Linux" then
33+
os_type = "linux"
34+
else
35+
return nil, "Unsupported OS type: " .. os_type
36+
end
37+
38+
local file_name = string.format("chaosblade-%s-%s-%s.tar.gz", version, os_type, arch)
39+
local url = string.format("https://github.com/chaosblade-io/chaosblade/releases/download/%s/%s", version, file_name)
40+
41+
local checksum_url = string.format("https://github.com/chaosblade-io/chaosblade/releases/download/%s/checksum.txt", version)
42+
local code, body = http.get(checksum_url)
43+
if code ~= 200 then
44+
return nil, "Failed to fetch checksum file."
45+
end
46+
47+
local checksum = ""
48+
for line in string.gmatch(body, "[^\r\n]+") do
49+
local sha, name = line:match("([a-f0-9]+)%s+(.+)")
50+
if name == file_name then
51+
checksum = sha
52+
break
53+
end
54+
end
55+
if checksum == "" then
56+
return nil, "Failed to find checksum for " .. file_name
57+
end
58+
59+
return {
60+
url = url,
61+
sha256 = checksum
62+
}
663
end
764

8-
return util
65+
return util

0 commit comments

Comments
 (0)