
Product
Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.
@xbghc/gitcode-api
Advanced tools
TypeScript client library for GitCode API with type-safe wrappers for users, repositories, pull requests, and issues.
GitCode API 客户端库,提供与 GitCode 平台的完整集成。
pnpm add @xbghc/gitcode-api
import { GitcodeClient } from '@xbghc/gitcode-api';
const client = new GitcodeClient();
// 获取用户信息
const userProfile = await client.user.getProfile();
console.log(userProfile.name, userProfile.email);
// 获取用户命名空间
const namespace = await client.user.getNamespace();
console.log(namespace.path, namespace.type);
// 获取仓库设置
const settings = await client.repo.getSettings('owner', 'repo');
console.log(settings.default_branch);
// 获取仓库分支
const branches = await client.repo.getBranches('owner', 'repo');
branches.forEach((branch) => {
console.log(branch.name, branch.default);
});
// 获取提交历史
const commits = await client.repo.getCommits('owner', 'repo');
console.log(commits[0].sha, commits[0].commit.message);
// 获取贡献者
const contributors = await client.repo.getContributors('owner', 'repo');
contributors.forEach((contributor) => {
console.log(contributor.name, contributor.contributions);
});
// 获取 Webhooks
const webhooks = await client.repo.getWebhooks('owner', 'repo');
console.log(webhooks.length);
// 获取文件内容
const fileBlob = await client.repo.getFileBlob('owner', 'repo', 'file-sha');
console.log(fileBlob.content, fileBlob.encoding);
// 比较代码差异
const comparison = await client.repo.compare('owner', 'repo', 'base', 'head');
console.log(comparison.files.length);
// 获取 PR 列表
const pulls = await client.pr.list('https://gitcode.com/owner/repo', {
state: 'open',
});
// 创建 PR
const newPR = await client.pr.create('https://gitcode.com/owner/repo', {
title: '新功能',
head: 'feature-branch',
base: 'main',
body: '这是一个新功能的 PR',
});
// 获取 PR 评论
const comments = await client.pr.comments('https://gitcode.com/owner/repo', 1);
// 获取 PR 设置
const prSettings = await client.pr.getSettings('owner', 'repo');
console.log(prSettings.allow_merge_commits);
// 获取 Issue 列表
const issues = await client.issue.list('https://gitcode.com/owner/repo', {
state: 'open',
});
// 获取 Issue 评论
const comments = await client.issue.comments('https://gitcode.com/owner/repo', 1);
客户端支持多种认证方式:
// 环境变量
process.env.GITANY_TOKEN = 'your-token';
// 或
process.env.GITCODE_TOKEN = 'your-token';
// 配置文件存储在 ~/.gitany/gitcode/config.json
client.user.getProfile() - 获取当前用户信息client.user.getNamespace() - 获取用户命名空间client.repo.getSettings(owner, repo) - 获取仓库设置client.repo.getBranches(owner, repo) - 获取仓库所有分支client.repo.getBranch(owner, repo, branch) - 获取特定分支信息client.repo.getCommits(owner, repo) - 获取仓库提交历史client.repo.getContributors(owner, repo) - 获取仓库贡献者client.repo.getFileBlob(owner, repo, sha) - 获取文件内容client.repo.compare(owner, repo, base, head) - 比较代码差异client.repo.getWebhooks(owner, repo) - 获取仓库 Webhooksclient.repo.getWebhook(owner, repo, id) - 获取特定 Webhookclient.pr.list(url, options) - 获取 PR 列表client.pr.create(url, body) - 创建新 PRclient.pr.comments(url, prNumber, options) - 获取 PR 评论client.pr.getSettings(owner, repo) - 获取 PR 设置client.issue.list(url, options) - 获取 Issue 列表client.issue.comments(url, issueNumber, options) - 获取 Issue 评论所有 API 响应都有完整的 TypeScript 类型定义,包括:
UserProfile - 用户信息UserNamespace - 用户命名空间RepoSettings - 仓库设置Branch - 分支信息Commit - 提交信息Contributor - 贡献者信息FileBlob - 文件内容Compare - 代码比较结果Webhook - Webhook 配置PullRequestSettings - PR 设置try {
const user = await client.user.getProfile();
} catch (error) {
console.error('获取用户信息失败:', error);
}
MIT
FAQs
TypeScript client library for GitCode API with type-safe wrappers for users, repositories, pull requests, and issues.
The npm package @xbghc/gitcode-api receives a total of 4 weekly downloads. As such, @xbghc/gitcode-api popularity was classified as not popular.
We found that @xbghc/gitcode-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.

Research
/Security News
A new npm package tests AI malware scanners with prompt injection, safety-triggering comments, context flooding, and obfuscated JavaScript.