Skip to content

Commit aef558c

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

30 files changed

+1957
-0
lines changed

.github/workflows/ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
release:
46+
if: startsWith(github.ref, 'refs/tags/v')
47+
needs: build-test
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Set up Go
54+
uses: actions/setup-go@v5
55+
with:
56+
go-version: ${{ env.GO_VERSION }}
57+
58+
- name: Install dependencies
59+
run: |
60+
go mod tidy
61+
go get github.com/stretchr/testify
62+
63+
- name: Install golangci-lint
64+
run: |
65+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }}
66+
67+
- name: Lint
68+
run: make lint
69+
70+
- name: Code format
71+
run: |
72+
if [ -f style.sh ]; then bash style.sh; fi
73+
74+
- name: Build binaries (multi-platform)
75+
run: make build-binaries
76+
77+
- name: Package binaries
78+
run: make package-binaries
79+
80+
- name: Upload Release Assets
81+
uses: softprops/action-gh-release@v2
82+
with:
83+
files: dist/*
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 项目变量
2+
IMAGE_NAME = gitlens-patch
3+
DIST_DIR = dist
4+
PLATFORMS = linux/amd64 linux/arm64 windows/amd64 windows/arm64
5+
TAG ?= dev
6+
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+
for platform in $(PLATFORMS); do \
31+
GOOS=$$(echo $$platform | cut -d/ -f1); \
32+
GOARCH=$$(echo $$platform | cut -d/ -f2); \
33+
OUTPUT=$(DIST_DIR)/$(IMAGE_NAME)-$$GOOS-$$GOARCH; \
34+
if [ "$$GOOS" = "windows" ]; then OUTPUT=$$OUTPUT.exe; fi; \
35+
echo "Building for $$platform -> $$OUTPUT"; \
36+
GOOS=$$GOOS GOARCH=$$GOARCH CGO_ENABLED=0 go build -o $$OUTPUT . || exit 1; \
37+
done
38+
39+
# 打包产物
40+
package-binaries:
41+
@echo "Packaging binaries into tar.gz/zip archives"
42+
for file in $(DIST_DIR)/$(IMAGE_NAME)-*; do \
43+
if [[ $$file == *.exe ]]; then \
44+
zip -j $(DIST_DIR)/$$(basename $$file)-$(TAG).zip $$file; \
45+
else \
46+
tar -czvf $(DIST_DIR)/$$(basename $$file)-$(TAG).tar.gz -C $(DIST_DIR) $$(basename $$file); \
47+
fi; \
48+
done
49+
50+
# Lint 检查
51+
.PHONY: lint
52+
53+
lint:
54+
@echo "Running golangci-lint..."
55+
@golangci-lint run ./...
56+
57+
# 代码格式化
58+
code-format:
59+
@echo "Running code format..."
60+
@find . -name "*.go" -type f -exec gofmt -w {} \;
61+
62+
# 清理构建产物
63+
clean:
64+
rm -rf $(DIST_DIR)

README.md

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

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)