Skip to content

Commit 5f1c0db

Browse files
committed
feat(init): 项目初始化,支持GitLens Patch多版本处理
- 初始化项目结构 - 实现V15、V16、V17等版本的JS补丁处理逻辑 - 支持多平台扩展目录检测(含cursor、cursor-server、remote-ssh等) - 集成Makefile、CI/CD、单元测试、lint等开发工具链
0 parents  commit 5f1c0db

30 files changed

+1959
-0
lines changed

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
env:
8+
GO_VERSION: '1.24.3'
9+
GOLANGCI_LINT_VERSION: 'v2.2.2'
10+
11+
jobs:
12+
build-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: ${{ env.GO_VERSION }}
22+
23+
- name: Install dependencies
24+
run: |
25+
go mod tidy
26+
go get github.com/stretchr/testify
27+
28+
- name: Install golangci-lint
29+
run: |
30+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }}
31+
32+
- name: Lint
33+
run: make lint
34+
35+
- name: Code format
36+
run: |
37+
if [ -f style.sh ]; then bash style.sh; fi
38+
39+
- name: Build (local)
40+
run: make build-local
41+
42+
- name: Test
43+
run: make test
44+
45+
- name: Build binaries
46+
if: startsWith(github.ref, 'refs/tags/v')
47+
run: make build-binaries
48+
49+
- name: Package binaries
50+
if: startsWith(github.ref, 'refs/tags/v')
51+
run: make package-binaries
52+
53+
- name: Upload Binaries
54+
if: startsWith(github.ref, 'refs/tags/v')
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: binaries
58+
path: |
59+
dist/*.tar.gz
60+
dist/*.zip
61+
62+
release:
63+
name: Create GitHub Release
64+
if: startsWith(github.ref, 'refs/tags/v')
65+
needs: build-test
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Download Binaries
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: binaries
73+
74+
- name: List Downloaded Files
75+
run: ls -l
76+
77+
- name: Create Release
78+
uses: ncipollo/release-action@v1
79+
with:
80+
artifacts: "*.tar.gz,*.zip"
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
tag: ${{ github.ref_name }}
83+
name: Release ${{ github.ref_name }}
84+
prerelease: false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
dist/

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# 项目变量
2+
IMAGE_NAME = gitlens-patch
3+
DIST_DIR = dist
4+
PLATFORMS = linux/amd64 linux/arm64 windows/amd64 windows/arm64
5+
GIT_TAG=$(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
6+
TAG ?= $(GIT_TAG)
7+
.PHONY: test test-all build-local build-binaries package-binaries clean lint code-format
8+
9+
# 单元测试
10+
test:
11+
go test ./...
12+
13+
test-all:
14+
for platform in $(PLATFORMS); do \
15+
GOOS=$$(echo $$platform | cut -d/ -f1); \
16+
GOARCH=$$(echo $$platform | cut -d/ -f2); \
17+
echo "Testing for $$platform"; \
18+
GOOS=$$GOOS GOARCH=$$GOARCH go test ./... || exit 1; \
19+
done
20+
21+
# 本地构建
22+
build-local:
23+
@echo "Building binary for local environment"
24+
mkdir -p $(DIST_DIR)
25+
go build -o $(DIST_DIR)/$(IMAGE_NAME) .
26+
27+
# 多平台构建
28+
build-binaries:
29+
@echo "Building binaries for platforms: $(PLATFORMS)"
30+
@mkdir -p $(DIST_DIR)
31+
for platform in $(PLATFORMS); do \
32+
GOOS=$$(echo $$platform | cut -d/ -f1); \
33+
GOARCH=$$(echo $$platform | cut -d/ -f2); \
34+
OUTPUT=$(DIST_DIR)/$(IMAGE_NAME)-$$GOOS-$$GOARCH; \
35+
if [ "$$GOOS" = "windows" ]; then OUTPUT=$$OUTPUT.exe; fi; \
36+
echo "Building for $$platform -> $$OUTPUT"; \
37+
GOOS=$$GOOS GOARCH=$$GOARCH CGO_ENABLED=0 go build -o $$OUTPUT . || exit 1; \
38+
done
39+
40+
# 打包产物
41+
package-binaries:
42+
@echo "Packaging binaries into tar.gz/zip archives"
43+
@mkdir -p $(DIST_DIR)
44+
@for file in $(DIST_DIR)/$(IMAGE_NAME)-*; do \
45+
case "$$file" in \
46+
*.exe) \
47+
zip -j $(DIST_DIR)/$$(basename $$file)-$(TAG).zip $$file ;; \
48+
*) \
49+
tar -czvf $(DIST_DIR)/$$(basename $$file)-$(TAG).tar.gz -C $(DIST_DIR) $$(basename $$file) ;; \
50+
esac; \
51+
done
52+
53+
54+
# Lint 检查
55+
.PHONY: lint
56+
57+
lint:
58+
@echo "Running golangci-lint..."
59+
@golangci-lint run ./...
60+
61+
# 代码格式化
62+
code-format:
63+
@echo "Running code format..."
64+
@find . -name "*.go" -type f -exec gofmt -w {} \;
65+
66+
# 清理构建产物
67+
clean:
68+
rm -rf $(DIST_DIR)

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# GitLens Patch
2+
3+
一个用于激活 GitLens Pro 功能的工具。
4+
5+
## 功能特性
6+
7+
- 支持 GitLens 15、16、17 版本
8+
- 自动检测 GitLens 安装路径
9+
- 支持多种编辑器(VSCode、Cursor、VSCode Insiders、Windsurf)
10+
- 自动备份原文件
11+
12+
## 目录结构
13+
14+
```
15+
gitlens-patch/
16+
├── main.go # 主程序入口
17+
├── internal/
18+
│ ├── app/
19+
│ │ └── app.go # 主应用逻辑
20+
│ ├── config/
21+
│ │ ├── constants.go # 常量配置
22+
│ │ └── paths.go # 路径配置
23+
│ ├── processor/
24+
│ │ ├── processor.go # 处理器接口
25+
│ │ ├── factory.go # 处理器工厂
26+
│ │ ├── v15.go # v15版本处理器
27+
│ │ └── v16plus.go # v16+版本处理器
28+
│ └── utils/
29+
│ ├── file.go # 文件操作工具
30+
│ ├── input.go # 用户输入工具
31+
│ └── path.go # 路径处理工具
32+
├── go.mod # Go模块文件
33+
└── README.md # 项目说明
34+
```
35+
36+
## 使用方法
37+
38+
### 编译
39+
40+
```bash
41+
go build -o gitlens-patch cmd/main.go
42+
```
43+
44+
### 运行
45+
46+
```bash
47+
# 激活 GitLens Pro
48+
./gitlens-patch
49+
50+
51+
# 指定扩展目录
52+
./gitlens-patch --ext-dir /path/to/extensions
53+
54+
# 也可以./gitlens-patch根据提示选择编号手动指定路径
55+
```
56+
57+
### 环境变量
58+
59+
- `VSCODE_EXTENSIONS_DIR`: 指定 VSCode 扩展目录
60+
61+
## 版本支持
62+
63+
- ✅ GitLens 15.x
64+
- ✅ GitLens 16.x
65+
- ✅ GitLens 17.x
66+
- ❌ 其他版本(会提示不支持)
67+
68+
## 注意事项
69+
70+
1. 使用前请确保已安装 GitLens 扩展
71+
2. 程序会自动备份原文件(.backup 后缀)
72+
3. 修改后需要重启编辑器才能生效
73+
4. 仅支持指定的版本,其他版本会提示不支持
74+

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/sunerpy/gitlens-patch
2+
3+
go 1.24.3
4+
5+
require github.com/stretchr/testify v1.10.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)