@remogram/provider-gitea-api 0.1.0-beta.0 → 0.1.0-beta.2

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