GitCode Issues API (v5) — Reference

All endpoints live under the base https://api.gitcode.com/api/v5. The legacy v4 layer exists but is unreliable (returns HTML instead of JSON on some paths, loses data on pagination) — do not use it.

Authentication: a personal access token, passed as the access_token query parameter. Create one at https://gitcode.com/setting/token-classic. Required scopes: api, read_repository, write_repository, issues.

Domain note: atomgit.com and gitcode.com share the same API backend and the same token. Owner/repo paths and endpoints are identical.

Read vs write auth (verified live). Listing issues, reading one issue, and reading its comments all work without any token on public repositories. The /user endpoint and /contents (file tree) require a token, and every write (comment, close) obviously requires one. This means reconnaissance can be done with no credentials at all (--no-auth), and a token is only needed for the reply/close phases.

The exact boundary, measured with no token set:

Endpoint No token
GET /repos/{o}/{r}/issues 200
GET /repos/{o}/{r}/issues/{n} 200
GET /repos/{o}/{r}/issues/{n}/comments 200
GET /repos/{o}/{r}/labels 200
GET /user (whoami) 401
POST /repos/{o}/{r}/issues/{n}/comments 401
PATCH /repos/{o}/{r}/issues/{n} 401
GET /repos/{o}/{r} 401
GET /repos/{o}/{r}/collaborators 401
GET /repos/{o}/{r}/permission 401

Consequence: a token's repository write permission cannot be probed anonymously — the repository metadata and permission endpoints are all behind auth. Confirm the account has write/push access to the repo out of band (web UI) before a write run.

login vs name (verified live)

GET /user returns both, and they are not interchangeable:

Field Meaning Mutable Live example
login Unique account handle, used in URLs Stable yertop
name Display name Yes, any time yert

The pipe account grape_bot happens to have login == name == "grape_bot", but yertop has name: "yert" — so assuming they match is unsafe. All identity comparisons (the idempotency check, the external-participant guard) compare against login. Passing name as --agent-login fails silently: no error, but the agent's own earlier comment becomes invisible to idempotency and readable as a stranger's participation, which blocks every close. whoami --agent-login X guards against this by reporting agent_login_matches.

Note that a comment's embedded user object carries both login and name, so the comparison must use login there too.

Live Payload Field Shapes (verified against a real repo)

The documented shape and the live shape differ. Code must tolerate both.

Field Documented Observed live Handling
assignee assignee: {...} assignees: [] — assignee key absent read both; normalised to _assignees
milestone milestone: int key absent treat absent as "none", never crash
state open / closed also seen close, opened compare lower-cased against {closed, close}
issue_state — workflow label, e.g. 待办的 not the open/closed flag — ignore for state
labels array of objects same ([{name, color}]) read .name

issue_state is a trap. A live payload shows state: "open" together with issue_state: "待办的" ("pending"). Only state decides open vs closed; do not infer closure from issue_state, and do not assume its values are English.

Endpoints Used by This Skill

1. Verify the token

GET /user?access_token=<token>

Returns the authenticated user. Read login — that is the value to pass as --agent-login so that idempotency and the external-participant guard work correctly.

2. List issues of a repository

GET /repos/{owner}/{repo}/issues?access_token=<token>&state=open&page=1&per_page=50
Param Type Notes
state query open | closed | all. Default open.
labels query Comma-separated label names.
sort query created_at (default) | updated_at.
direction query asc | desc. Default desc.
page query 1-based.
per_page query Max 100, default 20. Use 50–100 for triage listing. One page only — walk pages for a full tracker (list --all).

Response items include number, state, title, body, labels[], user.login, assignee, milestone, comments (count), created_at, updated_at.

3. Get a single issue

GET /repos/{owner}/{repo}/issues/{number}?access_token=<token>

Response is the issue object. state is the field to check when verifying a close. Note the response's state value can be opened / open / closed / close depending on the deployment — always compare lower-cased against the set, which the CLI does.

4. List comments of an issue

GET /repos/{owner}/{repo}/issues/{number}/comments?access_token=<token>

Returns an array; each item has id, body, user.login, created_at. On some deployments a non-existent issue returns 404 here — the CLI treats that as an empty list.

5. Create a comment (the reply step)

POST /repos/{owner}/{repo}/issues/{number}/comments?access_token=<token>
Content-Type: application/json

{ "body": "感谢您的支持,欢迎进一步使用交流" }

Quirk: some GitCode deployments reject a JSON body here and require form encoding. The CLI's post_comment tries JSON first and automatically falls back to application/x-www-form-urlencoded with the same body field. If both fail with 400, surface the raw error — do not assume success.

Idempotency: after posting, the CLI re-lists comments and confirms a comment with the exact body exists. If it is missing, the run aborts (exit 6) and the issue is not closed.

6. Close an issue (the close step)

The documented form is:

PATCH /repos/{owner}/issues/{number}?access_token=<token>
Content-Type: application/json

{ "state": "closed" }

