@apiclient.xyz/gitea 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +1 -1
- package/readme.md +265 -6
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@apiclient.xyz/gitea',
|
|
6
|
-
version: '1.0.
|
|
6
|
+
version: '1.0.3',
|
|
7
7
|
description: 'A TypeScript client for the Gitea API, providing easy access to repositories, organizations, secrets, and action runs.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxzQkFBc0I7SUFDNUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHdIQUF3SDtDQUN0SSxDQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apiclient.xyz/gitea",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A TypeScript client for the Gitea API, providing easy access to repositories, organizations, secrets, and action runs.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
package/readme.md
CHANGED
|
@@ -1,30 +1,289 @@
|
|
|
1
1
|
# @apiclient.xyz/gitea
|
|
2
2
|
|
|
3
|
-
A TypeScript client for the Gitea API, providing
|
|
3
|
+
A TypeScript client for the Gitea API, providing typed access to repositories, organizations, secrets management, and Gitea Actions workflow runs.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
npm install @apiclient.xyz/gitea
|
|
9
|
+
# or
|
|
10
|
+
pnpm install @apiclient.xyz/gitea
|
|
9
11
|
```
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
15
|
+
All examples below use ESM imports and top-level `await`. The package ships as a pure ESM module with full TypeScript type declarations.
|
|
16
|
+
|
|
17
|
+
### Creating a Client
|
|
18
|
+
|
|
13
19
|
```typescript
|
|
14
20
|
import { GiteaClient } from '@apiclient.xyz/gitea';
|
|
15
21
|
|
|
16
22
|
const client = new GiteaClient('https://gitea.example.com', 'your-api-token');
|
|
23
|
+
```
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
The `baseUrl` should point to your Gitea instance root (trailing slashes are stripped automatically). The `token` is an API token generated in Gitea under **Settings > Applications**.
|
|
26
|
+
|
|
27
|
+
### Testing the Connection
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
19
30
|
const result = await client.testConnection();
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
if (result.ok) {
|
|
33
|
+
console.log('Connected successfully.');
|
|
34
|
+
} else {
|
|
35
|
+
console.error('Connection failed:', result.error);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Listing Repositories
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Fetch the first page of repositories (default: 50 per page, sorted by updated)
|
|
22
43
|
const repos = await client.getRepos();
|
|
23
44
|
|
|
24
|
-
//
|
|
25
|
-
await client.
|
|
45
|
+
// Search with pagination
|
|
46
|
+
const results = await client.getRepos({
|
|
47
|
+
search: 'my-project',
|
|
48
|
+
page: 1,
|
|
49
|
+
perPage: 20,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
for (const repo of results) {
|
|
53
|
+
console.log(`${repo.full_name} - ${repo.description}`);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Listing Organizations
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const orgs = await client.getOrgs();
|
|
61
|
+
|
|
62
|
+
for (const org of orgs) {
|
|
63
|
+
console.log(`${org.name} (${org.repo_count} repos)`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// With pagination
|
|
67
|
+
const page2 = await client.getOrgs({ page: 2, perPage: 10 });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Managing Repository Secrets
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const ownerRepo = 'my-org/my-repo';
|
|
74
|
+
|
|
75
|
+
// List all secrets for a repository
|
|
76
|
+
const secrets = await client.getRepoSecrets(ownerRepo);
|
|
77
|
+
for (const secret of secrets) {
|
|
78
|
+
console.log(`${secret.name} (created ${secret.created_at})`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Create or update a secret
|
|
82
|
+
await client.setRepoSecret(ownerRepo, 'DEPLOY_TOKEN', 's3cret-value');
|
|
83
|
+
|
|
84
|
+
// Delete a secret
|
|
85
|
+
await client.deleteRepoSecret(ownerRepo, 'DEPLOY_TOKEN');
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Managing Organization Secrets
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const orgName = 'my-org';
|
|
92
|
+
|
|
93
|
+
// List all secrets for an organization
|
|
94
|
+
const orgSecrets = await client.getOrgSecrets(orgName);
|
|
95
|
+
|
|
96
|
+
// Create or update an organization-level secret
|
|
97
|
+
await client.setOrgSecret(orgName, 'NPM_TOKEN', 'npm_abc123');
|
|
98
|
+
|
|
99
|
+
// Delete an organization-level secret
|
|
100
|
+
await client.deleteOrgSecret(orgName, 'NPM_TOKEN');
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Working with Action Runs
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const ownerRepo = 'my-org/my-repo';
|
|
107
|
+
|
|
108
|
+
// List recent action runs
|
|
109
|
+
const runs = await client.getActionRuns(ownerRepo);
|
|
110
|
+
for (const run of runs) {
|
|
111
|
+
console.log(`#${run.id} ${run.name} [${run.status}/${run.conclusion}] on ${run.head_branch}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Paginate runs
|
|
115
|
+
const olderRuns = await client.getActionRuns(ownerRepo, { page: 2, perPage: 10 });
|
|
116
|
+
|
|
117
|
+
// Get jobs for a specific run
|
|
118
|
+
const jobs = await client.getActionRunJobs(ownerRepo, runs[0].id);
|
|
119
|
+
for (const job of jobs) {
|
|
120
|
+
console.log(` Job "${job.name}" - ${job.status} (${job.run_duration}s)`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Fetch raw log output for a job
|
|
124
|
+
const log = await client.getJobLog(ownerRepo, jobs[0].id);
|
|
125
|
+
console.log(log);
|
|
126
|
+
|
|
127
|
+
// Re-run a workflow
|
|
128
|
+
await client.rerunAction(ownerRepo, runs[0].id);
|
|
129
|
+
|
|
130
|
+
// Cancel a running workflow
|
|
131
|
+
await client.cancelAction(ownerRepo, runs[0].id);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## API Reference
|
|
135
|
+
|
|
136
|
+
### `GiteaClient`
|
|
137
|
+
|
|
138
|
+
| Method | Signature | Returns | Description |
|
|
139
|
+
|--------|-----------|---------|-------------|
|
|
140
|
+
| `constructor` | `(baseUrl: string, token: string)` | `GiteaClient` | Create a new client instance. |
|
|
141
|
+
| `testConnection` | `()` | `Promise<ITestConnectionResult>` | Verify credentials and connectivity. |
|
|
142
|
+
| `getRepos` | `(opts?: IListOptions)` | `Promise<IGiteaRepository[]>` | Search/list repositories with pagination. |
|
|
143
|
+
| `getOrgs` | `(opts?: IListOptions)` | `Promise<IGiteaOrganization[]>` | List organizations with pagination. |
|
|
144
|
+
| `getRepoSecrets` | `(ownerRepo: string)` | `Promise<IGiteaSecret[]>` | List all action secrets for a repository. |
|
|
145
|
+
| `setRepoSecret` | `(ownerRepo: string, key: string, value: string)` | `Promise<void>` | Create or update a repository secret. |
|
|
146
|
+
| `deleteRepoSecret` | `(ownerRepo: string, key: string)` | `Promise<void>` | Delete a repository secret. |
|
|
147
|
+
| `getOrgSecrets` | `(orgName: string)` | `Promise<IGiteaSecret[]>` | List all action secrets for an organization. |
|
|
148
|
+
| `setOrgSecret` | `(orgName: string, key: string, value: string)` | `Promise<void>` | Create or update an organization secret. |
|
|
149
|
+
| `deleteOrgSecret` | `(orgName: string, key: string)` | `Promise<void>` | Delete an organization secret. |
|
|
150
|
+
| `getActionRuns` | `(ownerRepo: string, opts?: IListOptions)` | `Promise<IGiteaActionRun[]>` | List action workflow runs for a repository. |
|
|
151
|
+
| `getActionRunJobs` | `(ownerRepo: string, runId: number)` | `Promise<IGiteaActionRunJob[]>` | List jobs within a specific action run. |
|
|
152
|
+
| `getJobLog` | `(ownerRepo: string, jobId: number)` | `Promise<string>` | Fetch the raw log output for a job. |
|
|
153
|
+
| `rerunAction` | `(ownerRepo: string, runId: number)` | `Promise<void>` | Re-run a completed action run. |
|
|
154
|
+
| `cancelAction` | `(ownerRepo: string, runId: number)` | `Promise<void>` | Cancel an in-progress action run. |
|
|
155
|
+
|
|
156
|
+
### Parameter Conventions
|
|
157
|
+
|
|
158
|
+
- **`ownerRepo`** -- Repository identifier in `"owner/repo"` format (e.g., `"my-org/my-repo"`).
|
|
159
|
+
- **`orgName`** -- Organization login name (e.g., `"my-org"`).
|
|
160
|
+
- **`key`** -- Secret name, typically uppercase with underscores (e.g., `"DEPLOY_TOKEN"`).
|
|
161
|
+
- **`runId` / `jobId`** -- Numeric identifiers returned by the list endpoints.
|
|
162
|
+
|
|
163
|
+
## Interfaces
|
|
164
|
+
|
|
165
|
+
All interfaces are exported from the package entry point and can be imported for type annotations.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import type {
|
|
169
|
+
IGiteaUser,
|
|
170
|
+
IGiteaRepository,
|
|
171
|
+
IGiteaOrganization,
|
|
172
|
+
IGiteaSecret,
|
|
173
|
+
IGiteaActionRun,
|
|
174
|
+
IGiteaActionRunJob,
|
|
175
|
+
ITestConnectionResult,
|
|
176
|
+
IListOptions,
|
|
177
|
+
} from '@apiclient.xyz/gitea';
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `IListOptions`
|
|
181
|
+
|
|
182
|
+
Pagination and search options accepted by list methods.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
interface IListOptions {
|
|
186
|
+
search?: string; // Free-text search query (repos only)
|
|
187
|
+
page?: number; // Page number (default: 1)
|
|
188
|
+
perPage?: number; // Results per page (default: 50 for repos/orgs, 30 for runs)
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `ITestConnectionResult`
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
interface ITestConnectionResult {
|
|
196
|
+
ok: boolean; // true if the connection succeeded
|
|
197
|
+
error?: string; // Error message when ok is false
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `IGiteaUser`
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
interface IGiteaUser {
|
|
205
|
+
id: number;
|
|
206
|
+
login: string;
|
|
207
|
+
full_name: string;
|
|
208
|
+
email: string;
|
|
209
|
+
avatar_url: string;
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### `IGiteaRepository`
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
interface IGiteaRepository {
|
|
217
|
+
id: number;
|
|
218
|
+
name: string;
|
|
219
|
+
full_name: string; // "owner/repo"
|
|
220
|
+
description: string;
|
|
221
|
+
default_branch: string;
|
|
222
|
+
html_url: string;
|
|
223
|
+
private: boolean;
|
|
224
|
+
topics: string[];
|
|
225
|
+
updated_at: string; // ISO 8601 timestamp
|
|
226
|
+
owner: {
|
|
227
|
+
id: number;
|
|
228
|
+
login: string;
|
|
229
|
+
avatar_url: string;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### `IGiteaOrganization`
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
interface IGiteaOrganization {
|
|
238
|
+
id: number;
|
|
239
|
+
name: string;
|
|
240
|
+
full_name: string;
|
|
241
|
+
description: string;
|
|
242
|
+
visibility: string; // "public", "limited", or "private"
|
|
243
|
+
repo_count: number;
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### `IGiteaSecret`
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface IGiteaSecret {
|
|
251
|
+
name: string; // Secret key name
|
|
252
|
+
created_at: string; // ISO 8601 timestamp
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### `IGiteaActionRun`
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
interface IGiteaActionRun {
|
|
260
|
+
id: number;
|
|
261
|
+
name: string; // Workflow name
|
|
262
|
+
status: string; // "running", "waiting", "success", "failure", etc.
|
|
263
|
+
conclusion: string; // Final result: "success", "failure", "cancelled", etc.
|
|
264
|
+
head_branch: string; // Branch that triggered the run
|
|
265
|
+
head_sha: string; // Commit SHA
|
|
266
|
+
html_url: string; // Web URL for the run
|
|
267
|
+
event: string; // Trigger event: "push", "pull_request", etc.
|
|
268
|
+
run_duration: number; // Duration in seconds
|
|
269
|
+
created_at: string; // ISO 8601 timestamp
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### `IGiteaActionRunJob`
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
interface IGiteaActionRunJob {
|
|
277
|
+
id: number;
|
|
278
|
+
name: string; // Job name from the workflow
|
|
279
|
+
status: string;
|
|
280
|
+
conclusion: string;
|
|
281
|
+
run_duration: number; // Duration in seconds
|
|
282
|
+
}
|
|
26
283
|
```
|
|
27
284
|
|
|
28
285
|
## License
|
|
29
286
|
|
|
30
|
-
MIT
|
|
287
|
+
MIT -- see [LICENSE](./license.md) for details.
|
|
288
|
+
|
|
289
|
+
Published under the [Lossless GmbH](https://lossless.com) umbrella.
|
package/ts/00_commitinfo_data.ts
CHANGED