گیتییار یک REST API جامع ارائه میدهد که به شما امکان میدهد وظایف را خودکار کنید، با ابزارهای دیگر انتگریشن بسازید و برنامههای سفارشی ایجاد کنید.
curl -u "username:password" http://localhost:3000/api/v1/user
یک توکن در تنظیمات → برنامهها → تولید توکن جدید ایجاد کنید
curl -H "Authorization: token YOUR_TOKEN" http://localhost:3000/api/v1/user
curl http://localhost:3000/api/v1/user?token=YOUR_TOKEN
http://localhost:3000/api/v1
یا دامنه پیکربندیشده شما:
https://gityar.example.com/api/v1
GET /api/v1/user
پاسخ:
{
"id": 1,
"login": "username",
"full_name": "Full Name",
"email": "user@example.com",
"avatar_url": "http://localhost:3000/user/avatar/username",
"created_at": "2024-01-01T00:00:00Z"
}
GET /api/v1/users/:username
GET /api/v1/user/repos
GET /api/v1/users/:username/repos
GET /api/v1/repos/:owner/:repo
POST /api/v1/user/repos
{
"name": "my-repo",
"description": "مخزن من",
"private": false,
"auto_init": true
}
DELETE /api/v1/repos/:owner/:repo
GET /api/v1/repos/:owner/:repo/issues
GET /api/v1/issues?filter=all
POST /api/v1/repos/:owner/:repo/issues
{
"title": "باگ: چیزی خراب است",
"body": "توضیح دقیق",
"labels": [1, 2],
"assignee": "username"
}
GET /api/v1/repos/:owner/:repo/issues/:index
PATCH /api/v1/repos/:owner/:repo/issues/:index
{
"title": "عنوان بهروز شده",
"state": "closed"
}
GET /api/v1/repos/:owner/:repo/pulls
POST /api/v1/repos/:owner/:repo/pulls
{
"title": "افزودن ویژگی جدید",
"body": "توضیح تغییرات",
"head": "feature-branch",
"base": "main"
}
POST /api/v1/repos/:owner/:repo/pulls/:index/merge
GET /api/v1/user/orgs
GET /api/v1/orgs/:org
POST /api/v1/orgs
{
"username": "my-org",
"full_name": "سازمان من"
}
GET /api/v1/repos/:owner/:repo/hooks
POST /api/v1/repos/:owner/:repo/hooks
{
"type": "gitea",
"config": {
"url": "https://example.com/webhook",
"content_type": "json",
"secret": "your-secret"
},
"events": ["push", "issues"],
"active": true
}
تمام endpoint های لیست از صفحهبندی پشتیبانی میکنند:
GET /api/v1/user/repos?page=2&limit=20
Header های پاسخ شامل:
X-Page: شماره صفحه فعلیX-PerPage: موارد در هر صفحهX-Total-Count: کل موارددرخواستهای API برای جلوگیری از سوء استفاده محدود میشوند.
Header ها:
X-RateLimit-Limit: حداکثر درخواست در هر ساعتX-RateLimit-Remaining: درخواستهای باقیماندهX-RateLimit-Reset: زمانی که محدودیت بازنشانی میشود{
"message": "درخواست نامعتبر",
"url": "http://localhost:3000/api/v1"
}
{
"message": "غیرمجاز"
}
{
"message": "مخزن یافت نشد",
"url": "http://localhost:3000/api/v1"
}
{
"message": "اعتبارسنجی ناموفق",
"errors": [
{
"resource": "Repository",
"field": "name",
"code": "invalid"
}
]
}
import requests
# احراز هویت
headers = {
'Authorization': 'token YOUR_TOKEN'
}
# لیست مخازن
response = requests.get(
'http://localhost:3000/api/v1/user/repos',
headers=headers
)
repos = response.json()
for repo in repos:
print(repo['full_name'])
# ایجاد مسئله
response = requests.post(
'http://localhost:3000/api/v1/repos/owner/repo/issues',
headers=headers,
json={
'title': 'گزارش باگ',
'body': 'توضیح دقیق'
}
)
const axios = require('axios');
const client = axios.create({
baseURL: 'http://localhost:3000/api/v1',
headers: {
'Authorization': 'token YOUR_TOKEN'
}
});
// لیست مخازن
async function listRepos() {
const response = await client.get('/user/repos');
return response.data;
}
// ایجاد مسئله
async function createIssue(owner, repo, issue) {
const response = await client.post(
`/repos/${owner}/${repo}/issues`,
issue
);
return response.data;
}
# دریافت اطلاعات کاربر
curl -H "Authorization: token YOUR_TOKEN" \
http://localhost:3000/api/v1/user
# ایجاد مخزن
curl -X POST \
-H "Authorization: token YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"my-repo","description":"مخزن من"}' \
http://localhost:3000/api/v1/user/repos