API Referansı

Genel Bakış

gityar, görevleri otomatikleştirmenizi, diğer araçlarla entegrasyonlar oluşturmanızı ve özel uygulamalar geliştirmenizi sağlayan kapsamlı bir REST API sağlar.

Kimlik Doğrulama

Temel Kimlik Doğrulama

curl -u "username:password" http://localhost:3000/api/v1/user

Erişim Belirteci (Önerilir)

AyarlarUygulamalarYeni Belirteç Oluştur'da bir belirteç oluşturun

curl -H "Authorization: token YOUR_TOKEN" http://localhost:3000/api/v1/user

Query Parametresi

curl http://localhost:3000/api/v1/user?token=YOUR_TOKEN

Temel URL

http://localhost:3000/api/v1

Veya yapılandırılmış alan adınız:

https://gityar.example.com/api/v1

API Endpoint'leri

Kullanıcı

Kimliği doğrulanmış kullanıcıyı al

GET /api/v1/user

Yanıt:

{
  "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"
}

Kullanıcıyı kullanıcı adına göre al

GET /api/v1/users/:username

Depolar

Depolarınızı listeleyin

GET /api/v1/user/repos

Kullanıcı depolarını listeleyin

GET /api/v1/users/:username/repos

Depoyu al

GET /api/v1/repos/:owner/:repo

Depo oluştur

POST /api/v1/user/repos

{
  "name": "my-repo",
  "description": "Benim depom",
  "private": false,
  "auto_init": true
}

Depo sil

DELETE /api/v1/repos/:owner/:repo

Sorunlar

Sorunları listeleyin

GET /api/v1/repos/:owner/:repo/issues
GET /api/v1/issues?filter=all

Sorun oluştur

POST /api/v1/repos/:owner/:repo/issues

{
  "title": "Hata: Bir şey bozuk",
  "body": "Ayrıntılı açıklama",
  "labels": [1, 2],
  "assignee": "username"
}

Sorunu al

GET /api/v1/repos/:owner/:repo/issues/:index

Sorunu güncelle

PATCH /api/v1/repos/:owner/:repo/issues/:index

{
  "title": "Güncellenmiş başlık",
  "state": "closed"
}

Çekme İstekleri

Çekme isteklerini listeleyin

GET /api/v1/repos/:owner/:repo/pulls

Çekme isteği oluştur

POST /api/v1/repos/:owner/:repo/pulls

{
  "title": "Yeni özellik ekle",
  "body": "Değişikliklerin açıklaması",
  "head": "feature-branch",
  "base": "main"
}

Çekme isteğini birleştir

POST /api/v1/repos/:owner/:repo/pulls/:index/merge

Organizasyonlar

Organizasyonlarınızı listeleyin

GET /api/v1/user/orgs

Organizasyonu al

GET /api/v1/orgs/:org

Organizasyon oluştur

POST /api/v1/orgs

{
  "username": "my-org",
  "full_name": "Benim Organizasyonum"
}

Web Kancaları

Depo web kancalarını listeleyin

GET /api/v1/repos/:owner/:repo/hooks

Web kanca oluştur

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
}

Sayfalama

Tüm liste endpoint'leri sayfalama destekler:

GET /api/v1/user/repos?page=2&limit=20

Yanıt başlıkları içerir:

  • X-Page: Mevcut sayfa numarası
  • X-PerPage: Sayfa başına öğe
  • X-Total-Count: Toplam öğe sayısı

Hız Sınırlama

API istekleri kötüye kullanımı önlemek için hız sınırlıdır.

Başlıklar:

  • X-RateLimit-Limit: Saat başına maksimum istek
  • X-RateLimit-Remaining: Kalan istekler
  • X-RateLimit-Reset: Sınırın sıfırlandığı zaman

Hata Yanıtları

400 Bad Request

{
  "message": "Geçersiz istek",
  "url": "http://localhost:3000/api/v1"
}

401 Unauthorized

{
  "message": "Yetkisiz"
}

404 Not Found

{
  "message": "Depo bulunamadı",
  "url": "http://localhost:3000/api/v1"
}

422 Unprocessable Entity

{
  "message": "Doğrulama başarısız",
  "errors": [
    {
      "resource": "Repository",
      "field": "name",
      "code": "invalid"
    }
  ]
}

Kod Örnekleri

Python

import requests

# Kimlik doğrulama
headers = {
    'Authorization': 'token YOUR_TOKEN'
}

# Depoları listele
response = requests.get(
    'http://localhost:3000/api/v1/user/repos',
    headers=headers
)

repos = response.json()
for repo in repos:
    print(repo['full_name'])

# Sorun oluştur
response = requests.post(
    'http://localhost:3000/api/v1/repos/owner/repo/issues',
    headers=headers,
    json={
        'title': 'Hata raporu',
        'body': 'Ayrıntılı açıklama'
    }
)

JavaScript (Node.js)

const axios = require('axios');

const client = axios.create({
  baseURL: 'http://localhost:3000/api/v1',
  headers: {
    'Authorization': 'token YOUR_TOKEN'
  }
});

// Depoları listele
async function listRepos() {
  const response = await client.get('/user/repos');
  return response.data;
}

// Sorun oluştur
async function createIssue(owner, repo, issue) {
  const response = await client.post(
    `/repos/${owner}/${repo}/issues`,
    issue
  );
  return response.data;
}

cURL

# Kullanıcı bilgilerini al
curl -H "Authorization: token YOUR_TOKEN" \
  http://localhost:3000/api/v1/user

# Depo oluştur
curl -X POST \
  -H "Authorization: token YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"my-repo","description":"Benim depom"}' \
  http://localhost:3000/api/v1/user/repos

Sonraki Adımlar