mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
- `internal/services`: typed Gitea workflows built on `gitea.dev/sdk`, independent of CLI flags and terminal I/O: issues, pull requests, reviews, comments, labels, milestones, releases and assets, repositories, branches, wiki, Actions (workflows, runs, jobs, logs, artifacts, secrets, variables), organizations, teams, webhooks, notifications, SSH keys, tracked time, admin users, search and status. - SDK types are mapped to tea's own output types, so `--json` stays a stable contract. Requests the SDK cannot express yet (e.g. pull list filters, multi-status run lists, org label archiving) go through small raw helpers, each marked `TODO(sdk)` with the missing SDK piece. - Targets Gitea 28 or newer: no version or API-schema probing. List helpers fill pages capped by `MAX_RESPONSE_ITEMS`. Nothing imports this package yet. Reviewed-on: https://gitea.com/gitea/tea/pulls/1125 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package services
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dev/tea/internal/transport"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// newTestClient serves handler for the duration of the test and returns a client for it.
|
|
// Requests probing the server version or API schema fail the test: tea targets one Gitea
|
|
// release and must never gate operations on either.
|
|
func newTestClient(t *testing.T, handler http.Handler) *transport.Client {
|
|
t.Helper()
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if strings.HasSuffix(r.URL.Path, "/api/v1/version") || strings.HasSuffix(r.URL.Path, "/swagger.v1.json") {
|
|
t.Errorf("unexpected capability probe %s", r.URL.Path)
|
|
w.WriteHeader(http.StatusTeapot)
|
|
return
|
|
}
|
|
handler.ServeHTTP(w, r)
|
|
}))
|
|
t.Cleanup(server.Close)
|
|
return transport.New(server.URL, "", false)
|
|
}
|
|
|
|
// requestJSON decodes the JSON object a handler received.
|
|
func requestJSON(t *testing.T, r *http.Request) map[string]any {
|
|
t.Helper()
|
|
var payload map[string]any
|
|
assert.NoError(t, json.NewDecoder(r.Body).Decode(&payload))
|
|
return payload
|
|
}
|