Note the path variance: the update endpoint puts only {owner} and {number} in the path, with repo sent as a form field. Community reports differ on whether the state value is closed or close, and some wrappers accept the repo in the path. The CLI therefore tries, in order, and verifies after each:

  1. PATCH /repos/{owner}/{repo}/issues/{number} with {"state": "closed"}
  2. PATCH /repos/{owner}/{repo}/issues/{number} with {"state": "close"}
  3. PATCH /repos/{owner}/issues/{number} with {"state": "closed", "repo": "<repo>"}

After each attempt it re-reads the issue and only reports success when state is closed/close. If none succeed, it raises and the caller reports "replied, still open".

7. Duplicate scan (local)

There is no "find similar issues" endpoint. The CLI issues a single list --state all call and compares titles locally by Jaccard similarity over token sets. Threshold 0.5 by default, overridable with --threshold. A score is a candidate, never a verdict — read both bodies.

Error Reference

HTTP Meaning CLI exit Handling
400 Bad request / malformed body 1 The comment POST falls back to form encoding; otherwise surface the raw error.
401 Missing or invalid token 3 Re-issue the token; do not retry blindly.
403 Token lacks the needed scope 3 Add api, issues, write_repository.
404 Owner, repo, or issue not found 4 Skip this issue; verify the owner/repo path.
429 Rate limited 1 Handled automatically: retried with backoff. See below.
5xx Server error 1 Retry once after a pause; then stop and report.

A 404 on an issue returns a body like {"error_code":404,"error_message":"Issue Not Found","trace_id":"..."} — the CLI maps it to exit 4 and the message is safe to show the user.

Rate limiting (429) — measured, not theoretical

GitCode v5 enforces a per-account-and-IP budget of 50 requests per minute. The limit is global across all endpoints, so a triage sweep (one GET /issues plus one GET /issues/{n}/comments per issue) bursts past it after roughly 50 calls. The live 429 body is:

{"error_code":429,"error_code_name":"UN_KNOW",
 "error_message":"429 The number of times the user invokes this API is too large. Threshold: 50 times per user per Minute. Limited account:p_repoRobot.",
 "trace_id":"..."}

The CLI handles this without operator intervention:

  • Per-request retry. Any 429 is retried with exponential backoff, honouring a Retry-After header when present. Default 3 retries, overridable with GITCODE_MAX_RETRIES. A non-429 error is raised immediately — no retry.
  • Cooldown. A module-level RateLimiter records the 429 and holds a cooldown until the window elapses; every subsequent request waits it out first.
  • Adaptive pacing in batch. Each 429 doubles a per-request penalty (capped at 5s) that is added to --delay, so a burst self-throttles rather than repeatedly tripping the limit. batch reports the total rate_limited count in its JSON output.

If you see repeated 429s despite this, the budget is shared with other tooling on the same account/IP (note Limited account:p_repoRobot above) — lower --delay, split the batch, or wait a minute.

Environment Pitfalls

  • Windows console encoding. Piping the CLI's output to a file on a zh-CN Windows console defaults to cp936 and turns every Chinese title into mojibake. The CLI forces UTF-8 on stdout/stderr, but when redirecting from PowerShell also pass -Encoding utf8, and read the file back as UTF-8.
  • Token in argv. --token puts the secret in the process list. Prefer GITCODE_TOKEN in the environment.
  • Pagination is mandatory. GET /repos/{owner}/{repo}/issues caps per_page at 100 and returns only one page. A tracker with more issues needs an explicit walk, or rows past the first page are silently lost. Use list --all (or --pages N) so the CLI follows pages until a short page is returned. Without this a 142-issue tracker yields only 100 rows.
  • Rate limiting on bulk reads. Classifying a whole tracker means one GET /issues/{n}/comments per issue. Keep a small delay between calls, and cache the issue list once rather than re-listing per issue. The CLI's retry/cooldown logic covers this — see above.

curl equivalents (for manual sanity checks)

# token check
curl "https://api.gitcode.com/api/v5/user?access_token=$TOKEN"

# list open issues
curl "https://api.gitcode.com/api/v5/repos/$OWNER/$REPO/issues?state=open&per_page=50&access_token=$TOKEN"

# read one issue
curl "https://api.gitcode.com/api/v5/repos/$OWNER/$REPO/issues/$NUM?access_token=$TOKEN"

# post the fixed reply
curl -X POST "https://api.gitcode.com/api/v5/repos/$OWNER/$REPO/issues/$NUM/comments?access_token=$TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"body":"感谢您的支持,欢迎进一步使用交流"}'

# close the issue
curl -X PATCH "https://api.gitcode.com/api/v5/repos/$OWNER/$REPO/issues/$NUM?access_token=$TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"state":"closed"}'

Security

  • Never write the token into a file inside the skill directory or any tracked file.
  • Prefer the environment variable over the command line: on a shared machine, command-line arguments are visible in the process list.
  • Tokens are per-account and carry write access. Treat a leaked token as a compromise: revoke it at the token settings page immediately.