renovate 44.84.0 → 44.85.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/dist/config/presets/forgejo/index.js +3 -2
- package/dist/config/presets/forgejo/index.js.map +1 -1
- package/dist/config/presets/gitea/index.js +10 -3
- package/dist/config/presets/gitea/index.js.map +1 -1
- package/dist/constants/error-messages.d.ts +3 -2
- package/dist/constants/error-messages.js +3 -1
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/modules/platform/api.js +6 -6
- package/dist/modules/platform/forgejo/index.js +21 -587
- package/dist/modules/platform/forgejo/index.js.map +1 -1
- package/dist/modules/platform/gitea/gitea-helper.js +90 -74
- package/dist/modules/platform/gitea/gitea-helper.js.map +1 -1
- package/dist/modules/platform/gitea/index.js +561 -529
- package/dist/modules/platform/gitea/index.js.map +1 -1
- package/dist/modules/platform/gitea/labels.js +42 -0
- package/dist/modules/platform/gitea/labels.js.map +1 -0
- package/dist/modules/platform/gitea/pr-cache.js +66 -28
- package/dist/modules/platform/gitea/pr-cache.js.map +1 -1
- package/dist/modules/platform/gitea/schema.js +141 -5
- package/dist/modules/platform/gitea/schema.js.map +1 -1
- package/dist/modules/platform/gitea/utils.js +10 -8
- package/dist/modules/platform/gitea/utils.js.map +1 -1
- package/dist/modules/platform/gitlab/index.js +11 -3
- package/dist/modules/platform/gitlab/index.js.map +1 -1
- package/dist/util/cache/repository/types.d.ts +13 -8
- package/dist/util/http/forgejo.js +6 -35
- package/dist/util/http/forgejo.js.map +1 -1
- package/dist/workers/repository/error.js +5 -0
- package/dist/workers/repository/error.js.map +1 -1
- package/dist/workers/repository/process/lookup/index.js +2 -2
- package/dist/workers/repository/process/lookup/index.js.map +1 -1
- package/dist/workers/repository/update/pr/changelog/forgejo/index.js +1 -1
- package/dist/workers/repository/update/pr/changelog/forgejo/index.js.map +1 -1
- package/dist/workers/repository/update/pr/changelog/gitea/index.js +3 -3
- package/dist/workers/repository/update/pr/changelog/gitea/index.js.map +1 -1
- package/package.json +1 -1
- package/renovate-schema.json +2 -2
- package/dist/modules/platform/forgejo/forgejo-helper.js +0 -235
- package/dist/modules/platform/forgejo/forgejo-helper.js.map +0 -1
- package/dist/modules/platform/forgejo/pr-cache.js +0 -114
- package/dist/modules/platform/forgejo/pr-cache.js.map +0 -1
- package/dist/modules/platform/forgejo/schema.js +0 -149
- package/dist/modules/platform/forgejo/schema.js.map +0 -1
- package/dist/modules/platform/forgejo/utils.js +0 -115
- package/dist/modules/platform/forgejo/utils.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forgejo-helper.js","names":[],"sources":["../../../../lib/modules/platform/forgejo/forgejo-helper.ts"],"sourcesContent":["import { isBoolean } from '@sindresorhus/is';\nimport { z } from 'zod/v4';\nimport { logger } from '../../../logger/index.ts';\nimport type { BranchStatus } from '../../../types/index.ts';\nimport { getCache } from '../../../util/cache/repository/index.ts';\nimport type { ForgejoHttpOptions } from '../../../util/http/forgejo.ts';\nimport { ForgejoHttp } from '../../../util/http/forgejo.ts';\nimport { getQueryString } from '../../../util/url.ts';\nimport {\n Branch,\n Comment,\n CommitStatus,\n type CommitStatusType,\n Issue,\n Label,\n PR,\n Repo,\n RepoContents,\n RepoSearchResults,\n User,\n Version,\n} from './schema.ts';\nimport type {\n CombinedCommitStatus,\n CommentCreateParams,\n CommitStatusCreateParams,\n IssueCreateParams,\n IssueSearchParams,\n IssueUpdateLabelsParams,\n IssueUpdateParams,\n PRCreateParams,\n PRMergeParams,\n PRUpdateParams,\n PrReviewersParams,\n RepoSearchParams,\n} from './types.ts';\nimport { API_PATH } from './utils.ts';\n\nexport const forgejoHttp = new ForgejoHttp();\n\nfunction urlEscape(raw: string): string {\n return encodeURIComponent(raw);\n}\nconst commitStatusStates: CommitStatusType[] = [\n 'unknown',\n 'success',\n 'pending',\n 'warning',\n 'failure',\n 'error',\n];\n\nexport async function getCurrentUser(\n options: ForgejoHttpOptions = {},\n): Promise<User> {\n const url = `${API_PATH}/user`;\n const res = await forgejoHttp.getJson(url, options, User);\n return res.body;\n}\n\nexport async function getVersion(\n options: ForgejoHttpOptions = {},\n): Promise<string> {\n const url = `${API_PATH}/version`;\n const res = await forgejoHttp.getJson(url, options, Version);\n return res.body.version;\n}\n\nexport async function isOrg(organization: string): Promise<boolean> {\n const repoCache = getCache();\n repoCache.platform ??= {};\n repoCache.platform.forgejo ??= {};\n repoCache.platform.forgejo.orgs ??= {};\n const cached = repoCache.platform.forgejo.orgs[organization];\n if (isBoolean(cached)) {\n return cached;\n }\n try {\n const url = `${API_PATH}/orgs/${organization}`;\n const res = await forgejoHttp.getJsonUnchecked(url);\n repoCache.platform.forgejo.orgs[organization] = res.statusCode === 200;\n return res.statusCode === 200;\n } catch (err) {\n if (err.statusCode === 404) {\n return false;\n }\n // throw other errors\n throw err;\n }\n}\n\nexport async function searchRepos(\n params: RepoSearchParams,\n options?: ForgejoHttpOptions,\n): Promise<Repo[]> {\n const query = getQueryString(params);\n const url = `${API_PATH}/repos/search?${query}`;\n const res = await forgejoHttp.getJson(\n url,\n {\n ...options,\n paginate: true,\n },\n RepoSearchResults,\n );\n\n if (!res.body.ok) {\n throw new Error(\n 'Unable to search for repositories, ok flag has not been set',\n );\n }\n\n return res.body.data;\n}\n\nexport async function orgListRepos(\n organization: string,\n options?: ForgejoHttpOptions,\n): Promise<Repo[]> {\n const url = `${API_PATH}/orgs/${organization}/repos`;\n const res = await forgejoHttp.getJson(\n url,\n {\n ...options,\n paginate: true,\n },\n z.array(Repo),\n );\n\n return res.body;\n}\n\nexport async function getRepo(\n repoPath: string,\n options: ForgejoHttpOptions = {},\n): Promise<Repo> {\n const url = `${API_PATH}/repos/${repoPath}`;\n const res = await forgejoHttp.getJson(url, options, Repo);\n return res.body;\n}\n\nexport async function getRepoContents(\n repoPath: string,\n filePath: string,\n ref?: string | null,\n options: ForgejoHttpOptions = {},\n): Promise<RepoContents> {\n const query = getQueryString(ref ? { ref } : {});\n const url = `${API_PATH}/repos/${repoPath}/contents/${urlEscape(\n filePath,\n )}?${query}`;\n const res = await forgejoHttp.getJson(url, options, RepoContents);\n\n return res.body;\n}\n\nexport async function createPR(\n repoPath: string,\n params: PRCreateParams,\n options?: ForgejoHttpOptions,\n): Promise<PR> {\n const url = `${API_PATH}/repos/${repoPath}/pulls`;\n const res = await forgejoHttp.postJson(\n url,\n {\n ...options,\n body: params,\n },\n PR,\n );\n\n return res.body;\n}\n\nexport async function updatePR(\n repoPath: string,\n idx: number,\n params: PRUpdateParams,\n options?: ForgejoHttpOptions,\n): Promise<PR> {\n const url = `${API_PATH}/repos/${repoPath}/pulls/${idx}`;\n const res = await forgejoHttp.patchJson(\n url,\n {\n ...options,\n body: params,\n },\n PR,\n );\n\n return res.body;\n}\n\nexport async function closePR(\n repoPath: string,\n idx: number,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n await updatePR(repoPath, idx, {\n ...options,\n state: 'closed',\n });\n}\n\nexport async function mergePR(\n repoPath: string,\n idx: number,\n params: PRMergeParams,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n const url = `${API_PATH}/repos/${repoPath}/pulls/${idx}/merge`;\n await forgejoHttp.postJson(url, {\n ...options,\n body: params,\n });\n}\n\nexport async function getPR(\n repoPath: string,\n idx: number,\n options: ForgejoHttpOptions = {},\n): Promise<PR> {\n const url = `${API_PATH}/repos/${repoPath}/pulls/${idx}`;\n const res = await forgejoHttp.getJson(url, options, PR);\n return res.body;\n}\n\nexport async function getPRByBranch(\n repoPath: string,\n base: string,\n head: string,\n options: ForgejoHttpOptions = {},\n): Promise<PR | null> {\n const url = `${API_PATH}/repos/${repoPath}/pulls/${base}/${head}`;\n try {\n const res = await forgejoHttp.getJson(url, options, PR);\n return res.body;\n } catch (err) {\n logger.trace({ err }, 'Error while fetching PR');\n if (err.statusCode !== 404) {\n logger.debug({ err }, 'Error while fetching PR');\n }\n return null;\n }\n}\n\nexport async function requestPrReviewers(\n repoPath: string,\n idx: number,\n params: PrReviewersParams,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n const url = `${API_PATH}/repos/${repoPath}/pulls/${idx}/requested_reviewers`;\n await forgejoHttp.postJson(url, {\n ...options,\n body: params,\n });\n}\n\nexport async function createIssue(\n repoPath: string,\n params: IssueCreateParams,\n options?: ForgejoHttpOptions,\n): Promise<Issue> {\n const url = `${API_PATH}/repos/${repoPath}/issues`;\n const res = await forgejoHttp.postJson(\n url,\n {\n ...options,\n body: params,\n },\n Issue,\n );\n\n return res.body;\n}\n\nexport async function updateIssue(\n repoPath: string,\n idx: number,\n params: IssueUpdateParams,\n options?: ForgejoHttpOptions,\n): Promise<Issue> {\n const url = `${API_PATH}/repos/${repoPath}/issues/${idx}`;\n const res = await forgejoHttp.patchJson(\n url,\n {\n ...options,\n body: params,\n },\n Issue,\n );\n\n return res.body;\n}\n\nexport async function updateIssueLabels(\n repoPath: string,\n idx: number,\n params: IssueUpdateLabelsParams,\n options?: ForgejoHttpOptions,\n): Promise<Label[]> {\n const url = `${API_PATH}/repos/${repoPath}/issues/${idx}/labels`;\n const res = await forgejoHttp.putJson(\n url,\n {\n ...options,\n body: params,\n },\n z.array(Label),\n );\n\n return res.body;\n}\n\nexport async function closeIssue(\n repoPath: string,\n idx: number,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n await updateIssue(repoPath, idx, {\n ...options,\n state: 'closed',\n });\n}\n\nexport async function searchIssues(\n repoPath: string,\n params: IssueSearchParams,\n options?: ForgejoHttpOptions,\n): Promise<Issue[]> {\n const query = getQueryString({ ...params, type: 'issues' });\n const url = `${API_PATH}/repos/${repoPath}/issues?${query}`;\n const res = await forgejoHttp.getJson(\n url,\n {\n ...options,\n paginate: true,\n },\n z.array(Issue),\n );\n\n return res.body;\n}\n\nexport async function getIssue(\n repoPath: string,\n idx: number,\n options: ForgejoHttpOptions = {},\n): Promise<Issue> {\n const url = `${API_PATH}/repos/${repoPath}/issues/${idx}`;\n const res = await forgejoHttp.getJson(url, options, Issue);\n return res.body;\n}\n\nexport async function getRepoLabels(\n repoPath: string,\n options: ForgejoHttpOptions = {},\n): Promise<Label[]> {\n const url = `${API_PATH}/repos/${repoPath}/labels`;\n const res = await forgejoHttp.getJson(url, options, z.array(Label));\n\n return res.body;\n}\n\nexport async function getOrgLabels(\n orgName: string,\n options: ForgejoHttpOptions = {},\n): Promise<Label[]> {\n const url = `${API_PATH}/orgs/${orgName}/labels`;\n const res = await forgejoHttp.getJson(url, options, z.array(Label));\n\n return res.body;\n}\n\nexport async function unassignLabel(\n repoPath: string,\n issue: number,\n label: number,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n const url = `${API_PATH}/repos/${repoPath}/issues/${issue}/labels/${label}`;\n await forgejoHttp.deleteJson(url, options);\n}\n\nexport async function createComment(\n repoPath: string,\n issue: number,\n body: string,\n options?: ForgejoHttpOptions,\n): Promise<Comment> {\n const params: CommentCreateParams = { body };\n const url = `${API_PATH}/repos/${repoPath}/issues/${issue}/comments`;\n const res = await forgejoHttp.postJson(\n url,\n {\n ...options,\n body: params,\n },\n Comment,\n );\n\n return res.body;\n}\n\nexport async function updateComment(\n repoPath: string,\n idx: number,\n body: string,\n options?: ForgejoHttpOptions,\n): Promise<Comment> {\n const params: CommentCreateParams = { body };\n const url = `${API_PATH}/repos/${repoPath}/issues/comments/${idx}`;\n const res = await forgejoHttp.patchJson(\n url,\n {\n ...options,\n body: params,\n },\n Comment,\n );\n\n return res.body;\n}\n\nexport async function deleteComment(\n repoPath: string,\n idx: number,\n options?: ForgejoHttpOptions,\n): Promise<void> {\n const url = `${API_PATH}/repos/${repoPath}/issues/comments/${idx}`;\n await forgejoHttp.deleteJson(url, options);\n}\n\nexport async function getComments(\n repoPath: string,\n issue: number,\n options: ForgejoHttpOptions = {},\n): Promise<Comment[]> {\n const url = `${API_PATH}/repos/${repoPath}/issues/${issue}/comments`;\n const res = await forgejoHttp.getJson(url, options, z.array(Comment));\n\n return res.body;\n}\n\nexport async function createCommitStatus(\n repoPath: string,\n branchCommit: string,\n params: CommitStatusCreateParams,\n options?: ForgejoHttpOptions,\n): Promise<CommitStatus> {\n const url = `${API_PATH}/repos/${repoPath}/statuses/${branchCommit}`;\n const res = await forgejoHttp.postJson(\n url,\n {\n ...options,\n body: params,\n },\n CommitStatus,\n );\n\n return res.body;\n}\n\nexport const forgejoToRenovateStatusMapping: Record<\n CommitStatusType,\n BranchStatus\n> = {\n unknown: 'yellow',\n success: 'green',\n pending: 'yellow',\n warning: 'red',\n failure: 'red',\n error: 'red',\n};\n\nexport const renovateToForgejoStatusMapping: Record<\n BranchStatus,\n CommitStatusType\n> = {\n green: 'success',\n yellow: 'pending',\n red: 'failure',\n};\n\nfunction filterStatus(data: CommitStatus[]): CommitStatus[] {\n const ret: Record<string, CommitStatus> = {};\n for (const i of data) {\n if (!ret[i.context] || ret[i.context].id < i.id) {\n ret[i.context] = i;\n }\n }\n return Object.values(ret);\n}\n\nexport async function getCombinedCommitStatus(\n repoPath: string,\n branchName: string,\n options?: ForgejoHttpOptions,\n): Promise<CombinedCommitStatus> {\n const url = `${API_PATH}/repos/${repoPath}/commits/${urlEscape(\n branchName,\n )}/statuses`;\n const res = await forgejoHttp.getJson(\n url,\n {\n ...options,\n paginate: true,\n },\n z.array(CommitStatus),\n );\n\n let worstState = 0;\n const statuses = filterStatus(res.body);\n for (const cs of statuses) {\n worstState = Math.max(worstState, commitStatusStates.indexOf(cs.status));\n }\n\n return {\n worstStatus: commitStatusStates[worstState],\n statuses,\n };\n}\n\nexport async function getBranch(\n repoPath: string,\n branchName: string,\n options: ForgejoHttpOptions = {},\n): Promise<Branch> {\n const url = `${API_PATH}/repos/${repoPath}/branches/${urlEscape(branchName)}`;\n const res = await forgejoHttp.getJson(url, options, Branch);\n\n return res.body;\n}\n"],"mappings":";;;;;;;;;AAsCA,MAAa,cAAc,IAAI,YAAY;AAE3C,SAAS,UAAU,KAAqB;CACtC,OAAO,mBAAmB,GAAG;AAC/B;AACA,MAAM,qBAAyC;CAC7C;CACA;CACA;CACA;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AAM,MAAM,GAAG,SAAS,SAAS,SAAS,UAAU,MAAM;CAG1D,QAAO,MAFW,YAAY,QAAQ,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC,EAAA,CAEzD;AACb;AAEA,eAAsB,mBACpB,UACA,cACA,QACA,SACuB;CACvB,MAAM,MAAM,GAAG,SAAS,SAAS,SAAS,YAAY;CAUtD,QAAO,MATW,YAAY,SAC5B,KACA;EACE,GAAG;EACH,MAAM;CACR,GACA,YACF,EAAA,CAEW;AACb;AAEA,MAAa,iCAGT;CACF,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;AACT;AAEA,MAAa,iCAGT;CACF,OAAO;CACP,QAAQ;CACR,KAAK;AACP;AAEA,SAAS,aAAa,MAAsC;CAC1D,MAAM,MAAoC,CAAC;CAC3C,KAAK,MAAM,KAAK,MACd,IAAI,CAAC,IAAI,EAAE,YAAY,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,IAC3C,IAAI,EAAE,WAAW;CAGrB,OAAO,OAAO,OAAO,GAAG;AAC1B;AAEA,eAAsB,wBACpB,UACA,YACA,SAC+B;CAC/B,MAAM,MAAM,GAAG,SAAS,SAAS,SAAS,WAAW,UACnD,UACF,EAAE;CACF,MAAM,MAAM,MAAM,YAAY,QAC5B,KACA;EACE,GAAG;EACH,UAAU;CACZ,GACA,EAAE,MAAM,YAAY,CACtB;CAEA,IAAI,aAAa;CACjB,MAAM,WAAW,aAAa,IAAI,IAAI;CACtC,KAAK,MAAM,MAAM,UACf,aAAa,KAAK,IAAI,YAAY,mBAAmB,QAAQ,GAAG,MAAM,CAAC;CAGzE,OAAO;EACL,aAAa,mBAAmB;EAChC;CACF;AACF"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { TEMPORARY_ERROR } from "../../../constants/error-messages.js";
|
|
2
|
-
import { get, set } from "../../../util/cache/memory/index.js";
|
|
3
|
-
import { logger } from "../../../logger/index.js";
|
|
4
|
-
import { getQueryString, parseLinkHeader, parseUrl } from "../../../util/url.js";
|
|
5
|
-
import { getCache } from "../../../util/cache/repository/index.js";
|
|
6
|
-
import { PRList } from "./schema.js";
|
|
7
|
-
import { API_PATH, toRenovatePR } from "./utils.js";
|
|
8
|
-
import { isNullOrUndefined } from "@sindresorhus/is";
|
|
9
|
-
import { dequal } from "dequal";
|
|
10
|
-
import { DateTime } from "luxon";
|
|
11
|
-
//#region lib/modules/platform/forgejo/pr-cache.ts
|
|
12
|
-
var ForgejoPrCache = class ForgejoPrCache {
|
|
13
|
-
cache;
|
|
14
|
-
items = [];
|
|
15
|
-
repo;
|
|
16
|
-
ignorePrAuthor;
|
|
17
|
-
author;
|
|
18
|
-
constructor(repo, ignorePrAuthor, author) {
|
|
19
|
-
this.repo = repo;
|
|
20
|
-
this.ignorePrAuthor = ignorePrAuthor;
|
|
21
|
-
this.author = author;
|
|
22
|
-
const repoCache = getCache();
|
|
23
|
-
repoCache.platform ??= {};
|
|
24
|
-
repoCache.platform.forgejo ??= {};
|
|
25
|
-
let pullRequestCache = repoCache.platform.forgejo.pullRequestsCache;
|
|
26
|
-
if (isNullOrUndefined(pullRequestCache) || pullRequestCache.author !== author) pullRequestCache = {
|
|
27
|
-
items: {},
|
|
28
|
-
updated_at: null,
|
|
29
|
-
author
|
|
30
|
-
};
|
|
31
|
-
repoCache.platform.forgejo.pullRequestsCache = pullRequestCache;
|
|
32
|
-
this.cache = pullRequestCache;
|
|
33
|
-
this.updateItems();
|
|
34
|
-
}
|
|
35
|
-
static forceSync() {
|
|
36
|
-
set("forgejo-pr-cache-synced", false);
|
|
37
|
-
}
|
|
38
|
-
static async init(http, repo, ignorePrAuthor, author) {
|
|
39
|
-
const res = new ForgejoPrCache(repo, ignorePrAuthor, author);
|
|
40
|
-
if (!get("forgejo-pr-cache-synced")) {
|
|
41
|
-
await res.sync(http);
|
|
42
|
-
set("forgejo-pr-cache-synced", true);
|
|
43
|
-
}
|
|
44
|
-
return res;
|
|
45
|
-
}
|
|
46
|
-
getPrs() {
|
|
47
|
-
return this.items;
|
|
48
|
-
}
|
|
49
|
-
static async getPrs(http, repo, ignorePrAuthor, author) {
|
|
50
|
-
return (await ForgejoPrCache.init(http, repo, ignorePrAuthor, author)).getPrs();
|
|
51
|
-
}
|
|
52
|
-
setPr(item) {
|
|
53
|
-
this.cache.items[item.number] = item;
|
|
54
|
-
this.updateItems();
|
|
55
|
-
}
|
|
56
|
-
static async setPr(http, repo, ignorePrAuthor, author, item) {
|
|
57
|
-
(await ForgejoPrCache.init(http, repo, ignorePrAuthor, author)).setPr(item);
|
|
58
|
-
}
|
|
59
|
-
reconcile(rawItems) {
|
|
60
|
-
const { items } = this.cache;
|
|
61
|
-
let { updated_at } = this.cache;
|
|
62
|
-
const cacheTime = updated_at ? DateTime.fromISO(updated_at) : null;
|
|
63
|
-
let needNextPage = true;
|
|
64
|
-
for (const rawItem of rawItems) {
|
|
65
|
-
if (!rawItem) {
|
|
66
|
-
logger.warn("Forgejo PR is empty, throwing temporary error");
|
|
67
|
-
throw new Error(TEMPORARY_ERROR);
|
|
68
|
-
}
|
|
69
|
-
const id = rawItem.number;
|
|
70
|
-
const newItem = toRenovatePR(rawItem, this.author);
|
|
71
|
-
if (!newItem) continue;
|
|
72
|
-
const oldItem = items[id];
|
|
73
|
-
if (dequal(oldItem, newItem)) {
|
|
74
|
-
needNextPage = false;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
items[id] = newItem;
|
|
78
|
-
const itemTime = DateTime.fromISO(rawItem.updated_at);
|
|
79
|
-
if (!cacheTime || itemTime > cacheTime) updated_at = rawItem.updated_at;
|
|
80
|
-
}
|
|
81
|
-
this.cache.updated_at = updated_at;
|
|
82
|
-
return needNextPage;
|
|
83
|
-
}
|
|
84
|
-
async sync(http) {
|
|
85
|
-
let query = getQueryString({
|
|
86
|
-
state: "all",
|
|
87
|
-
sort: "recentupdate",
|
|
88
|
-
limit: this.items.length ? 20 : 100,
|
|
89
|
-
...this.ignorePrAuthor ? {} : { poster: this.author }
|
|
90
|
-
});
|
|
91
|
-
while (query) {
|
|
92
|
-
const res = await http.getJson(`${API_PATH}/repos/${this.repo}/pulls?${query}`, {
|
|
93
|
-
memCache: false,
|
|
94
|
-
paginate: false
|
|
95
|
-
}, PRList);
|
|
96
|
-
if (!this.reconcile(res.body)) break;
|
|
97
|
-
const uri = parseUrl(parseLinkHeader(res.headers.link)?.next?.url);
|
|
98
|
-
query = uri ? uri.search : null;
|
|
99
|
-
}
|
|
100
|
-
this.updateItems();
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Ensure the pr cache starts with the most recent PRs.
|
|
105
|
-
* JavaScript ensures that the cache is sorted by PR number.
|
|
106
|
-
*/
|
|
107
|
-
updateItems() {
|
|
108
|
-
this.items = Object.values(this.cache.items).reverse();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
|
-
export { ForgejoPrCache };
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=pr-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pr-cache.js","names":["memCache.get"],"sources":["../../../../lib/modules/platform/forgejo/pr-cache.ts"],"sourcesContent":["import { isNullOrUndefined } from '@sindresorhus/is';\nimport { dequal } from 'dequal';\nimport { DateTime } from 'luxon';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport * as memCache from '../../../util/cache/memory/index.ts';\nimport { getCache } from '../../../util/cache/repository/index.ts';\nimport type { ForgejoHttp } from '../../../util/http/forgejo.ts';\nimport {\n getQueryString,\n parseLinkHeader,\n parseUrl,\n} from '../../../util/url.ts';\nimport type { Pr } from '../types.ts';\nimport type { PR } from './schema.ts';\nimport { PRList } from './schema.ts';\nimport type { ForgejoPrCacheData } from './types.ts';\nimport { API_PATH, toRenovatePR } from './utils.ts';\n\nexport class ForgejoPrCache {\n private cache: ForgejoPrCacheData;\n private items: Pr[] = [];\n private repo: string;\n private readonly ignorePrAuthor: boolean;\n private author: string | null;\n\n private constructor(\n repo: string,\n ignorePrAuthor: boolean,\n author: string | null,\n ) {\n this.repo = repo;\n this.ignorePrAuthor = ignorePrAuthor;\n this.author = author;\n const repoCache = getCache();\n repoCache.platform ??= {};\n repoCache.platform.forgejo ??= {};\n let pullRequestCache = repoCache.platform.forgejo.pullRequestsCache as\n ForgejoPrCacheData | undefined;\n if (\n isNullOrUndefined(pullRequestCache) ||\n pullRequestCache.author !== author\n ) {\n pullRequestCache = {\n items: {},\n updated_at: null,\n author,\n };\n }\n repoCache.platform.forgejo.pullRequestsCache = pullRequestCache;\n this.cache = pullRequestCache;\n this.updateItems();\n }\n\n static forceSync(): void {\n memCache.set('forgejo-pr-cache-synced', false);\n }\n\n private static async init(\n http: ForgejoHttp,\n repo: string,\n ignorePrAuthor: boolean,\n author: string | null,\n ): Promise<ForgejoPrCache> {\n const res = new ForgejoPrCache(repo, ignorePrAuthor, author);\n const isSynced = memCache.get<true | undefined>('forgejo-pr-cache-synced');\n\n if (!isSynced) {\n await res.sync(http);\n memCache.set('forgejo-pr-cache-synced', true);\n }\n\n return res;\n }\n\n private getPrs(): Pr[] {\n return this.items;\n }\n\n static async getPrs(\n http: ForgejoHttp,\n repo: string,\n ignorePrAuthor: boolean,\n author: string,\n ): Promise<Pr[]> {\n const prCache = await ForgejoPrCache.init(\n http,\n repo,\n ignorePrAuthor,\n author,\n );\n return prCache.getPrs();\n }\n\n private setPr(item: Pr): void {\n this.cache.items[item.number] = item;\n this.updateItems();\n }\n\n static async setPr(\n http: ForgejoHttp,\n repo: string,\n ignorePrAuthor: boolean,\n author: string,\n item: Pr,\n ): Promise<void> {\n const prCache = await ForgejoPrCache.init(\n http,\n repo,\n ignorePrAuthor,\n author,\n );\n prCache.setPr(item);\n }\n\n private reconcile(rawItems: (PR | null)[]): boolean {\n const { items } = this.cache;\n let { updated_at } = this.cache;\n const cacheTime = updated_at ? DateTime.fromISO(updated_at) : null;\n\n let needNextPage = true;\n\n for (const rawItem of rawItems) {\n if (!rawItem) {\n logger.warn('Forgejo PR is empty, throwing temporary error');\n // Forgejo API sometimes returns empty PRs, so we throw a temporary error\n // https://github.com/go-forgejo/forgejo/blob/fcd096231ac2deaefbca10a7db1b9b01f1da93d7/services/convert/pull.go#L34-L52\n throw new Error(TEMPORARY_ERROR);\n }\n const id = rawItem.number;\n\n const newItem = toRenovatePR(rawItem, this.author);\n if (!newItem) {\n continue;\n }\n\n const oldItem = items[id];\n if (dequal(oldItem, newItem)) {\n needNextPage = false;\n continue;\n }\n\n items[id] = newItem;\n\n const itemTime = DateTime.fromISO(rawItem.updated_at);\n if (!cacheTime || itemTime > cacheTime) {\n updated_at = rawItem.updated_at;\n }\n }\n\n this.cache.updated_at = updated_at;\n\n return needNextPage;\n }\n\n private async sync(http: ForgejoHttp): Promise<ForgejoPrCache> {\n let query: string | null = getQueryString({\n state: 'all',\n sort: 'recentupdate',\n // Fetch 100 PRs on the first run to ensure we have the most recent PRs.\n // Forgejo will cap appropriate (50 by default, see `MAX_RESPONSE_ITEMS`).\n // https://docs.forgejo.com/administration/config-cheat-sheet#api-api\n // https://forgejo.org/docs/latest/admin/config-cheat-sheet/#api-api\n limit: this.items.length ? 20 : 100,\n // Supported since Forgejo v10.0.0.\n // Will be ignored by older instances.\n ...(this.ignorePrAuthor ? {} : { poster: this.author }),\n });\n\n while (query) {\n const res = await http.getJson(\n `${API_PATH}/repos/${this.repo}/pulls?${query}`,\n {\n memCache: false,\n paginate: false,\n },\n PRList,\n );\n\n const needNextPage = this.reconcile(res.body);\n if (!needNextPage) {\n break;\n }\n\n const uri = parseUrl(parseLinkHeader(res.headers.link)?.next?.url);\n query = uri ? uri.search : null;\n }\n\n this.updateItems();\n\n return this;\n }\n\n /**\n * Ensure the pr cache starts with the most recent PRs.\n * JavaScript ensures that the cache is sorted by PR number.\n */\n private updateItems(): void {\n this.items = Object.values(this.cache.items).reverse();\n }\n}\n"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,eAAe;EAEnB,KAAK,MAAM,WAAW,UAAU;GAC9B,IAAI,CAAC,SAAS;IACZ,OAAO,KAAK,+CAA+C;IAG3D,MAAM,IAAI,MAAM,eAAe;GACjC;GACA,MAAM,KAAK,QAAQ;GAEnB,MAAM,UAAU,aAAa,SAAS,KAAK,MAAM;GACjD,IAAI,CAAC,SACH;GAGF,MAAM,UAAU,MAAM;GACtB,IAAI,OAAO,SAAS,OAAO,GAAG;IAC5B,eAAe;IACf;GACF;GAEA,MAAM,MAAM;GAEZ,MAAM,WAAW,SAAS,QAAQ,QAAQ,UAAU;GACpD,IAAI,CAAC,aAAa,WAAW,WAC3B,aAAa,QAAQ;EAEzB;EAEA,KAAK,MAAM,aAAa;EAExB,OAAO;CACT;CAEA,MAAc,KAAK,MAA4C;EAC7D,IAAI,QAAuB,eAAe;GACxC,OAAO;GACP,MAAM;GAKN,OAAO,KAAK,MAAM,SAAS,KAAK;GAGhC,GAAI,KAAK,iBAAiB,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO;EACvD,CAAC;EAED,OAAO,OAAO;GACZ,MAAM,MAAM,MAAM,KAAK,QACrB,GAAG,SAAS,SAAS,KAAK,KAAK,SAAS,SACxC;IACE,UAAU;IACV,UAAU;GACZ,GACA,MACF;GAGA,IAAI,CADiB,KAAK,UAAU,IAAI,IACxB,GACd;GAGF,MAAM,MAAM,SAAS,gBAAgB,IAAI,QAAQ,IAAI,CAAC,EAAE,MAAM,GAAG;GACjE,QAAQ,MAAM,IAAI,SAAS;EAC7B;EAEA,KAAK,YAAY;EAEjB,OAAO;CACT;;;;;CAMA,cAA4B;EAC1B,KAAK,QAAQ,OAAO,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,QAAQ;CACvD;AACF"}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { fromBase64 } from "../../../util/string.js";
|
|
2
|
-
import { DeepNullish, EmailAddress, LooseArray } from "../../../util/schema-utils/index.js";
|
|
3
|
-
import { LongCommitSha } from "../../../util/schema-utils/git.js";
|
|
4
|
-
import { z } from "zod/v4";
|
|
5
|
-
//#region lib/modules/platform/forgejo/schema.ts
|
|
6
|
-
const ContentsCommon = z.object({
|
|
7
|
-
name: z.string(),
|
|
8
|
-
path: z.string()
|
|
9
|
-
});
|
|
10
|
-
const ContentsFile = ContentsCommon.extend({
|
|
11
|
-
type: z.literal("file"),
|
|
12
|
-
content: z.string().nullable()
|
|
13
|
-
}).transform((input) => ({
|
|
14
|
-
...input,
|
|
15
|
-
contentString: input.content ? fromBase64(input.content) : ""
|
|
16
|
-
}));
|
|
17
|
-
const ContentsDir = ContentsCommon.extend({ type: z.literal("dir") });
|
|
18
|
-
const ContentsSymlink = ContentsCommon.extend({ type: z.literal("symlink") });
|
|
19
|
-
const ContentsSubmodule = ContentsCommon.extend({ type: z.literal("submodule") });
|
|
20
|
-
const RepoContents = z.discriminatedUnion("type", [
|
|
21
|
-
ContentsFile,
|
|
22
|
-
ContentsDir,
|
|
23
|
-
ContentsSymlink,
|
|
24
|
-
ContentsSubmodule
|
|
25
|
-
]);
|
|
26
|
-
const ContentsListResponse = z.array(RepoContents);
|
|
27
|
-
const User = DeepNullish(z.object({
|
|
28
|
-
id: z.number(),
|
|
29
|
-
email: EmailAddress.optional().catch(void 0),
|
|
30
|
-
full_name: z.string().optional(),
|
|
31
|
-
login: z.string()
|
|
32
|
-
}));
|
|
33
|
-
const RepoPermission = z.object({
|
|
34
|
-
admin: z.boolean(),
|
|
35
|
-
pull: z.boolean(),
|
|
36
|
-
push: z.boolean()
|
|
37
|
-
});
|
|
38
|
-
const PRMergeMethod = z.enum([
|
|
39
|
-
"fast-forward-only",
|
|
40
|
-
"merge",
|
|
41
|
-
"rebase",
|
|
42
|
-
"rebase-merge",
|
|
43
|
-
"squash"
|
|
44
|
-
]);
|
|
45
|
-
const Repo = DeepNullish(z.object({
|
|
46
|
-
id: z.number(),
|
|
47
|
-
allow_fast_forward_only_merge: z.boolean().default(false),
|
|
48
|
-
allow_merge_commits: z.boolean().default(false),
|
|
49
|
-
allow_rebase: z.boolean().default(false),
|
|
50
|
-
allow_rebase_explicit: z.boolean().default(false),
|
|
51
|
-
allow_squash_merge: z.boolean().default(false),
|
|
52
|
-
archived: z.boolean().optional(),
|
|
53
|
-
clone_url: z.string().optional(),
|
|
54
|
-
default_merge_style: PRMergeMethod.optional().catch(void 0),
|
|
55
|
-
external_tracker: z.unknown().optional(),
|
|
56
|
-
has_issues: z.boolean().optional().default(false),
|
|
57
|
-
has_pull_requests: z.boolean().optional(),
|
|
58
|
-
ssh_url: z.string().optional(),
|
|
59
|
-
default_branch: z.string(),
|
|
60
|
-
empty: z.boolean().optional(),
|
|
61
|
-
fork: z.boolean().optional(),
|
|
62
|
-
full_name: z.string(),
|
|
63
|
-
mirror: z.boolean().optional(),
|
|
64
|
-
owner: User,
|
|
65
|
-
permissions: RepoPermission
|
|
66
|
-
}));
|
|
67
|
-
const Label = DeepNullish(z.object({
|
|
68
|
-
id: z.number(),
|
|
69
|
-
name: z.string(),
|
|
70
|
-
description: z.string().optional(),
|
|
71
|
-
color: z.string().optional()
|
|
72
|
-
}));
|
|
73
|
-
const PRState = z.enum([
|
|
74
|
-
"open",
|
|
75
|
-
"closed",
|
|
76
|
-
"all"
|
|
77
|
-
]);
|
|
78
|
-
const IssueState = z.enum([
|
|
79
|
-
"open",
|
|
80
|
-
"closed",
|
|
81
|
-
"all"
|
|
82
|
-
]);
|
|
83
|
-
const PartialRepo = z.object({ full_name: z.string() });
|
|
84
|
-
const PR = DeepNullish(z.object({
|
|
85
|
-
number: z.number(),
|
|
86
|
-
state: PRState,
|
|
87
|
-
title: z.string(),
|
|
88
|
-
body: z.string(),
|
|
89
|
-
mergeable: z.boolean(),
|
|
90
|
-
merged: z.boolean().optional(),
|
|
91
|
-
created_at: z.string(),
|
|
92
|
-
updated_at: z.string(),
|
|
93
|
-
closed_at: z.string().optional(),
|
|
94
|
-
diff_url: z.string().optional(),
|
|
95
|
-
base: z.object({ ref: z.string() }).optional(),
|
|
96
|
-
head: z.object({
|
|
97
|
-
label: z.string(),
|
|
98
|
-
sha: LongCommitSha,
|
|
99
|
-
repo: PartialRepo.optional()
|
|
100
|
-
}).optional(),
|
|
101
|
-
assignee: User.optional(),
|
|
102
|
-
assignees: z.array(User).optional(),
|
|
103
|
-
user: User.optional(),
|
|
104
|
-
labels: z.array(Label).optional()
|
|
105
|
-
}));
|
|
106
|
-
const NullablePR = PR.nullable();
|
|
107
|
-
const PRList = LooseArray(NullablePR);
|
|
108
|
-
const Issue = DeepNullish(z.object({
|
|
109
|
-
number: z.number(),
|
|
110
|
-
state: IssueState.optional(),
|
|
111
|
-
title: z.string(),
|
|
112
|
-
body: z.string(),
|
|
113
|
-
assignees: z.array(User).optional(),
|
|
114
|
-
labels: z.array(Label).optional()
|
|
115
|
-
}));
|
|
116
|
-
const Comment = z.object({
|
|
117
|
-
id: z.number(),
|
|
118
|
-
body: z.string()
|
|
119
|
-
});
|
|
120
|
-
const CommitStatusType = z.enum([
|
|
121
|
-
"pending",
|
|
122
|
-
"success",
|
|
123
|
-
"error",
|
|
124
|
-
"failure",
|
|
125
|
-
"warning",
|
|
126
|
-
"unknown"
|
|
127
|
-
]).catch("unknown");
|
|
128
|
-
const CommitStatus = DeepNullish(z.object({
|
|
129
|
-
id: z.number(),
|
|
130
|
-
status: CommitStatusType,
|
|
131
|
-
context: z.string(),
|
|
132
|
-
description: z.string().optional(),
|
|
133
|
-
target_url: z.string().optional(),
|
|
134
|
-
created_at: z.string()
|
|
135
|
-
}));
|
|
136
|
-
const Commit = z.object({ id: z.string() });
|
|
137
|
-
z.object({
|
|
138
|
-
name: z.string(),
|
|
139
|
-
commit: Commit
|
|
140
|
-
});
|
|
141
|
-
const RepoSearchResults = z.object({
|
|
142
|
-
ok: z.boolean(),
|
|
143
|
-
data: z.array(Repo)
|
|
144
|
-
});
|
|
145
|
-
const Version = z.object({ version: z.string() });
|
|
146
|
-
//#endregion
|
|
147
|
-
export { Comment, Commit, CommitStatus, CommitStatusType, ContentsListResponse, Issue, IssueState, Label, NullablePR, PR, PRList, PRMergeMethod, PRState, Repo, RepoContents, RepoPermission, RepoSearchResults, User, Version };
|
|
148
|
-
|
|
149
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../../../lib/modules/platform/forgejo/schema.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { LongCommitSha } from '../../../util/schema-utils/git.ts';\nimport {\n DeepNullish,\n EmailAddress,\n LooseArray,\n} from '../../../util/schema-utils/index.ts';\nimport { fromBase64 } from '../../../util/string.ts';\n\nconst ContentsCommon = z.object({\n name: z.string(),\n path: z.string(),\n});\n\nconst ContentsFile = ContentsCommon.extend({\n type: z.literal('file'),\n content: z.string().nullable(),\n}).transform((input) => ({\n ...input,\n contentString: input.content ? fromBase64(input.content) : '',\n}));\n\nconst ContentsDir = ContentsCommon.extend({ type: z.literal('dir') });\nconst ContentsSymlink = ContentsCommon.extend({ type: z.literal('symlink') });\nconst ContentsSubmodule = ContentsCommon.extend({\n type: z.literal('submodule'),\n});\n\nexport const RepoContents = z.discriminatedUnion('type', [\n ContentsFile,\n ContentsDir,\n ContentsSymlink,\n ContentsSubmodule,\n]);\nexport type RepoContents = z.infer<typeof RepoContents>;\n\nexport const ContentsListResponse = z.array(RepoContents);\n\nexport const User = DeepNullish(\n z.object({\n id: z.number(),\n // catch empty strings which are returned if an organization has no email\n email: EmailAddress.optional().catch(undefined),\n full_name: z.string().optional(),\n login: z.string(),\n }),\n);\nexport type User = z.infer<typeof User>;\n\nexport const RepoPermission = z.object({\n admin: z.boolean(),\n pull: z.boolean(),\n push: z.boolean(),\n});\nexport type RepoPermission = z.infer<typeof RepoPermission>;\n\nexport const PRMergeMethod = z.enum([\n 'fast-forward-only',\n 'merge',\n 'rebase',\n 'rebase-merge',\n 'squash',\n]);\nexport type PRMergeMethod = z.infer<typeof PRMergeMethod>;\n\n// Lenient Repo schema - only validates fields Renovate reads, most are optional\nexport const Repo = DeepNullish(\n z.object({\n id: z.number(),\n allow_fast_forward_only_merge: z.boolean().default(false),\n allow_merge_commits: z.boolean().default(false),\n allow_rebase: z.boolean().default(false),\n allow_rebase_explicit: z.boolean().default(false),\n allow_squash_merge: z.boolean().default(false),\n archived: z.boolean().optional(),\n clone_url: z.string().optional(),\n // catch unknown merge methods e.g. `manually-merged`\n default_merge_style: PRMergeMethod.optional().catch(undefined),\n external_tracker: z.unknown().optional(),\n has_issues: z.boolean().optional().default(false),\n has_pull_requests: z.boolean().optional(),\n ssh_url: z.string().optional(),\n default_branch: z.string(),\n empty: z.boolean().optional(),\n fork: z.boolean().optional(),\n full_name: z.string(),\n mirror: z.boolean().optional(),\n owner: User,\n permissions: RepoPermission,\n }),\n);\nexport type Repo = z.infer<typeof Repo>;\n\nexport const Label = DeepNullish(\n z.object({\n id: z.number(),\n name: z.string(),\n description: z.string().optional(),\n color: z.string().optional(),\n }),\n);\nexport type Label = z.infer<typeof Label>;\n\nexport const PRState = z.enum(['open', 'closed', 'all']);\nexport type PRState = z.infer<typeof PRState>;\n\nexport const IssueState = z.enum(['open', 'closed', 'all']);\nexport type IssueState = z.infer<typeof IssueState>;\n\n// Lenient partial repo schema for embedded repo references in PRs (only full_name is read)\nconst PartialRepo = z.object({\n full_name: z.string(),\n});\n\nexport const PR = DeepNullish(\n z.object({\n number: z.number(),\n state: PRState,\n title: z.string(),\n body: z.string(),\n mergeable: z.boolean(),\n merged: z.boolean().optional(),\n created_at: z.string(),\n updated_at: z.string(),\n closed_at: z.string().optional(),\n diff_url: z.string().optional(),\n base: z\n .object({\n ref: z.string(),\n })\n .optional(),\n head: z\n .object({\n label: z.string(),\n sha: LongCommitSha,\n repo: PartialRepo.optional(),\n })\n .optional(),\n assignee: User.optional(),\n assignees: z.array(User).optional(),\n user: User.optional(),\n labels: z.array(Label).optional(),\n }),\n);\nexport type PR = z.infer<typeof PR>;\n\n// TODO remove when the TEMPORARY_ERROR in pr-cache.ts is no longer needed\nexport const NullablePR = PR.nullable();\n\nexport const PRList = LooseArray(NullablePR);\n\nexport const Issue = DeepNullish(\n z.object({\n number: z.number(),\n state: IssueState.optional(),\n title: z.string(),\n body: z.string(),\n assignees: z.array(User).optional(),\n labels: z.array(Label).optional(),\n }),\n);\nexport type Issue = z.infer<typeof Issue>;\n\nexport const Comment = z.object({\n id: z.number(),\n body: z.string(),\n});\nexport type Comment = z.infer<typeof Comment>;\n\nexport const CommitStatusType = z\n .enum(['pending', 'success', 'error', 'failure', 'warning', 'unknown'])\n .catch('unknown');\nexport type CommitStatusType = z.infer<typeof CommitStatusType>;\n\nexport const CommitStatus = DeepNullish(\n z.object({\n id: z.number(),\n status: CommitStatusType,\n context: z.string(),\n description: z.string().optional(),\n target_url: z.string().optional(),\n created_at: z.string(),\n }),\n);\nexport type CommitStatus = z.infer<typeof CommitStatus>;\n\nexport const Commit = z.object({\n id: z.string(),\n});\nexport type Commit = z.infer<typeof Commit>;\n\nexport const Branch = z.object({\n name: z.string(),\n commit: Commit,\n});\nexport type Branch = z.infer<typeof Branch>;\n\nexport const RepoSearchResults = z.object({\n ok: z.boolean(),\n data: z.array(Repo),\n});\n\nexport const Version = z.object({\n version: z.string(),\n});\n"],"mappings":";;;;;AASA,MAAM,iBAAiB,EAAE,OAAO;CAC9B,MAAM,EAAE,OAAO;CACf,MAAM,EAAE,OAAO;AACjB,CAAC;AAED,MAAM,eAAe,eAAe,OAAO;CACzC,MAAM,EAAE,QAAQ,MAAM;CACtB,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;AAC/B,CAAC,CAAC,CAAC,WAAW,WAAW;CACvB,GAAG;CACH,eAAe,MAAM,UAAU,WAAW,MAAM,OAAO,IAAI;AAC7D,EAAE;AAEF,MAAM,cAAc,eAAe,OAAO,EAAE,MAAM,EAAE,QAAQ,KAAK,EAAE,CAAC;AACpE,MAAM,kBAAkB,eAAe,OAAO,EAAE,MAAM,EAAE,QAAQ,SAAS,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pB,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS;AAClC,CAAC,CACH;AAIA,MAAa,aAAa,GAAG,SAAS;AAEtC,MAAa,SAAS,WAAW,UAAU;AAE3C,MAAa,QAAQ,YACnB,EAAE,OAAO;CACP,QAAQ,EAAE,OAAO;CACjB,OAAO,WAAW,SAAS;CAC3B,OAAO,EAAE,OAAO;CAChB,MAAM,EAAE,OAAO;CACf,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC,SAAS;CAClC,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS;AAClC,CAAC,CACH;AAGA,MAAa,UAAU,EAAE,OAAO;CAC9B,IAAI,EAAE,OAAO;CACb,MAAM,EAAE,OAAO;AACjB,CAAC;AAGD,MAAa,mBAAmB,EAC7B,KAAK;CAAC;CAAW;CAAW;CAAS;CAAW;CAAW;AAAS,CAAC,CAAC,CACtE,MAAM,SAAS;AAGlB,MAAa,eAAe,YAC1B,EAAE,OAAO;CACP,IAAI,EAAE,OAAO;CACb,QAAQ;CACR,SAAS,EAAE,OAAO;CAClB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;CACjC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,YAAY,EAAE,OAAO;AACvB,CAAC,CACH;AAGA,MAAa,SAAS,EAAE,OAAO,EAC7B,IAAI,EAAE,OAAO,EACf,CAAC;AAGqB,EAAE,OAAO;CAC7B,MAAM,EAAE,OAAO;CACf,QAAQ;AACV,CAAC;AAGD,MAAa,oBAAoB,EAAE,OAAO;CACxC,IAAI,EAAE,QAAQ;CACd,MAAM,EAAE,MAAM,IAAI;AACpB,CAAC;AAED,MAAa,UAAU,EAAE,OAAO,EAC9B,SAAS,EAAE,OAAO,EACpB,CAAC"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { CONFIG_GIT_URL_UNAVAILABLE } from "../../../constants/error-messages.js";
|
|
2
|
-
import { regEx } from "../../../util/regex.js";
|
|
3
|
-
import { coerceArray } from "../../../util/array.js";
|
|
4
|
-
import { logger } from "../../../logger/index.js";
|
|
5
|
-
import { parseUrl } from "../../../util/url.js";
|
|
6
|
-
import { find } from "../../../util/host-rules.js";
|
|
7
|
-
import { getPrBodyStruct } from "../pr-body.js";
|
|
8
|
-
import { isNonEmptyArray } from "@sindresorhus/is";
|
|
9
|
-
//#region lib/modules/platform/forgejo/utils.ts
|
|
10
|
-
function smartLinks(body) {
|
|
11
|
-
return body?.replace(regEx(/\]\(\.\.\/issues\//g), "](issues/").replace(regEx(/\]\(\.\.\/pull\//g), "](pulls/");
|
|
12
|
-
}
|
|
13
|
-
function trimTrailingApiPath(url) {
|
|
14
|
-
return url?.replace(regEx(/api\/v1\/?$/g), "");
|
|
15
|
-
}
|
|
16
|
-
function getRepoUrl(repo, gitUrl, endpoint) {
|
|
17
|
-
if (gitUrl === "ssh") {
|
|
18
|
-
if (!repo.ssh_url) throw new Error(CONFIG_GIT_URL_UNAVAILABLE);
|
|
19
|
-
logger.debug(`Using SSH URL: ${repo.ssh_url}`);
|
|
20
|
-
return repo.ssh_url;
|
|
21
|
-
}
|
|
22
|
-
const opts = find({
|
|
23
|
-
hostType: "forgejo",
|
|
24
|
-
url: endpoint
|
|
25
|
-
});
|
|
26
|
-
if (gitUrl === "endpoint") {
|
|
27
|
-
const url = parseUrl(endpoint);
|
|
28
|
-
if (!url) throw new Error(CONFIG_GIT_URL_UNAVAILABLE);
|
|
29
|
-
url.username = opts.token ?? "";
|
|
30
|
-
url.pathname = `${url.pathname}${repo.full_name}.git`;
|
|
31
|
-
logger.debug({ url: url.toString() }, "using URL based on configured endpoint");
|
|
32
|
-
return url.toString();
|
|
33
|
-
}
|
|
34
|
-
if (!repo.clone_url) throw new Error(CONFIG_GIT_URL_UNAVAILABLE);
|
|
35
|
-
logger.debug(`Using HTTP URL: ${repo.clone_url}`);
|
|
36
|
-
const repoUrl = parseUrl(repo.clone_url);
|
|
37
|
-
if (!repoUrl) throw new Error(CONFIG_GIT_URL_UNAVAILABLE);
|
|
38
|
-
repoUrl.username = opts.token ?? "";
|
|
39
|
-
return repoUrl.toString();
|
|
40
|
-
}
|
|
41
|
-
function getMergeMethod(strategy) {
|
|
42
|
-
switch (strategy) {
|
|
43
|
-
case "fast-forward": return "rebase";
|
|
44
|
-
case "merge-commit": return "merge";
|
|
45
|
-
case "rebase": return "rebase-merge";
|
|
46
|
-
case "squash": return strategy;
|
|
47
|
-
default: return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const API_PATH = "/api/v1";
|
|
51
|
-
const DRAFT_PREFIX = "WIP: ";
|
|
52
|
-
const reconfigurePrRegex = regEx(/reconfigure$/);
|
|
53
|
-
function toRenovatePR(data, author) {
|
|
54
|
-
if (!data.base?.ref || !data.head?.label || !data.head?.sha || !data.head?.repo?.full_name) {
|
|
55
|
-
logger.trace(`Skipping Pull Request #${data.number} due to missing base and/or head branch`);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const createdBy = data.user?.login;
|
|
59
|
-
if (createdBy && author && !reconfigurePrRegex.test(data.head.label) && createdBy !== author) return null;
|
|
60
|
-
let title = data.title;
|
|
61
|
-
let isDraft = false;
|
|
62
|
-
if (title.startsWith("WIP: ")) {
|
|
63
|
-
title = title.substring(5);
|
|
64
|
-
isDraft = true;
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
labels: coerceArray(data.labels).map((l) => l.name),
|
|
68
|
-
number: data.number,
|
|
69
|
-
state: data.merged ? "merged" : data.state,
|
|
70
|
-
title,
|
|
71
|
-
isDraft,
|
|
72
|
-
bodyStruct: getPrBodyStruct(data.body),
|
|
73
|
-
sha: data.head.sha,
|
|
74
|
-
sourceBranch: data.head.label,
|
|
75
|
-
targetBranch: data.base.ref,
|
|
76
|
-
sourceRepo: data.head.repo.full_name,
|
|
77
|
-
createdAt: data.created_at,
|
|
78
|
-
cannotMergeReason: data.mergeable ? void 0 : `pr.mergeable="${data.mergeable}"`,
|
|
79
|
-
hasAssignees: !!(data.assignee?.login ?? isNonEmptyArray(data.assignees))
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Check if a repository is usable.
|
|
84
|
-
* A repo isn't usable if one of the following conditions is met:
|
|
85
|
-
* - The repo is a `mirror`
|
|
86
|
-
* - We don't have pull or push permissions
|
|
87
|
-
* - Pull requests are disabled
|
|
88
|
-
* @param repo Repo to check
|
|
89
|
-
* @returns `true` if the repository is usable, `false` otherwise
|
|
90
|
-
*/
|
|
91
|
-
function usableRepo(repo) {
|
|
92
|
-
if (repo.mirror === true) return false;
|
|
93
|
-
if (repo.permissions.pull === false || repo.permissions.push === false) {
|
|
94
|
-
logger.debug(`Skipping repository ${repo.full_name} because of missing pull or push permissions`);
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (repo.has_pull_requests === false) {
|
|
98
|
-
logger.debug(`Skipping repository ${repo.full_name} because pull requests are disabled`);
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
function isAllowed(style, repo) {
|
|
104
|
-
switch (style) {
|
|
105
|
-
case "merge": return repo.allow_merge_commits;
|
|
106
|
-
case "rebase": return repo.allow_rebase;
|
|
107
|
-
case "rebase-merge": return repo.allow_rebase_explicit;
|
|
108
|
-
case "squash": return repo.allow_squash_merge;
|
|
109
|
-
case "fast-forward-only": return repo.allow_fast_forward_only_merge;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
//#endregion
|
|
113
|
-
export { API_PATH, DRAFT_PREFIX, getMergeMethod, getRepoUrl, isAllowed, smartLinks, toRenovatePR, trimTrailingApiPath, usableRepo };
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["hostRules.find"],"sources":["../../../../lib/modules/platform/forgejo/utils.ts"],"sourcesContent":["import { isNonEmptyArray } from '@sindresorhus/is';\nimport type { MergeStrategy } from '../../../config/types.ts';\nimport { CONFIG_GIT_URL_UNAVAILABLE } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport * as hostRules from '../../../util/host-rules.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport { getPrBodyStruct } from '../pr-body.ts';\nimport type { GitUrlOption, Pr } from '../types.ts';\nimport type { PR, PRMergeMethod, Repo } from './schema.ts';\n\nexport function smartLinks(body: string): string {\n return body\n ?.replace(regEx(/\\]\\(\\.\\.\\/issues\\//g), '](issues/')\n .replace(regEx(/\\]\\(\\.\\.\\/pull\\//g), '](pulls/');\n}\n\nexport function trimTrailingApiPath(url: string): string {\n return url?.replace(regEx(/api\\/v1\\/?$/g), '');\n}\n\nexport function getRepoUrl(\n repo: Repo,\n gitUrl: GitUrlOption | undefined,\n endpoint: string,\n): string {\n if (gitUrl === 'ssh') {\n if (!repo.ssh_url) {\n throw new Error(CONFIG_GIT_URL_UNAVAILABLE);\n }\n logger.debug(`Using SSH URL: ${repo.ssh_url}`);\n return repo.ssh_url;\n }\n\n // Find options for current host and determine Git endpoint\n const opts = hostRules.find({\n hostType: 'forgejo',\n url: endpoint,\n });\n\n if (gitUrl === 'endpoint') {\n const url = parseUrl(endpoint);\n if (!url) {\n throw new Error(CONFIG_GIT_URL_UNAVAILABLE);\n }\n url.username = opts.token ?? '';\n url.pathname = `${url.pathname}${repo.full_name}.git`;\n logger.debug(\n { url: url.toString() },\n 'using URL based on configured endpoint',\n );\n return url.toString();\n }\n\n if (!repo.clone_url) {\n throw new Error(CONFIG_GIT_URL_UNAVAILABLE);\n }\n\n logger.debug(`Using HTTP URL: ${repo.clone_url}`);\n const repoUrl = parseUrl(repo.clone_url);\n if (!repoUrl) {\n throw new Error(CONFIG_GIT_URL_UNAVAILABLE);\n }\n repoUrl.username = opts.token ?? '';\n return repoUrl.toString();\n}\n\nexport function getMergeMethod(\n strategy: MergeStrategy | undefined,\n): PRMergeMethod | null {\n switch (strategy) {\n case 'fast-forward':\n return 'rebase';\n case 'merge-commit':\n return 'merge';\n case 'rebase':\n return 'rebase-merge';\n case 'squash':\n return strategy;\n case 'auto':\n default:\n return null;\n }\n}\n\nexport const API_PATH = '/api/v1';\n\nexport const DRAFT_PREFIX = 'WIP: ';\nconst reconfigurePrRegex = regEx(/reconfigure$/);\n\nexport function toRenovatePR(data: PR, author: string | null): Pr | null {\n if (\n !data.base?.ref ||\n !data.head?.label ||\n !data.head?.sha ||\n !data.head?.repo?.full_name\n ) {\n logger.trace(\n `Skipping Pull Request #${data.number} due to missing base and/or head branch`,\n );\n return null;\n }\n\n const createdBy = data.user?.login;\n if (\n createdBy &&\n author &&\n !reconfigurePrRegex.test(data.head.label) &&\n createdBy !== author\n ) {\n return null;\n }\n\n let title = data.title;\n let isDraft = false;\n if (title.startsWith(DRAFT_PREFIX)) {\n title = title.substring(DRAFT_PREFIX.length);\n isDraft = true;\n }\n const labels = coerceArray(data.labels).map((l) => l.name);\n\n return {\n labels,\n number: data.number,\n state: data.merged ? 'merged' : data.state,\n title,\n isDraft,\n bodyStruct: getPrBodyStruct(data.body),\n sha: data.head.sha,\n sourceBranch: data.head.label,\n targetBranch: data.base.ref,\n sourceRepo: data.head.repo.full_name,\n createdAt: data.created_at,\n cannotMergeReason: data.mergeable\n ? undefined\n : `pr.mergeable=\"${data.mergeable}\"`,\n hasAssignees: !!(data.assignee?.login ?? isNonEmptyArray(data.assignees)),\n };\n}\n\n/**\n * Check if a repository is usable.\n * A repo isn't usable if one of the following conditions is met:\n * - The repo is a `mirror`\n * - We don't have pull or push permissions\n * - Pull requests are disabled\n * @param repo Repo to check\n * @returns `true` if the repository is usable, `false` otherwise\n */\nexport function usableRepo(repo: Repo): boolean {\n if (repo.mirror === true) {\n return false;\n }\n\n if (repo.permissions.pull === false || repo.permissions.push === false) {\n logger.debug(\n `Skipping repository ${repo.full_name} because of missing pull or push permissions`,\n );\n return false;\n }\n\n if (repo.has_pull_requests === false) {\n logger.debug(\n `Skipping repository ${repo.full_name} because pull requests are disabled`,\n );\n return false;\n }\n return true;\n}\n\nexport function isAllowed(style: PRMergeMethod, repo: Repo): boolean {\n switch (style) {\n case 'merge':\n return repo.allow_merge_commits;\n case 'rebase':\n return repo.allow_rebase;\n case 'rebase-merge':\n return repo.allow_rebase_explicit;\n case 'squash':\n return repo.allow_squash_merge;\n case 'fast-forward-only':\n return repo.allow_fast_forward_only_merge;\n }\n}\n"],"mappings":";;;;;;;;;AAYA,SAAgB,WAAW,MAAsB;CAC/C,OAAO,MACH,QAAQ,MAAM,qBAAqB,GAAG,WAAW,CAAC,CACnD,QAAQ,MAAM,mBAAmB,GAAG,UAAU;AACnD;AAEA,SAAgB,oBAAoB,KAAqB;CACvD,OAAO,KAAK,QAAQ,MAAM,cAAc,GAAG,EAAE;AAC/C;AAEA,SAAgB,WACd,MACA,QACA,UACQ;CACR,IAAI,WAAW,OAAO;EACpB,IAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,0BAA0B;EAE5C,OAAO,MAAM,kBAAkB,KAAK,SAAS;EAC7C,OAAO,KAAK;CACd;CAGA,MAAM,OAAOA,KAAe;EAC1B,UAAU;EACV,KAAK;CACP,CAAC;CAED,IAAI,WAAW,YAAY;EACzB,MAAM,MAAM,SAAS,QAAQ;EAC7B,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,0BAA0B;EAE5C,IAAI,WAAW,KAAK,SAAS;EAC7B,IAAI,WAAW,GAAG,IAAI,WAAW,KAAK,UAAU;EAChD,OAAO,MACL,EAAE,KAAK,IAAI,SAAS,EAAE,GACtB,wCACF;EACA,OAAO,IAAI,SAAS;CACtB;CAEA,IAAI,CAAC,KAAK,WACR,MAAM,IAAI,MAAM,0BAA0B;CAG5C,OAAO,MAAM,mBAAmB,KAAK,WAAW;CAChD,MAAM,UAAU,SAAS,KAAK,SAAS;CACvC,IAAI,CAAC,SACH,MAAM,IAAI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