@remogram/provider-gitea-api 0.1.0-beta.0 → 0.1.0-beta.1
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/index.js +46 -7
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
gitAheadBehind,
|
|
10
10
|
ERROR_CODES,
|
|
11
11
|
forgeError,
|
|
12
|
+
forgeIngestCapabilityFacts,
|
|
12
13
|
} from '@remogram/core';
|
|
13
14
|
const PUBLIC_GITEA_HOST = 'gitea.com';
|
|
14
15
|
const PUBLIC_GITEA_API = 'https://gitea.com/api/v1';
|
|
@@ -117,6 +118,44 @@ export async function giteaFetch(config, parsed, path, options = {}) {
|
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
const MAX_CHECK_PAGES = 50;
|
|
122
|
+
const GITEA_PAGE_SIZE = 100;
|
|
123
|
+
|
|
124
|
+
export async function giteaFetchPaginated(config, parsed, path) {
|
|
125
|
+
const all = [];
|
|
126
|
+
for (let page = 1; page <= MAX_CHECK_PAGES; page += 1) {
|
|
127
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
128
|
+
const body = await giteaFetch(
|
|
129
|
+
config,
|
|
130
|
+
parsed,
|
|
131
|
+
`${path}${separator}limit=${GITEA_PAGE_SIZE}&page=${page}`,
|
|
132
|
+
);
|
|
133
|
+
const items = Array.isArray(body) ? body : [];
|
|
134
|
+
all.push(...items);
|
|
135
|
+
if (items.length < GITEA_PAGE_SIZE) break;
|
|
136
|
+
}
|
|
137
|
+
return all;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function normalizeGiteaStatusState(state) {
|
|
141
|
+
const normalized = String(state ?? '').toLowerCase();
|
|
142
|
+
if (normalized === 'success' || normalized === 'pass') return 'success';
|
|
143
|
+
if (normalized === 'pending' || normalized === 'running' || normalized === 'waiting') {
|
|
144
|
+
return 'pending';
|
|
145
|
+
}
|
|
146
|
+
if (normalized === 'failure' || normalized === 'fail' || normalized === 'error') {
|
|
147
|
+
return 'failure';
|
|
148
|
+
}
|
|
149
|
+
return 'unknown';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function normalizeGiteaPrState(state) {
|
|
153
|
+
const normalized = String(state ?? '').toLowerCase();
|
|
154
|
+
if (normalized === 'open') return 'open';
|
|
155
|
+
if (normalized === 'closed') return 'closed';
|
|
156
|
+
return normalized || 'unknown';
|
|
157
|
+
}
|
|
158
|
+
|
|
120
159
|
export async function repoStatus(ctx) {
|
|
121
160
|
const token = giteaToken();
|
|
122
161
|
let defaultBranch = null;
|
|
@@ -139,13 +178,13 @@ export function providerCapabilities() {
|
|
|
139
178
|
check_sources: ['commit_statuses'],
|
|
140
179
|
mergeability_confidence: 'direct',
|
|
141
180
|
host_binding: 'verified_remote_host',
|
|
142
|
-
pagination: '
|
|
181
|
+
pagination: 'supported',
|
|
143
182
|
write_support: false,
|
|
183
|
+
...forgeIngestCapabilityFacts(),
|
|
144
184
|
};
|
|
145
185
|
}
|
|
146
186
|
|
|
147
187
|
export async function refsCompare(ctx, baseRef, headRef) {
|
|
148
|
-
requireToken();
|
|
149
188
|
assertGitRef(baseRef, 'base');
|
|
150
189
|
assertGitRef(headRef, 'head');
|
|
151
190
|
const baseSha = gitRevParse(ctx.cwd, baseRef);
|
|
@@ -186,7 +225,7 @@ export async function prView(ctx, opts) {
|
|
|
186
225
|
pr_number: pr.number,
|
|
187
226
|
url: sanitizeUrl(pr.html_url ?? pr.url),
|
|
188
227
|
title: sanitizeField(pr.title),
|
|
189
|
-
state:
|
|
228
|
+
state: normalizeGiteaPrState(pr.state),
|
|
190
229
|
base_ref: sanitizeField(pr.base?.ref),
|
|
191
230
|
base_sha: sanitizeField(pr.base?.sha),
|
|
192
231
|
head_ref: sanitizeField(pr.head?.ref),
|
|
@@ -215,21 +254,21 @@ export async function prChecks(ctx, opts) {
|
|
|
215
254
|
forgeError: forgeError(ERROR_CODES.MISSING_REF, 'Could not determine head SHA for checks'),
|
|
216
255
|
});
|
|
217
256
|
}
|
|
218
|
-
const
|
|
257
|
+
const statusRecords = await giteaFetchPaginated(
|
|
219
258
|
ctx.config,
|
|
220
259
|
ctx.parsed,
|
|
221
260
|
repoApiPath(ctx.config, 'commits', sha, 'statuses'),
|
|
222
261
|
);
|
|
223
|
-
const mapped =
|
|
262
|
+
const mapped = statusRecords.map((s) => ({
|
|
224
263
|
context: sanitizeField(s.context),
|
|
225
|
-
state:
|
|
264
|
+
state: normalizeGiteaStatusState(s.state),
|
|
226
265
|
description: sanitizeField(s.description),
|
|
227
266
|
}));
|
|
228
267
|
const conclusion = summarizeChecks(mapped);
|
|
229
268
|
return { head_sha: sha, check_conclusion: conclusion, statuses: mapped };
|
|
230
269
|
}
|
|
231
270
|
|
|
232
|
-
function summarizeChecks(statuses) {
|
|
271
|
+
export function summarizeChecks(statuses) {
|
|
233
272
|
if (!statuses.length) return 'missing';
|
|
234
273
|
if (statuses.some((s) => s.state === 'failure' || s.state === 'error')) return 'failure';
|
|
235
274
|
if (statuses.some((s) => s.state === 'pending')) return 'pending';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remogram/provider-gitea-api",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "Gitea REST API forge provider for remogram",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@remogram/core": "0.1.0-beta.
|
|
25
|
+
"@remogram/core": "0.1.0-beta.1"
|
|
26
26
|
}
|
|
27
27
|
}
|