Metadata-Version: 2.4
Name: pygitcode
Version: 0.1.2a0
Summary: A CLI tool for GitCode (api.gitcode.com), modeled after GitHub CLI.
Author-email: codeasier <825770651@qq.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/yourusername/pygitcode
Project-URL: Documentation, https://github.com/yourusername/pygitcode#readme
Project-URL: Repository, https://github.com/yourusername/pygitcode.git
Project-URL: Issues, https://github.com/yourusername/pygitcode/issues
Keywords: gitcode,cli,git,api,vcs,developer-tools
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0
Requires-Dist: httpx>=0.24
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: pytest-mock>=3.14; extra == "dev"
Requires-Dist: respx>=0.21; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: black>=24.0; extra == "dev"
Requires-Dist: basedpyright>=1.19; extra == "dev"
Requires-Dist: pre-commit>=3.0; extra == "dev"
Dynamic: license-file

# pygitcode

> A CLI tool for [GitCode](https://gitcode.com/) (`api.gitcode.com`), modeled after GitHub CLI (`gh`).

[![PyPI](https://img.shields.io/pypi/v/pygitcode)](https://pypi.org/project/pygitcode/)
[![Python](https://img.shields.io/pypi/pyversions/pygitcode)](https://pypi.org/project/pygitcode/)
[![License](https://img.shields.io/pypi/l/pygitcode)](https://github.com/yourusername/pygitcode/blob/main/LICENSE)

## Installation

```bash
pip install pygitcode
```

This exposes the `gc` (or `gitcode`) command in your shell.

## Windows PowerShell Users

On Windows PowerShell, `gc` is a built-in alias for the `Get-Content` cmdlet, which shadows the GitCode CLI. Use `gitcode` instead:

```powershell
gitcode auth login
gitcode issue list
gitcode pr list
```

Alternatively, you can remove or override the alias in your PowerShell profile:

```powershell
# Remove for the current session
Remove-Item Alias:gc -Force

# Or persist the override in your profile
Set-Alias -Name gc -Value 'C:\Users\<user>\AppData\Roaming\Python\Python313\Scripts\gc.exe'
```

## Quick Start

### Authentication

```bash
# Login with your GitCode personal access token
gc auth login

# Check auth status
gc auth status

# Print the current auth token
gc auth token

# Logout
gc auth logout

# Or set environment variable
export GC_TOKEN=your_token_here
```

### Issues

```bash
# List issues (with filtering options)
gc issue list
gc issue list --state closed --author @me
gc issue list --label bug --label "help wanted"
gc issue list --web    # Open in browser

# View an issue (with comments)
gc issue view 42
gc issue view 42 --comments
gc issue view 42 --web

# Create an issue
gc issue create -t "Bug report" -b "Something is broken"
gc issue create --label bug --label "help wanted"   # Multiple labels
gc issue create --web    # Create in browser

# Edit an issue (add/remove labels, assignees, milestones)
gc issue edit 42 -t "Updated title"
gc issue edit 42 --add-label bug --remove-label "in progress"
gc issue edit 42 --add-assignee @me --remove-assignee otheruser
gc issue edit 42 --milestone v1.0 --remove-milestone

# Comment on an issue
gc issue comment 42 -b "Thanks for the report!"
gc issue comment 42 --editor    # Use system editor

# Close / reopen / delete
gc issue close 42
gc issue close 42 -c "Fixed in #50" --reason completed
```

### Pull Requests

```bash
# List PRs (with filtering options)
gc pr list
gc pr list --state merged --author @me
gc pr list --base main --draft
gc pr list --web    # Open in browser

# View a PR (identifier optional - infers from current branch)
gc pr view           # View PR for current branch
gc pr view 42        # By number
gc pr view 42 --comments   # Include comments
gc pr view https://gitcode.com/owner/repo/pulls/42
gc pr view feature-branch

# Create a PR (auto-detects current branch and default base)
gc pr create -t "Add new feature"

# Create with auto-fill from commits
gc pr create --fill              # Use latest commit
gc pr create --fill-first        # Use first commit
gc pr create --fill-verbose      # Use all commits for body

# Create with editor
gc pr create --editor

# Preview without creating
gc pr create --dry-run

# Create in browser
gc pr create --web

# Close / merge / reopen (identifier optional)
gc pr close          # Close PR for current branch
gc pr close 42 -c "Closing as stale"
gc pr close --delete-branch    # Delete remote branch too

gc pr merge          # Merge PR for current branch
gc pr merge 42 -s    # Squash merge
gc pr merge --rebase
gc pr merge --delete-branch    # Delete remote branch after merge

# Edit a PR (add/remove labels, assignees, reviewers, milestones)
gc pr edit 42 -t "New title"
gc pr edit --add-label bug --remove-label "needs review"
gc pr edit --add-reviewer @me --remove-reviewer otheruser
gc pr edit --milestone v1.0 --remove-milestone

# Mark as ready or convert to draft
gc pr ready          # Mark current branch's PR as ready
gc pr ready --undo   # Convert back to draft

# Comment / review / diff (identifier optional)
gc pr comment -b "LGTM"
gc pr comment --path src/file.py --position 5 -b "Suggestion"
gc pr comment --body-file comment.txt
gc pr comment --editor

gc pr review --approve
gc pr review --comment -b "Looks good but needs tests"
gc pr review --request-changes -b "Missing documentation"

gc pr diff           # View diff for current branch's PR
gc pr diff 42

# Checkout a PR (identifier optional)
gc pr checkout        # Checkout PR for current branch? (prompts if ambiguous)
gc pr checkout 42
gc pr checkout -b local-branch-name
```

### Global Options

```bash
# Use a different repo without cd-ing into it
gc issue list -R owner/repo
gc pr list -R owner/repo

# Output as JSON with field selection
gc issue list --json number,title,state,author
gc pr list --json number,title,state,head,base

# Filter with jq
gc issue list -q '.[] | select(.state == "open")'
gc pr list -q '.[] | select(.draft == true)'

# Format with Go-style templates
gc issue list -t '{{.number}} {{.title}} ({{.state}})'
gc pr view -t 'PR #{{.number}}: {{.title}}\n{{.body}}'

# Open in browser
gc issue view 42 -w
gc pr view -w
```

## Alignment with `gh` CLI

`pygitcode` aims to be as familiar as possible to `gh` users:

| Feature | `gh` | `gc` |
|---------|------|------|
| PR identifier optional (current branch inference) | ✅ | ✅ |
| `--fill` / `--fill-first` / `--fill-verbose` | ✅ | ✅ |
| `--editor` | ✅ | ✅ |
| `--dry-run` | ✅ | ✅ |
| `--web` (create/view in browser) | ✅ | ✅ |
| `--remove-*` flags for edit commands | ✅ | ✅ |
| `pr ready --undo` (convert to draft) | ✅ | ✅ |
| `pr review --comment` / `--request-changes` | ✅ | ✅ (fallback) |
| `--json fields` | ✅ | ✅ |
| `-q jq` filtering | ✅ | ✅ |
| `-t template` formatting | ✅ | ✅ |
| Command aliases (`ls` → `list`, `new` → `create`) | ✅ | ✅ |
| Multi-value options (`--label bug --label feature`) | ✅ | ✅ |

### Known Limitations (GitCode API differences)

- **PR comment model**: GitCode uses `path + position`, not GitHub's `line/side/commit`
- **PR review**: GitCode review API differs from GitHub; `--comment` and `--request-changes` fall back to PR comments
- **Issue create/update API**: GitCode puts `repo` in request body, not URL path

## Development

```bash
# Clone
git clone https://github.com/yourusername/pygitcode.git
cd pygitcode

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run all checks manually
pre-commit run --all-files

# Or run individually
python -m pytest tests/unit/ --cov=gitcode_cli
python -m ruff check src/ tests/
python -m ruff format src/ tests/
python -m basedpyright src/
```

## Roadmap

See [ROADMAP.md](ROADMAP.md) for planned features and current gaps.

## License

MIT
