Skip to content

zevwings/workflow.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workflow CLI

A powerful CLI tool for managing workflows, PRs, Jira tickets, and more.

项目结构

workflow.go/
├── cmd/
│   └── workflow/          # CLI 入口
│       └── main.go        # 主程序入口
├── internal/              # 核心业务逻辑层(不对外暴露)
│   ├── commands/         # Cobra 命令定义层
│   │   ├── root.go       # root 命令
│   │   ├── pr.go         # PR 命令组(所有 PR 相关命令)
│   │   ├── jira.go       # Jira 命令组
│   │   └── ...           # 其他命令组
│   ├── base/             # 基础设施模块
│   │   ├── http/         # HTTP 客户端
│   │   ├── llm/          # LLM 集成
│   │   ├── settings/     # 配置管理
│   │   ├── shell/        # Shell 检测
│   │   └── util/         # 工具函数
│   ├── git/              # Git 操作模块
│   ├── jira/             # Jira 集成模块
│   ├── pr/               # PR 管理模块(GitHub、Codeup)
│   ├── commit/           # Commit 操作模块
│   ├── completion/       # Shell 补全模块
│   ├── proxy/            # 代理管理模块
│   ├── repo/             # 仓库配置管理模块
│   ├── template/         # 模板渲染模块
│   └── rollback/         # 回滚管理模块
├── docs/                 # 文档目录
├── go.mod                # Go 模块定义
└── README.md             # 项目说明

架构设计

本项目采用适合 Go + Cobra 的分层架构:

1. CLI 入口层 (cmd/workflow/)

  • 职责:程序入口,调用命令定义层
  • 特点:薄层,只负责程序启动和错误处理

2. 命令定义层 (internal/commands/)

  • 职责:定义 Cobra 命令结构
    • 命令参数定义(Flags、Args)
    • 参数验证
    • 用户交互(输入、选择、确认)
    • 输出格式化(表格、列表、进度条)
    • 调用业务逻辑层的方法
  • 特点
    • 面向用户,处理所有交互
    • 调用业务逻辑层,不直接操作外部资源
    • 扁平结构,一个功能一个文件(如 pr.go 包含所有 PR 相关命令)

3. 业务逻辑层 (internal/)

  • 职责:实现所有业务逻辑
    • 数据模型定义和验证
    • 外部 API 调用(GitHub、Jira、LLM 等)
    • 文件系统操作
    • 配置管理
    • 工具函数和辅助功能
  • 特点
    • 可被多个命令复用
    • 不依赖 CLI 框架(Cobra)
    • 可独立测试
    • 使用 internal/ 确保不对外暴露

命令执行流程

用户输入: workflow pr create
    ↓
cmd/workflow/main.go (程序入口)
    ↓
internal/commands/root.go (创建 root 命令)
    ↓
internal/commands/pr.go (解析参数、用户交互)
    ↓
internal/pr/platform.go (业务逻辑处理)
    ↓
internal/base/http/client.go (HTTP 请求)
    ↓
外部 API (GitHub/Codeup)
    ↓
结果返回并格式化输出

开发

构建

# 使用 Makefile(推荐)
make dev      # 构建 debug 版本到 bin/workflow
make build    # 构建 release 版本到 bin/workflow
make release  # 构建优化版本到 bin/workflow

# 或直接使用 go build
go build -o bin/workflow cmd/workflow/main.go

运行

# 使用 Makefile 构建后
./bin/workflow

# 或直接运行
make dev && ./bin/workflow

添加新命令

  1. internal/commands/ 下创建命令文件(如 internal/commands/newcmd.go
  2. 定义 Cobra 命令(参考 pr.go 的实现)
  3. internal/commands/root.go 中注册命令:
    cmd.AddCommand(NewNewCmd())
  4. internal/ 下实现业务逻辑(如需要)

依赖

  • github.com/spf13/cobra - CLI 框架
  • github.com/spf13/viper - 配置管理

文档

开发指南

工具文档

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •