renovate 44.84.0 → 44.85.0
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/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/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/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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["helper\n .getRepoLabels","helper\n .getOrgLabels","helper.searchRepos","helper.getCurrentUser","helper.getVersion","helper.getRepoContents","helper.getRepo","git.initRepo","helper.orgListRepos","git.getBranchCommit","helper.createCommitStatus","helper.renovateToGiteaStatusMapping","helper.getCombinedCommitStatus","helper.giteaToRenovateStatusMapping","helper.getPR","helper.getPRByBranch","helper.createPR","helper.mergePR","helper.updatePR","helper\n .searchIssues","helper.getIssue","helper.closeIssue","helper.updateIssue","helper.updateIssueLabels","helper.createIssue","helper.unassignLabel","helper.getComments","helper.createComment","helper.updateComment","helper.deleteComment","helper.requestPrReviewers"],"sources":["../../../../lib/modules/platform/gitea/index.ts"],"sourcesContent":["import { isNumber, isString } from '@sindresorhus/is';\nimport semver from 'semver';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport {\n REPOSITORY_ACCESS_FORBIDDEN,\n REPOSITORY_ARCHIVED,\n REPOSITORY_BLOCKED,\n REPOSITORY_CHANGED,\n REPOSITORY_EMPTY,\n REPOSITORY_MIRRORED,\n} from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport type { BranchStatus } from '../../../types/index.ts';\nimport { coerceArray, deduplicateArray } from '../../../util/array.ts';\nimport { parseJson } from '../../../util/common.ts';\nimport { getEnv } from '../../../util/env.ts';\nimport * as git from '../../../util/git/index.ts';\nimport { setBaseUrl } from '../../../util/http/gitea.ts';\nimport { map } from '../../../util/promises.ts';\nimport { sanitize } from '../../../util/sanitize.ts';\nimport { ensureTrailingSlash } from '../../../util/url.ts';\nimport { getPrBodyStruct, hashBody } from '../pr-body.ts';\nimport type {\n AutodiscoverConfig,\n BranchStatusConfig,\n CreatePRConfig,\n EnsureCommentConfig,\n EnsureCommentRemovalConfig,\n EnsureIssueConfig,\n FindPRConfig,\n Issue,\n MergePRConfig,\n Platform,\n PlatformParams,\n PlatformResult,\n Pr,\n RepoParams,\n RepoResult,\n RepoSortMethod,\n SortMethod,\n UpdatePrConfig,\n} from '../types.ts';\nimport { repoFingerprint } from '../util.ts';\nimport { smartTruncate } from '../utils/pr-body.ts';\nimport * as helper from './gitea-helper.ts';\nimport { giteaHttp } from './gitea-helper.ts';\nimport { GiteaPrCache } from './pr-cache.ts';\nimport type {\n CombinedCommitStatus,\n Comment,\n Label,\n PRMergeMethod,\n PRUpdateParams,\n Repo,\n} from './types.ts';\nimport {\n DRAFT_PREFIX,\n getMergeMethod,\n getRepoUrl,\n isAllowed,\n smartLinks,\n toRenovatePR,\n trimTrailingApiPath,\n usableRepo,\n} from './utils.ts';\n\ninterface GiteaRepoConfig {\n ignorePrAuthor: boolean;\n repository: string;\n mergeMethod: PRMergeMethod;\n\n issueList: Promise<Issue[]> | null;\n labelList: Promise<Label[]> | null;\n defaultBranch: string;\n cloneSubmodules: boolean;\n cloneSubmodulesFilter: string[] | undefined;\n hasIssuesEnabled: boolean;\n}\n\nexport const id = 'gitea';\n\nconst defaults = {\n hostType: 'gitea',\n endpoint: 'https://gitea.com/',\n version: '0.0.0',\n isForgejo: false,\n};\n\nlet config: GiteaRepoConfig = {} as any;\nlet botUserID: number;\nlet botUserName: string;\n\nexport function resetPlatform(): void {\n config = {} as any;\n botUserID = undefined as never;\n botUserName = undefined as never;\n defaults.hostType = 'gitea';\n defaults.endpoint = 'https://gitea.com/';\n defaults.version = '0.0.0';\n defaults.isForgejo = false;\n setBaseUrl(defaults.endpoint);\n}\n\nfunction toRenovateIssue(data: Issue): Issue {\n return {\n number: data.number,\n state: data.state,\n title: data.title,\n body: data.body,\n };\n}\n\nfunction matchesState(actual: string, expected: string): boolean {\n if (expected === 'all') {\n return true;\n }\n if (expected.startsWith('!')) {\n return actual !== expected.substring(1);\n }\n\n return actual === expected;\n}\n\nfunction findCommentByTopic(\n comments: Comment[],\n topic: string,\n): Comment | null {\n return comments.find((c) => c.body.startsWith(`### ${topic}\\n\\n`)) ?? null;\n}\n\nfunction findCommentByContent(\n comments: Comment[],\n content: string,\n): Comment | null {\n return comments.find((c) => c.body.trim() === content) ?? null;\n}\n\nfunction getLabelList(): Promise<Label[]> {\n if (config.labelList === null) {\n const repoLabels = helper\n .getRepoLabels(config.repository, {\n memCache: false,\n })\n .then((labels) => {\n logger.debug(`Retrieved ${labels.length} repo labels`);\n return labels;\n });\n\n const orgLabels = helper\n .getOrgLabels(config.repository.split('/')[0], {\n memCache: false,\n })\n .then((labels) => {\n logger.debug(`Retrieved ${labels.length} org labels`);\n return labels;\n })\n .catch(() => {\n // Will fail if owner of repo is not org or Gitea version < 1.12\n logger.debug(`Unable to fetch organization labels`);\n return [] as Label[];\n });\n\n config.labelList = Promise.all([repoLabels, orgLabels]).then((labels) =>\n ([] as Label[]).concat(...labels),\n );\n }\n\n return config.labelList;\n}\n\nasync function lookupLabelByName(name: string): Promise<number | null> {\n logger.debug(`lookupLabelByName(${name})`);\n const labelList = await getLabelList();\n return labelList.find((l) => l.name === name)?.id ?? null;\n}\n\ninterface FetchRepositoriesArgs {\n topic?: string;\n sort?: RepoSortMethod;\n order?: SortMethod;\n}\n\nasync function fetchRepositories({\n topic,\n sort,\n order,\n}: FetchRepositoriesArgs): Promise<string[]> {\n const repos = await helper.searchRepos({\n uid: botUserID,\n archived: false,\n ...(topic && {\n topic: true,\n q: topic,\n }),\n ...(sort && {\n sort,\n }),\n ...(order && {\n order,\n }),\n });\n return repos.filter(usableRepo).map((r) => r.full_name);\n}\n\nconst platform: Platform = {\n async initPlatform({\n endpoint,\n token,\n }: PlatformParams): Promise<PlatformResult> {\n if (!token) {\n throw new Error('Init: You must configure a Gitea personal access token');\n }\n\n if (endpoint) {\n let baseEndpoint = trimTrailingApiPath(endpoint);\n baseEndpoint = ensureTrailingSlash(baseEndpoint);\n defaults.endpoint = baseEndpoint;\n } else {\n logger.debug(`Using default Gitea endpoint: ${defaults.endpoint}`);\n }\n setBaseUrl(defaults.endpoint);\n\n let gitAuthor: string;\n try {\n const user = await helper.getCurrentUser({ token });\n // oxlint-disable-next-line typescript/prefer-nullish-coalescing -- `full_name` can be emtpy string\n gitAuthor = `${user.full_name || user.login} <${user.email}>`;\n botUserID = user.id;\n botUserName = user.login;\n const env = getEnv();\n /* v8 ignore next: experimental feature */\n if (semver.valid(env.RENOVATE_X_PLATFORM_VERSION)) {\n defaults.version = env.RENOVATE_X_PLATFORM_VERSION!;\n } else {\n defaults.version = await helper.getVersion({ token });\n }\n if (defaults.version?.includes('gitea-')) {\n defaults.isForgejo = true;\n logger.info(\n `Detected Forgejo instance, please use 'forgejo' platform instead`,\n );\n }\n logger.debug(\n `${defaults.isForgejo ? 'Forgejo' : 'Gitea'} version: ${defaults.version}`,\n );\n } catch (err) {\n logger.debug(\n { err },\n 'Error authenticating with Gitea. Check your token',\n );\n throw new Error('Init: Authentication failure');\n }\n\n return {\n endpoint: defaults.endpoint,\n gitAuthor,\n };\n },\n\n async getRawFile(\n fileName: string,\n repoName?: string,\n branchOrTag?: string,\n ): Promise<string | null> {\n const repo = repoName ?? config.repository;\n const contents = await helper.getRepoContents(repo, fileName, branchOrTag);\n return contents.contentString ?? null;\n },\n\n async getJsonFile(\n fileName: string,\n repoName?: string,\n branchOrTag?: string,\n ): Promise<any> {\n // TODO #22198\n const raw = await platform.getRawFile(fileName, repoName, branchOrTag);\n return parseJson(raw, fileName);\n },\n\n async initRepo({\n repository,\n cloneSubmodules,\n cloneSubmodulesFilter,\n gitUrl,\n }: RepoParams): Promise<RepoResult> {\n let repo: Repo;\n\n config = {} as any;\n config.repository = repository;\n config.cloneSubmodules = !!cloneSubmodules;\n config.cloneSubmodulesFilter = cloneSubmodulesFilter;\n config.ignorePrAuthor = GlobalConfig.get('ignorePrAuthor');\n\n // Try to fetch information about repository\n try {\n repo = await helper.getRepo(repository);\n } catch (err) {\n logger.debug({ err }, 'Unknown Gitea initRepo error');\n throw err;\n }\n\n // Ensure appropriate repository state and permissions\n if (repo.archived) {\n logger.debug('Repository is archived - aborting renovation');\n throw new Error(REPOSITORY_ARCHIVED);\n }\n if (repo.mirror) {\n logger.debug('Repository is a mirror - aborting renovation');\n throw new Error(REPOSITORY_MIRRORED);\n }\n if (repo.permissions.pull === false || repo.permissions.push === false) {\n logger.debug(\n 'Repository does not permit pull or push - aborting renovation',\n );\n throw new Error(REPOSITORY_ACCESS_FORBIDDEN);\n }\n if (repo.empty) {\n logger.debug('Repository is empty - aborting renovation');\n throw new Error(REPOSITORY_EMPTY);\n }\n\n if (repo.has_pull_requests === false) {\n logger.debug('Repo has disabled pull requests - aborting renovation');\n throw new Error(REPOSITORY_BLOCKED);\n }\n\n // similar to gitea behaviour- if default merge style is allowed, use this;\n // else fall back to predefined order. Order chosen to minimize commits - see\n // https://github.com/renovatebot/renovate/pull/37768 for discussion.\n const preferredOrder: PRMergeMethod[] = [\n repo.default_merge_style,\n 'fast-forward-only',\n 'squash',\n 'merge',\n 'rebase',\n 'rebase-merge',\n ];\n\n const mergeStyle = preferredOrder.find((style) => isAllowed(style, repo));\n\n if (mergeStyle) {\n config.mergeMethod = mergeStyle;\n } else {\n logger.debug(\n 'Repository has no allowed merge methods - aborting renovation',\n );\n throw new Error(REPOSITORY_BLOCKED);\n }\n\n // Determine author email and branches\n config.defaultBranch = repo.default_branch;\n logger.debug(`${repository} default branch = ${config.defaultBranch}`);\n\n const url = getRepoUrl(repo, gitUrl, defaults.endpoint);\n\n // Initialize Git storage\n await git.initRepo({\n ...config,\n url,\n });\n\n // Reset cached resources\n config.issueList = null;\n config.labelList = null;\n config.hasIssuesEnabled = !repo.external_tracker && repo.has_issues;\n\n return {\n defaultBranch: config.defaultBranch,\n isFork: !!repo.fork,\n repoFingerprint: repoFingerprint(repo.id, defaults.endpoint),\n };\n },\n\n async getRepos(config?: AutodiscoverConfig): Promise<string[]> {\n logger.debug('Auto-discovering Gitea repositories');\n try {\n if (config?.topics) {\n logger.debug({ topics: config.topics }, 'Auto-discovering by topics');\n const fetchRepoArgs: FetchRepositoriesArgs[] = config.topics.map(\n (topic) => {\n return {\n topic,\n sort: config.sort,\n order: config.order,\n };\n },\n );\n const repos = await map(fetchRepoArgs, fetchRepositories);\n return deduplicateArray(repos.flat());\n }\n if (config?.namespaces) {\n logger.debug(\n { namespaces: config.namespaces },\n 'Auto-discovering by organization',\n );\n const repos = await map(\n config.namespaces,\n async (organization: string) => {\n const orgRepos = await helper.orgListRepos(organization);\n return orgRepos\n .filter((r) => !r.mirror && !r.archived)\n .map((r) => r.full_name);\n },\n );\n return deduplicateArray(repos.flat());\n }\n return await fetchRepositories({\n sort: config?.sort,\n order: config?.order,\n });\n } catch (err) {\n logger.error({ err }, 'Gitea getRepos() error');\n throw err;\n }\n },\n\n async setBranchStatus({\n branchName,\n context,\n description,\n state,\n url: target_url,\n }: BranchStatusConfig): Promise<void> {\n try {\n // Create new status for branch commit\n const branchCommit = git.getBranchCommit(branchName);\n // TODO: check branchCommit\n\n await helper.createCommitStatus(config.repository, branchCommit!, {\n state: helper.renovateToGiteaStatusMapping[state] || 'pending',\n context,\n description,\n ...(target_url && { target_url }),\n });\n\n // Refresh caches by re-fetching commit status for branch\n await helper.getCombinedCommitStatus(config.repository, branchName, {\n memCache: false,\n });\n } catch (err) {\n logger.warn({ err }, 'Failed to set branch status');\n }\n },\n\n async getBranchStatus(\n branchName: string,\n internalChecksAsSuccess: boolean,\n ): Promise<BranchStatus> {\n let ccs: CombinedCommitStatus;\n try {\n ccs = await helper.getCombinedCommitStatus(config.repository, branchName);\n } catch (err) {\n if (err.statusCode === 404) {\n logger.debug(\n 'Received 404 when checking branch status, assuming branch deletion',\n );\n throw new Error(REPOSITORY_CHANGED);\n }\n\n logger.debug('Unknown error when checking branch status');\n throw err;\n }\n\n logger.debug({ ccs }, 'Branch status check result');\n if (\n !internalChecksAsSuccess &&\n ccs.worstStatus === 'success' &&\n ccs.statuses.every((status) => status.context?.startsWith('renovate/'))\n ) {\n logger.debug(\n 'Successful checks are all internal renovate/ checks, so returning \"pending\" branch status',\n );\n return 'yellow';\n }\n\n /* v8 ignore next -- the mapping covers every status Gitea returns, 'yellow' fallback is defensive */\n return helper.giteaToRenovateStatusMapping[ccs.worstStatus] ?? 'yellow';\n },\n\n async getBranchStatusCheck(\n branchName: string,\n context: string,\n ): Promise<BranchStatus | null> {\n const ccs = await helper.getCombinedCommitStatus(\n config.repository,\n branchName,\n );\n const cs = ccs.statuses.find((s) => s.context === context);\n if (!cs) {\n return null;\n } // no status check exists\n const status = helper.giteaToRenovateStatusMapping[cs.status];\n if (status) {\n return status;\n }\n logger.warn(\n { check: cs },\n 'Could not map Gitea status value to Renovate status',\n );\n return 'yellow';\n },\n\n getPrList(): Promise<Pr[]> {\n return GiteaPrCache.getPrs(\n giteaHttp,\n config.repository,\n config.ignorePrAuthor,\n botUserName,\n );\n },\n\n async getPr(number: number): Promise<Pr | null> {\n // Search for pull request in cached list or attempt to query directly\n const prList = await platform.getPrList();\n let pr = prList.find((p) => p.number === number) ?? null;\n if (pr) {\n logger.debug('Returning from cached PRs');\n } else {\n logger.debug('PR not found in cached PRs - trying to fetch directly');\n const gpr = await helper.getPR(config.repository, number);\n pr = toRenovatePR(gpr, botUserName);\n\n // Add pull request to cache for further lookups / queries\n if (pr) {\n await GiteaPrCache.setPr(\n giteaHttp,\n config.repository,\n config.ignorePrAuthor,\n botUserName,\n pr,\n );\n }\n }\n\n // Abort and return null if no match was found\n if (!pr) {\n return null;\n }\n\n return pr;\n },\n\n async findPr({\n branchName,\n prTitle: title,\n state = 'all',\n includeOtherAuthors,\n targetBranch,\n }: FindPRConfig): Promise<Pr | null> {\n logger.debug(`findPr(${branchName}, ${title!}, ${state})`);\n if (includeOtherAuthors && isString(targetBranch)) {\n // do not use pr cache as it only fetches prs created by the Renovate account\n const pr = await helper.getPRByBranch(\n config.repository,\n targetBranch,\n branchName,\n );\n if (!pr) {\n return null;\n }\n\n return toRenovatePR(pr, null);\n }\n const prList = await platform.getPrList();\n const pr = prList.find(\n (p) =>\n p.sourceRepo === config.repository &&\n p.sourceBranch === branchName &&\n matchesState(p.state, state) &&\n (!title || p.title === title),\n );\n\n if (pr) {\n logger.debug(`Found PR #${pr.number}`);\n }\n return pr ?? null;\n },\n\n async createPr({\n sourceBranch,\n targetBranch,\n prTitle,\n prBody: rawBody,\n labels: labelNames,\n platformPrOptions,\n draftPR,\n }: CreatePRConfig): Promise<Pr> {\n let title = prTitle;\n const base = targetBranch;\n const head = sourceBranch;\n const body = sanitize(rawBody);\n if (draftPR) {\n title = DRAFT_PREFIX + title;\n }\n\n logger.debug(`Creating pull request: ${title} (${head} => ${base})`);\n try {\n const labels = Array.isArray(labelNames)\n ? await map(labelNames, lookupLabelByName)\n : [];\n const gpr = await helper.createPR(config.repository, {\n base,\n head,\n title,\n body,\n labels: labels.filter(isNumber),\n });\n\n if (platformPrOptions?.usePlatformAutomerge) {\n // Only Gitea v1.24.0+ and Forgejo v10.0.0+ support delete_branch_after_merge.\n // This is required to not have undesired behavior when renovate finds existing branches on next run.\n if (\n semver.gte(defaults.version, defaults.isForgejo ? '10.0.0' : '1.24.0')\n ) {\n try {\n await helper.mergePR(config.repository, gpr.number, {\n Do:\n getMergeMethod(platformPrOptions?.automergeStrategy) ??\n config.mergeMethod,\n merge_when_checks_succeed: true,\n delete_branch_after_merge: true,\n });\n\n logger.debug(\n { prNumber: gpr.number },\n 'Gitea-native automerge: success',\n );\n } catch (err) {\n logger.warn(\n { err, prNumber: gpr.number },\n 'Gitea-native automerge: fail',\n );\n }\n } else {\n logger.debug(\n { prNumber: gpr.number },\n `Gitea-native automerge: not supported on this version of ${defaults.isForgejo ? 'Forgejo' : 'Gitea'}. Use ${defaults.isForgejo ? '10.0.0' : '1.24.0'} or newer.`,\n );\n }\n }\n\n const pr = toRenovatePR(gpr, botUserName);\n if (!pr) {\n throw new Error('Can not parse newly created Pull Request');\n }\n\n await GiteaPrCache.setPr(\n giteaHttp,\n config.repository,\n config.ignorePrAuthor,\n botUserName,\n pr,\n );\n return pr;\n } catch (err) {\n // When the user manually deletes a branch from Renovate, the PR remains but is no longer linked to any branch. In\n // the most recent versions of Gitea, the PR gets automatically closed when that happens, but older versions do\n // not handle this properly and keep the PR open. As pushing a branch with the same name resurrects the PR, this\n // would cause a HTTP 409 conflict error, which we hereby gracefully handle.\n if (err.statusCode === 409) {\n logger.warn(\n { prTitle: title, sourceBranch },\n 'Attempting to gracefully recover from 409 Conflict response in createPr()',\n );\n\n // Refresh cached PR list and search for pull request with matching information\n GiteaPrCache.forceSync();\n const pr = await platform.findPr({\n branchName: sourceBranch,\n state: 'open',\n });\n\n // If a valid PR was found, return and gracefully recover from the error. Otherwise, abort and throw error.\n // v8 ignore else -- TODO: add test #40625\n if (pr?.bodyStruct) {\n if (pr.title !== title || pr.bodyStruct.hash !== hashBody(body)) {\n logger.debug(\n `Recovered from 409 Conflict, but PR for ${sourceBranch} is outdated. Updating...`,\n );\n await platform.updatePr({\n number: pr.number,\n prTitle: title,\n prBody: body,\n });\n pr.title = title;\n pr.bodyStruct = getPrBodyStruct(body);\n } else {\n logger.debug(\n `Recovered from 409 Conflict and PR for ${sourceBranch} is up-to-date`,\n );\n }\n\n return pr;\n }\n }\n\n throw err;\n }\n },\n\n async updatePr({\n number,\n prTitle,\n prBody: body,\n labels,\n state,\n targetBranch,\n }: UpdatePrConfig): Promise<void> {\n let title = prTitle;\n if ((await getPrList()).find((pr) => pr.number === number)?.isDraft) {\n title = DRAFT_PREFIX + title;\n }\n\n const prUpdateParams: PRUpdateParams = {\n title,\n ...(body && { body }),\n ...(state && { state }),\n };\n if (targetBranch) {\n prUpdateParams.base = targetBranch;\n }\n\n /**\n * Update PR labels.\n * In the Gitea API, labels are replaced on each update if the field is present.\n * If the field is not present (i.e., undefined), labels aren't updated.\n * However, the labels array must contain label IDs instead of names,\n * so a lookup is performed to fetch the details (including the ID) of each label.\n */\n if (Array.isArray(labels)) {\n prUpdateParams.labels = (await map(labels, lookupLabelByName)).filter(\n isNumber,\n );\n if (labels.length !== prUpdateParams.labels.length) {\n logger.warn(\n 'Some labels could not be looked up. Renovate may halt label updates assuming changes by others.',\n );\n }\n }\n\n const gpr = await helper.updatePR(\n config.repository,\n number,\n prUpdateParams,\n );\n const pr = toRenovatePR(gpr, botUserName);\n if (pr) {\n await GiteaPrCache.setPr(\n giteaHttp,\n config.repository,\n config.ignorePrAuthor,\n botUserName,\n pr,\n );\n }\n },\n\n async mergePr({ id, strategy }: MergePRConfig): Promise<boolean> {\n try {\n await helper.mergePR(config.repository, id, {\n Do: getMergeMethod(strategy) ?? config.mergeMethod,\n });\n return true;\n } catch (err) {\n logger.warn({ err, id }, 'Merging of PR failed');\n return false;\n }\n },\n\n getIssueList(): Promise<Issue[]> {\n if (config.hasIssuesEnabled === false) {\n return Promise.resolve([]);\n }\n config.issueList ??= helper\n .searchIssues(config.repository, { state: 'all' }, { memCache: false })\n .then((issues) => {\n const issueList = issues.map(toRenovateIssue);\n logger.debug(`Retrieved ${issueList.length} Issues`);\n return issueList;\n });\n\n return config.issueList;\n },\n\n async getIssue(number: number, memCache = true): Promise<Issue | null> {\n if (config.hasIssuesEnabled === false) {\n return null;\n }\n try {\n const body = (\n await helper.getIssue(config.repository, number, { memCache })\n ).body;\n return {\n number,\n body,\n };\n } catch (err) /* v8 ignore next -- defensive: issue fetch failures are logged and swallowed, not simulated in specs */ {\n logger.debug({ err, number }, 'Error getting issue');\n return null;\n }\n },\n\n async findIssue(title: string): Promise<Issue | null> {\n const issueList = await platform.getIssueList();\n const issue = issueList.find(\n (i) => i.state === 'open' && i.title === title,\n );\n\n if (!issue) {\n return null;\n }\n // TODO: types (#22198)\n logger.debug(`Found Issue #${issue.number!}`);\n // TODO #22198\n return getIssue!(issue.number!);\n },\n\n async ensureIssue({\n title,\n reuseTitle,\n body: content,\n labels: labelNames,\n shouldReOpen,\n once,\n }: EnsureIssueConfig): Promise<'updated' | 'created' | null> {\n logger.debug(`ensureIssue(${title})`);\n if (config.hasIssuesEnabled === false) {\n logger.info(\n 'Cannot ensure issue because issues are disabled in this repository',\n );\n return null;\n }\n try {\n const body = smartLinks(content);\n\n const issueList = await platform.getIssueList();\n let issues = issueList.filter((i) => i.title === title);\n if (!issues.length) {\n issues = issueList.filter((i) => i.title === reuseTitle);\n }\n\n const labels = Array.isArray(labelNames)\n ? (await Promise.all(labelNames.map(lookupLabelByName))).filter(\n isNumber,\n )\n : undefined;\n\n // Update any matching issues which currently exist\n if (issues.length) {\n let activeIssue = issues.find((i) => i.state === 'open');\n\n // If no active issue was found, decide if it shall be skipped, re-opened or updated without state change\n if (!activeIssue) {\n if (once) {\n logger.debug('Issue already closed - skipping update');\n return null;\n }\n if (shouldReOpen) {\n logger.debug('Reopening previously closed Issue');\n }\n\n // Pick the last issue in the list as the active one\n activeIssue = issues.at(-1)!;\n }\n\n // Close any duplicate issues\n for (const issue of issues) {\n if (issue.state === 'open' && issue.number !== activeIssue.number) {\n // TODO: types (#22198)\n logger.warn({ issueNo: issue.number! }, 'Closing duplicate issue');\n // TODO #22198\n await helper.closeIssue(config.repository, issue.number!);\n }\n }\n\n // Check if issue has already correct state\n if (\n activeIssue.title === title &&\n activeIssue.body === body &&\n activeIssue.state === 'open'\n ) {\n logger.debug(\n // TODO: types (#22198)\n `Issue #${activeIssue.number!} is open and up to date - nothing to do`,\n );\n return null;\n }\n\n if (shouldReOpen || activeIssue.state === 'open') {\n // Update issue body and re-open\n logger.debug(`Updating Issue #${activeIssue.number}`);\n const existingIssue = await helper.updateIssue(\n config.repository,\n // TODO #22198\n activeIssue.number!,\n {\n body,\n title,\n state: 'open',\n },\n );\n\n // Test whether the issues need to be updated\n const existingLabelIds = coerceArray(existingIssue.labels).map(\n (label) => label.id,\n );\n if (\n labels &&\n (labels.length !== existingLabelIds.length ||\n labels.filter((labelId) => !existingLabelIds.includes(labelId))\n .length !== 0)\n ) {\n await helper.updateIssueLabels(\n config.repository,\n // TODO #22198\n activeIssue.number!,\n {\n labels,\n },\n );\n }\n\n return 'updated';\n }\n }\n\n // Create new issue and reset cache\n const issue = await helper.createIssue(config.repository, {\n body,\n title,\n labels,\n });\n logger.debug(`Created new Issue #${issue.number}`);\n config.issueList = null;\n\n return 'created';\n } catch (err) {\n logger.warn({ err }, 'Could not ensure issue');\n }\n\n return null;\n },\n\n async ensureIssueClosing(title: string): Promise<void> {\n logger.debug(`ensureIssueClosing(${title})`);\n if (config.hasIssuesEnabled === false) {\n return;\n }\n const issueList = await platform.getIssueList();\n for (const issue of issueList) {\n if (issue.state === 'open' && issue.title === title) {\n logger.debug(`Closing issue...issueNo: ${issue.number!}`);\n // TODO #22198\n await helper.closeIssue(config.repository, issue.number!);\n }\n }\n },\n\n async deleteLabel(issue: number, labelName: string): Promise<void> {\n logger.debug(`Deleting label ${labelName} from Issue #${issue}`);\n const label = await lookupLabelByName(labelName);\n if (label) {\n await helper.unassignLabel(config.repository, issue, label);\n } else {\n logger.warn({ issue, labelName }, 'Failed to lookup label for deletion');\n }\n },\n\n async ensureComment({\n number: issue,\n topic,\n content,\n }: EnsureCommentConfig): Promise<boolean> {\n try {\n let body = sanitize(content);\n const commentList = await helper.getComments(config.repository, issue);\n\n // Search comment by either topic or exact body\n let comment: Comment | null = null;\n if (topic) {\n comment = findCommentByTopic(commentList, topic);\n body = `### ${topic}\\n\\n${body}`;\n } else {\n comment = findCommentByContent(commentList, body);\n }\n\n // Create a new comment if no match has been found, otherwise update if necessary\n if (!comment) {\n comment = await helper.createComment(config.repository, issue, body);\n logger.info(\n { repository: config.repository, issue, comment: comment.id },\n 'Comment added',\n );\n } else if (comment.body === body) {\n logger.debug(`Comment #${comment.id} is already up-to-date`);\n } else {\n await helper.updateComment(config.repository, comment.id, body);\n logger.debug(\n { repository: config.repository, issue, comment: comment.id },\n 'Comment updated',\n );\n }\n\n return true;\n } catch (err) {\n logger.warn({ err, issue, subject: topic }, 'Error ensuring comment');\n return false;\n }\n },\n\n async ensureCommentRemoval(\n deleteConfig: EnsureCommentRemovalConfig,\n ): Promise<void> {\n const { number: issue } = deleteConfig;\n const key =\n deleteConfig.type === 'by-topic'\n ? deleteConfig.topic\n : deleteConfig.content;\n logger.debug(`Ensuring comment \"${key}\" in #${issue} is removed`);\n const commentList = await helper.getComments(config.repository, issue);\n\n let comment: Comment | null = null;\n // v8 ignore else -- TODO: add test #40625\n if (deleteConfig.type === 'by-topic') {\n comment = findCommentByTopic(commentList, deleteConfig.topic);\n } else if (deleteConfig.type === 'by-content') {\n const body = sanitize(deleteConfig.content);\n comment = findCommentByContent(commentList, body);\n }\n\n // Abort and do nothing if no matching comment was found\n if (!comment) {\n return;\n }\n\n // Try to delete comment\n try {\n await helper.deleteComment(config.repository, comment.id);\n } catch (err) {\n logger.warn(\n { err, issue, config: deleteConfig },\n 'Error deleting comment',\n );\n }\n },\n\n async getBranchPr(branchName: string): Promise<Pr | null> {\n logger.debug(`getBranchPr(${branchName})`);\n const pr = await platform.findPr({ branchName, state: 'open' });\n return pr ? platform.getPr(pr.number) : null;\n },\n\n async addAssignees(number: number, assignees: string[]): Promise<void> {\n logger.debug(\n `Updating assignees '${assignees?.join(', ')}' on Issue #${number}`,\n );\n await helper.updateIssue(config.repository, number, {\n assignees,\n });\n },\n\n async addReviewers(number: number, reviewers: string[]): Promise<void> {\n logger.debug(`Adding reviewers '${reviewers?.join(', ')}' to #${number}`);\n if (semver.lt(defaults.version, '1.14.0')) {\n logger.debug(\n { version: defaults.version },\n 'Adding reviewer not yet supported.',\n );\n return;\n }\n try {\n await helper.requestPrReviewers(config.repository, number, { reviewers });\n } catch (err) {\n logger.warn({ err, number, reviewers }, 'Failed to assign reviewer');\n }\n },\n\n massageMarkdown(prBody: string): string {\n return smartTruncate(smartLinks(prBody), maxBodyLength());\n },\n\n maxBodyLength,\n};\n\nexport function maxBodyLength(): number {\n return 1000000;\n}\n\n/* oxlint-disable typescript/unbound-method */\nexport const {\n addAssignees,\n addReviewers,\n createPr,\n deleteLabel,\n ensureComment,\n ensureCommentRemoval,\n ensureIssue,\n ensureIssueClosing,\n findIssue,\n findPr,\n getBranchPr,\n getBranchStatus,\n getBranchStatusCheck,\n getIssue,\n getRawFile,\n getJsonFile,\n getIssueList,\n getPr,\n massageMarkdown,\n getPrList,\n getRepos,\n initPlatform,\n initRepo,\n mergePr,\n setBranchStatus,\n updatePr,\n} = platform;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,MAAa,KAAK;AAElB,MAAM,WAAW;CACf,UAAU;CACV,UAAU;CACV,SAAS;CACT,WAAW;AACb;AAEA,IAAI,SAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI;AAEJ,SAAgB,gBAAsB;CACpC,SAAS,CAAC;CACV,YAAY,KAAA;CACZ,cAAc,KAAA;CACd,SAAS,WAAW;CACpB,SAAS,WAAW;CACpB,SAAS,UAAU;CACnB,SAAS,YAAY;CACrB,WAAW,SAAS,QAAQ;AAC9B;AAEA,SAAS,gBAAgB,MAAoB;CAC3C,OAAO;EACL,QAAQ,KAAK;EACb,OAAO,KAAK;EACZ,OAAO,KAAK;EACZ,MAAM,KAAK;CACb;AACF;AAEA,SAAS,aAAa,QAAgB,UAA2B;CAC/D,IAAI,aAAa,OACf,OAAO;CAET,IAAI,SAAS,WAAW,GAAG,GACzB,OAAO,WAAW,SAAS,UAAU,CAAC;CAGxC,OAAO,WAAW;AACpB;AAEA,SAAS,mBACP,UACA,OACgB;CAChB,OAAO,SAAS,MAAM,MAAM,EAAE,KAAK,WAAW,OAAO,MAAM,KAAK,CAAC,KAAK;AACxE;AAEA,SAAS,qBACP,UACA,SACgB;CAChB,OAAO,SAAS,MAAM,MAAM,EAAE,KAAK,KAAK,MAAM,OAAO,KAAK;AAC5D;AAEA,SAAS,eAAiC;CACxC,IAAI,OAAO,cAAc,MAAM;EAC7B,MAAM,aAAaA,cACF,OAAO,YAAY,EAChC,UAAU,MACZ,CAAC,CAAC,CACD,MAAM,WAAW;GAChB,OAAO,MAAM,aAAa,OAAO,OAAO,aAAa;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AC;CACH;CAEA,MAAM,aAAa,QAAgB,WAAoC;EACrE,OAAO,MAAM,qBAAqB,WAAW,KAAK,IAAI,EAAE,QAAQ,QAAQ;EACxE,IAAI,OAAO,GAAG,SAAS,SAAS,QAAQ,GAAG;GACzC,OAAO,MACL,EAAE,SAAS,SAAS,QAAQ,GAC5B,oCACF;GACA;EACF;EACA,IAAI;GACF,MAAMQ,mBAA0B,OAAO,YAAY,QAAQ,EAAE,UAAU,CAAC;EAC1E,SAAS,KAAK;GACZ,OAAO,KAAK;IAAE;IAAK;IAAQ;GAAU,GAAG,2BAA2B;EACrE;CACF;CAEA,gBAAgB,QAAwB;EACtC,OAAO,cAAc,WAAW,MAAM,GAAG,cAAc,CAAC;CAC1D;CAEA;AACF;AAEA,SAAgB,gBAAwB;CACtC,OAAO;AACT;AAGA,MAAa,EACX,cACA,cACA,UACA,aACA,eACA,sBACA,aACA,oBACA,WACA,QACA,aACA,iBACA,sBACA,UACA,YACA,aACA,cACA,OACA,iBACA,WACA,UACA,cACA,UACA,SACA,iBACA,aACE"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["helper.searchIssues","helper.searchRepos","helper.getCurrentUser","helper.getVersion","helper.getRepoContents","helper.getRepo","helper.isOrg","git.initRepo","helper.orgListRepos","git.getBranchCommit","helper.createCommitStatus","helper.toPlatformStatusMapping","helper.getCombinedCommitStatus","helper.toRenovateStatusMapping","helper.getPR","helper.getPRByBranch","helper.createPR","helper.mergePR","helper.updatePR","helper.getIssue","helper.closeIssue","helper.updateIssue","helper.updateIssueLabels","helper.createIssue","helper.unassignLabel","helper.getComments","helper.createComment","helper.updateComment","helper.deleteComment","helper.requestPrReviewers"],"sources":["../../../../lib/modules/platform/gitea/index.ts"],"sourcesContent":["import { isNumber, isString } from '@sindresorhus/is';\nimport semver from 'semver';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport {\n REPOSITORY_ACCESS_FORBIDDEN,\n REPOSITORY_ARCHIVED,\n REPOSITORY_BLOCKED,\n REPOSITORY_CHANGED,\n REPOSITORY_EMPTY,\n REPOSITORY_MIRRORED,\n} from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport type { BranchStatus } from '../../../types/index.ts';\nimport { coerceArray, deduplicateArray } from '../../../util/array.ts';\nimport { parseJson } from '../../../util/common.ts';\nimport { getEnv } from '../../../util/env.ts';\nimport * as git from '../../../util/git/index.ts';\nimport { GiteaHttp, setBaseUrl } from '../../../util/http/gitea.ts';\nimport { map } from '../../../util/promises.ts';\nimport { sanitize } from '../../../util/sanitize.ts';\nimport { ensureTrailingSlash } from '../../../util/url.ts';\nimport { getPrBodyStruct, hashBody } from '../pr-body.ts';\nimport type {\n AutodiscoverConfig,\n BranchStatusConfig,\n CreatePRConfig,\n EnsureCommentConfig,\n EnsureCommentRemovalConfig,\n EnsureIssueConfig,\n FindPRConfig,\n Issue,\n MergePRConfig,\n Platform,\n PlatformParams,\n PlatformResult,\n Pr,\n RepoParams,\n RepoResult,\n RepoSortMethod,\n SortMethod,\n UpdatePrConfig,\n} from '../types.ts';\nimport { repoFingerprint } from '../util.ts';\nimport { smartTruncate } from '../utils/pr-body.ts';\nimport * as helper from './gitea-helper.ts';\nimport { lookupLabelByName } from './labels.ts';\nimport { GiteaPrCache } from './pr-cache.ts';\nimport type { Comment, Label, PRMergeMethod, Repo } from './schema.ts';\nimport type {\n CombinedCommitStatus,\n GiteaPlatform,\n GiteaPlatformOptions,\n PRUpdateParams,\n} from './types.ts';\nimport {\n DRAFT_PREFIX,\n getMergeMethod,\n getRepoUrl,\n isAllowed,\n platformDisplayName,\n smartLinks,\n toRenovatePR,\n trimTrailingApiPath,\n usableRepo,\n} from './utils.ts';\n\ninterface GiteaRepoConfig {\n ignorePrAuthor: boolean;\n repository: string;\n mergeMethod: PRMergeMethod;\n\n issueList: Promise<Issue[]> | null;\n labelList: Promise<Label[]> | null;\n defaultBranch: string;\n cloneSubmodules: boolean;\n cloneSubmodulesFilter: string[] | undefined;\n hasIssuesEnabled: boolean;\n isOrgRepo: boolean;\n orgName: string;\n}\n\nexport const id = 'gitea';\n\nexport const giteaHttp = new GiteaHttp();\n\nfunction toRenovateIssue(data: Issue): Issue {\n return {\n number: data.number,\n state: data.state,\n title: data.title,\n body: data.body,\n };\n}\n\nfunction matchesState(actual: string, expected: string): boolean {\n if (expected === 'all') {\n return true;\n }\n if (expected.startsWith('!')) {\n return actual !== expected.substring(1);\n }\n\n return actual === expected;\n}\n\nfunction findCommentByTopic(\n comments: Comment[],\n topic: string,\n): Comment | null {\n return comments.find((c) => c.body.startsWith(`### ${topic}\\n\\n`)) ?? null;\n}\n\nfunction findCommentByContent(\n comments: Comment[],\n content: string,\n): Comment | null {\n return comments.find((c) => c.body.trim() === content) ?? null;\n}\n\ninterface FetchRepositoriesArgs {\n topic?: string;\n sort?: RepoSortMethod;\n order?: SortMethod;\n}\n\n/**\n * Builds the platform implementation shared by every platform which speaks the\n * Gitea API. Each call owns its own module state, so `gitea` and `forgejo` do\n * not share caches or configuration.\n */\nexport function createPlatform(options: GiteaPlatformOptions): GiteaPlatform {\n const {\n id,\n http,\n setBaseUrl,\n logDetectedVersion,\n checkNativeAutomerge,\n minReviewerVersion,\n } = options;\n const name = platformDisplayName[id];\n\n const defaults = {\n endpoint: options.defaultEndpoint,\n version: '0.0.0',\n };\n\n let config: GiteaRepoConfig = {} as any;\n let botUserID: number;\n let botUserName: string;\n const prCache = new GiteaPrCache(http, id);\n\n function resetPlatform(): void {\n config = {} as any;\n prCache.reset();\n botUserID = undefined as never;\n botUserName = undefined as never;\n defaults.endpoint = options.defaultEndpoint;\n defaults.version = '0.0.0';\n setBaseUrl(defaults.endpoint);\n }\n\n async function fetchIssueList(): Promise<Issue[]> {\n const issues = await helper.searchIssues(\n http,\n config.repository,\n { state: 'all' },\n { memCache: false },\n );\n const issueList = issues.map(toRenovateIssue);\n logger.debug(`Retrieved ${issueList.length} Issues`);\n return issueList;\n }\n\n async function fetchRepositories({\n topic,\n sort,\n order,\n }: FetchRepositoriesArgs): Promise<string[]> {\n const repos = await helper.searchRepos(http, {\n uid: botUserID,\n archived: false,\n ...(topic && {\n topic: true,\n q: topic,\n }),\n ...(sort && {\n sort,\n }),\n ...(order && {\n order,\n }),\n });\n return repos.filter(usableRepo).map((r) => r.full_name);\n }\n\n const platform: Platform = {\n async initPlatform({\n endpoint,\n token,\n }: PlatformParams): Promise<PlatformResult> {\n if (!token) {\n throw new Error(\n `Init: You must configure a ${name} personal access token`,\n );\n }\n\n if (endpoint) {\n let baseEndpoint = trimTrailingApiPath(endpoint);\n baseEndpoint = ensureTrailingSlash(baseEndpoint);\n defaults.endpoint = baseEndpoint;\n } else {\n logger.debug(`Using default ${name} endpoint: ${defaults.endpoint}`);\n }\n setBaseUrl(defaults.endpoint);\n\n let gitAuthor: string;\n try {\n const user = await helper.getCurrentUser(http, { token });\n // oxlint-disable-next-line typescript/prefer-nullish-coalescing -- `full_name` can be emtpy string\n gitAuthor = `${user.full_name || user.login} <${user.email}>`;\n botUserID = user.id;\n botUserName = user.login;\n const env = getEnv();\n /* v8 ignore if: experimental feature */\n if (semver.valid(env.RENOVATE_X_PLATFORM_VERSION)) {\n defaults.version = env.RENOVATE_X_PLATFORM_VERSION!;\n } else {\n defaults.version = await helper.getVersion(http, { token });\n }\n\n logDetectedVersion(defaults.version);\n } catch (err) {\n logger.debug(\n { err },\n `Error authenticating with ${name}. Check your token`,\n );\n throw new Error('Init: Authentication failure');\n }\n\n return {\n endpoint: defaults.endpoint,\n gitAuthor,\n };\n },\n\n async getRawFile(\n fileName: string,\n repoName?: string,\n branchOrTag?: string,\n ): Promise<string | null> {\n const repo = repoName ?? config.repository;\n const contents = await helper.getRepoContents(\n http,\n repo,\n fileName,\n branchOrTag,\n );\n if (contents.type !== 'file') {\n return null;\n }\n return contents.contentString;\n },\n\n async getJsonFile(\n fileName: string,\n repoName?: string,\n branchOrTag?: string,\n ): Promise<any> {\n // TODO #22198\n const raw = await platform.getRawFile(fileName, repoName, branchOrTag);\n return parseJson(raw, fileName);\n },\n\n async initRepo({\n repository,\n cloneSubmodules,\n cloneSubmodulesFilter,\n gitUrl,\n }: RepoParams): Promise<RepoResult> {\n let repo: Repo;\n\n config = {} as any;\n config.repository = repository;\n config.cloneSubmodules = !!cloneSubmodules;\n config.cloneSubmodulesFilter = cloneSubmodulesFilter;\n config.ignorePrAuthor = GlobalConfig.get('ignorePrAuthor');\n\n // Try to fetch information about repository\n try {\n repo = await helper.getRepo(http, repository);\n } catch (err) {\n logger.debug({ err }, `Unknown ${name} initRepo error`);\n throw err;\n }\n\n // Ensure appropriate repository state and permissions\n if (repo.archived) {\n logger.debug('Repository is archived - aborting renovation');\n throw new Error(REPOSITORY_ARCHIVED);\n }\n if (repo.mirror) {\n logger.debug('Repository is a mirror - aborting renovation');\n throw new Error(REPOSITORY_MIRRORED);\n }\n if (!repo.permissions.pull || !repo.permissions.push) {\n logger.debug(\n 'Repository does not permit pull or push - aborting renovation',\n );\n throw new Error(REPOSITORY_ACCESS_FORBIDDEN);\n }\n if (repo.empty) {\n logger.debug('Repository is empty - aborting renovation');\n throw new Error(REPOSITORY_EMPTY);\n }\n\n if (repo.has_pull_requests === false) {\n logger.debug('Repo has disabled pull requests - aborting renovation');\n throw new Error(REPOSITORY_BLOCKED);\n }\n\n // if default merge style is allowed, use this; else fall back to\n // predefined order. Order chosen to minimize commits - see\n // https://github.com/renovatebot/renovate/pull/37768 for discussion.\n const preferredOrder: PRMergeMethod[] = [\n ...(repo.default_merge_style ? [repo.default_merge_style] : []),\n 'fast-forward-only',\n 'squash',\n 'merge',\n 'rebase',\n 'rebase-merge',\n ];\n\n const mergeStyle = preferredOrder.find((style) => isAllowed(style, repo));\n\n if (mergeStyle) {\n config.mergeMethod = mergeStyle;\n } else {\n logger.debug(\n 'Repository has no allowed merge methods - aborting renovation',\n );\n throw new Error(REPOSITORY_BLOCKED);\n }\n\n try {\n config.isOrgRepo = await helper.isOrg(http, id, repo.owner.login);\n } catch (err) {\n logger.debug({ err }, `${name} initRepo() error`);\n throw err;\n }\n\n // Determine author email and branches\n config.defaultBranch = repo.default_branch;\n logger.debug(`${repository} default branch = ${config.defaultBranch}`);\n\n const url = getRepoUrl(repo, gitUrl, defaults.endpoint, id);\n\n // Initialize Git storage\n await git.initRepo({\n ...config,\n url,\n });\n\n // Reset cached resources\n config.issueList = null;\n config.labelList = null;\n prCache.initRepo(config.repository, config.ignorePrAuthor, botUserName);\n config.hasIssuesEnabled = !repo.external_tracker && repo.has_issues;\n config.orgName = repo.owner.login;\n\n return {\n defaultBranch: config.defaultBranch,\n isFork: !!repo.fork,\n repoFingerprint: repoFingerprint(repo.id, defaults.endpoint),\n };\n },\n\n async getRepos(config?: AutodiscoverConfig): Promise<string[]> {\n logger.debug(`Auto-discovering ${name} repositories`);\n try {\n if (config?.topics) {\n logger.debug({ topics: config.topics }, 'Auto-discovering by topics');\n const fetchRepoArgs: FetchRepositoriesArgs[] = config.topics.map(\n (topic) => {\n return {\n topic,\n sort: config.sort,\n order: config.order,\n };\n },\n );\n const repos = await map(fetchRepoArgs, fetchRepositories);\n return deduplicateArray(repos.flat());\n }\n if (config?.namespaces) {\n logger.debug(\n { namespaces: config.namespaces },\n 'Auto-discovering by organization',\n );\n const repos = await map(\n config.namespaces,\n async (organization: string) => {\n const orgRepos = await helper.orgListRepos(http, organization);\n return orgRepos\n .filter((r) => !r.mirror && !r.archived)\n .map((r) => r.full_name);\n },\n );\n return deduplicateArray(repos.flat());\n }\n return await fetchRepositories({\n sort: config?.sort,\n order: config?.order,\n });\n } catch (err) {\n logger.error(\n { err, platform: id },\n 'Error auto-discovering repositories',\n );\n throw err;\n }\n },\n\n async setBranchStatus({\n branchName,\n context,\n description,\n state,\n url: target_url,\n }: BranchStatusConfig): Promise<void> {\n try {\n // Create new status for branch commit\n const branchCommit = git.getBranchCommit(branchName);\n // TODO: check branchCommit\n\n await helper.createCommitStatus(\n http,\n config.repository,\n branchCommit!,\n {\n state: helper.toPlatformStatusMapping[state] || 'pending',\n context,\n description,\n ...(target_url && { target_url }),\n },\n );\n\n // Refresh caches by re-fetching commit status for branch\n await helper.getCombinedCommitStatus(\n http,\n config.repository,\n branchName,\n {\n memCache: false,\n },\n );\n } catch (err) {\n logger.warn({ err }, 'Failed to set branch status');\n }\n },\n\n async getBranchStatus(\n branchName: string,\n internalChecksAsSuccess: boolean,\n ): Promise<BranchStatus> {\n let ccs: CombinedCommitStatus;\n try {\n ccs = await helper.getCombinedCommitStatus(\n http,\n config.repository,\n branchName,\n );\n } catch (err) {\n if (err.statusCode === 404) {\n logger.debug(\n 'Received 404 when checking branch status, assuming branch deletion',\n );\n throw new Error(REPOSITORY_CHANGED);\n }\n\n logger.debug('Unknown error when checking branch status');\n throw err;\n }\n\n logger.debug({ ccs }, 'Branch status check result');\n if (\n !internalChecksAsSuccess &&\n ccs.worstStatus === 'success' &&\n ccs.statuses.every((status) => status.context?.startsWith('renovate/'))\n ) {\n logger.debug(\n 'Successful checks are all internal renovate/ checks, so returning \"pending\" branch status',\n );\n return 'yellow';\n }\n\n return helper.toRenovateStatusMapping[ccs.worstStatus];\n },\n\n async getBranchStatusCheck(\n branchName: string,\n context: string,\n ): Promise<BranchStatus | null> {\n const ccs = await helper.getCombinedCommitStatus(\n http,\n config.repository,\n branchName,\n );\n const cs = ccs.statuses.find((s) => s.context === context);\n if (!cs) {\n return null;\n } // no status check exists\n return helper.toRenovateStatusMapping[cs.status];\n },\n\n getPrList(): Promise<Pr[]> {\n return prCache.getPrs();\n },\n\n async getPr(number: number): Promise<Pr | null> {\n // Search for pull request in cached list or attempt to query directly\n const prList = await platform.getPrList();\n let pr = prList.find((p) => p.number === number) ?? null;\n if (pr) {\n logger.debug('Returning from cached PRs');\n } else {\n logger.debug('PR not found in cached PRs - trying to fetch directly');\n const gpr = await helper.getPR(http, config.repository, number);\n pr = toRenovatePR(gpr, botUserName);\n\n // Add pull request to cache for further lookups / queries\n if (pr) {\n await prCache.setPr(pr);\n }\n }\n\n // Abort and return null if no match was found\n if (!pr) {\n return null;\n }\n\n return pr;\n },\n\n async findPr({\n branchName,\n prTitle: title,\n state = 'all',\n includeOtherAuthors,\n targetBranch,\n }: FindPRConfig): Promise<Pr | null> {\n logger.debug(`findPr(${branchName}, ${title!}, ${state})`);\n if (includeOtherAuthors && isString(targetBranch)) {\n // do not use pr cache as it only fetches prs created by the Renovate account\n const pr = await helper.getPRByBranch(\n http,\n config.repository,\n targetBranch,\n branchName,\n );\n if (!pr) {\n return null;\n }\n\n return toRenovatePR(pr, null);\n }\n const prList = await platform.getPrList();\n const pr = prList.find(\n (p) =>\n p.sourceRepo === config.repository &&\n p.sourceBranch === branchName &&\n matchesState(p.state, state) &&\n (!title || p.title === title),\n );\n\n if (pr) {\n logger.debug(`Found PR #${pr.number}`);\n }\n return pr ?? null;\n },\n\n async createPr({\n sourceBranch,\n targetBranch,\n prTitle,\n prBody: rawBody,\n labels: labelNames,\n platformPrOptions,\n draftPR,\n }: CreatePRConfig): Promise<Pr> {\n let title = prTitle;\n const base = targetBranch;\n const head = sourceBranch;\n const body = sanitize(rawBody);\n if (draftPR) {\n title = DRAFT_PREFIX + title;\n }\n\n logger.debug(`Creating pull request: ${title} (${head} => ${base})`);\n try {\n const labels = Array.isArray(labelNames)\n ? await map(labelNames, (name) =>\n lookupLabelByName(http, config, name),\n )\n : [];\n const gpr = await helper.createPR(http, config.repository, {\n base,\n head,\n title,\n body,\n labels: labels.filter(isNumber),\n });\n\n if (platformPrOptions?.usePlatformAutomerge) {\n // `delete_branch_after_merge` is required to not have undesired\n // behavior when renovate finds existing branches on next run.\n const unsupportedReason = checkNativeAutomerge(defaults.version);\n if (unsupportedReason === null) {\n try {\n await helper.mergePR(http, config.repository, gpr.number, {\n Do:\n getMergeMethod(platformPrOptions?.automergeStrategy) ??\n config.mergeMethod,\n merge_when_checks_succeed: true,\n delete_branch_after_merge: true,\n });\n\n logger.debug(\n { prNumber: gpr.number },\n `${name}-native automerge: success`,\n );\n } catch (err) {\n logger.warn(\n { err, prNumber: gpr.number, platform: id },\n 'Platform-native automerge: fail',\n );\n }\n } else {\n logger.debug({ prNumber: gpr.number }, unsupportedReason);\n }\n }\n\n const pr = toRenovatePR(gpr, botUserName);\n if (!pr) {\n throw new Error('Can not parse newly created Pull Request');\n }\n\n await prCache.setPr(pr);\n return pr;\n } catch (err) {\n // When the user manually deletes a branch from Renovate, the PR remains but is no longer linked to any branch. In\n // the most recent versions of the platform, the PR gets automatically closed when that happens, but older versions\n // do not handle this properly and keep the PR open. As pushing a branch with the same name resurrects the PR, this\n // would cause a HTTP 409 conflict error, which we hereby gracefully handle.\n if (err.statusCode === 409) {\n logger.warn(\n { prTitle: title, sourceBranch },\n 'Attempting to gracefully recover from 409 Conflict response in createPr()',\n );\n\n // Refresh cached PR list and search for pull request with matching information\n prCache.forceSync();\n const pr = await platform.findPr({\n branchName: sourceBranch,\n state: 'open',\n });\n\n // If a valid PR was found, return and gracefully recover from the error. Otherwise, abort and throw error.\n // v8 ignore else -- TODO: add test #40625\n if (pr?.bodyStruct) {\n if (pr.title !== title || pr.bodyStruct.hash !== hashBody(body)) {\n logger.debug(\n `Recovered from 409 Conflict, but PR for ${sourceBranch} is outdated. Updating...`,\n );\n await platform.updatePr({\n number: pr.number,\n prTitle: title,\n prBody: body,\n });\n pr.title = title;\n pr.bodyStruct = getPrBodyStruct(body);\n } else {\n logger.debug(\n `Recovered from 409 Conflict and PR for ${sourceBranch} is up-to-date`,\n );\n }\n\n return pr;\n }\n }\n\n throw err;\n }\n },\n\n async updatePr({\n number,\n prTitle,\n prBody: body,\n labels,\n state,\n targetBranch,\n }: UpdatePrConfig): Promise<void> {\n let title = prTitle;\n if (\n (await platform.getPrList()).find((pr) => pr.number === number)?.isDraft\n ) {\n title = DRAFT_PREFIX + title;\n }\n\n const prUpdateParams: PRUpdateParams = {\n title,\n ...(body && { body }),\n ...(state && { state }),\n };\n if (targetBranch) {\n prUpdateParams.base = targetBranch;\n }\n\n /**\n * Update PR labels.\n * In the Gitea API, labels are replaced on each update if the field is present.\n * If the field is not present (i.e., undefined), labels aren't updated.\n * However, the labels array must contain label IDs instead of names,\n * so a lookup is performed to fetch the details (including the ID) of each label.\n */\n if (Array.isArray(labels)) {\n prUpdateParams.labels = (\n await map(labels, (name) => lookupLabelByName(http, config, name))\n ).filter(isNumber);\n if (labels.length !== prUpdateParams.labels.length) {\n logger.warn(\n 'Some labels could not be looked up. Renovate may halt label updates assuming changes by others.',\n );\n }\n }\n\n const gpr = await helper.updatePR(\n http,\n config.repository,\n number,\n prUpdateParams,\n );\n const pr = toRenovatePR(gpr, botUserName);\n if (pr) {\n await prCache.setPr(pr);\n }\n },\n\n async mergePr({ id: prNumber, strategy }: MergePRConfig): Promise<boolean> {\n try {\n await helper.mergePR(http, config.repository, prNumber, {\n Do: getMergeMethod(strategy) ?? config.mergeMethod,\n });\n return true;\n } catch (err) {\n logger.warn({ err, id: prNumber }, 'Merging of PR failed');\n return false;\n }\n },\n\n getIssueList(): Promise<Issue[]> {\n if (config.hasIssuesEnabled === false) {\n return Promise.resolve([]);\n }\n config.issueList ??= fetchIssueList();\n\n return config.issueList;\n },\n\n async getIssue(number: number, memCache = true): Promise<Issue | null> {\n if (config.hasIssuesEnabled === false) {\n return null;\n }\n try {\n const body = (\n await helper.getIssue(http, config.repository, number, { memCache })\n ).body;\n return {\n number,\n body,\n };\n } catch (err) {\n logger.debug({ err, number }, 'Error getting issue');\n return null;\n }\n },\n\n async findIssue(title: string): Promise<Issue | null> {\n const issueList = await platform.getIssueList();\n const issue = issueList.find(\n (i) => i.state === 'open' && i.title === title,\n );\n\n if (!issue) {\n return null;\n }\n // TODO: types (#22198)\n logger.debug(`Found Issue #${issue.number!}`);\n // TODO #22198\n return platform.getIssue!(issue.number!);\n },\n\n async ensureIssue({\n title,\n reuseTitle,\n body: content,\n labels: labelNames,\n shouldReOpen,\n once,\n }: EnsureIssueConfig): Promise<'updated' | 'created' | null> {\n logger.debug(`ensureIssue(${title})`);\n if (config.hasIssuesEnabled === false) {\n logger.info(\n 'Cannot ensure issue because issues are disabled in this repository',\n );\n return null;\n }\n try {\n const body = smartLinks(content);\n\n const issueList = await platform.getIssueList();\n let issues = issueList.filter((i) => i.title === title);\n if (!issues.length) {\n issues = issueList.filter((i) => i.title === reuseTitle);\n }\n\n const labels = Array.isArray(labelNames)\n ? (\n await Promise.all(\n labelNames.map((name) => lookupLabelByName(http, config, name)),\n )\n ).filter(isNumber)\n : undefined;\n\n // Update any matching issues which currently exist\n if (issues.length) {\n let activeIssue = issues.find((i) => i.state === 'open');\n\n // If no active issue was found, decide if it shall be skipped, re-opened or updated without state change\n if (!activeIssue) {\n if (once) {\n logger.debug('Issue already closed - skipping update');\n return null;\n }\n if (shouldReOpen) {\n logger.debug('Reopening previously closed Issue');\n }\n\n // Pick the last issue in the list as the active one\n activeIssue = issues.at(-1)!;\n }\n\n // Close any duplicate issues\n for (const issue of issues) {\n if (issue.state === 'open' && issue.number !== activeIssue.number) {\n // TODO: types (#22198)\n logger.warn(\n { issueNo: issue.number! },\n 'Closing duplicate issue',\n );\n // TODO #22198\n await helper.closeIssue(http, config.repository, issue.number!);\n }\n }\n\n // Check if issue has already correct state\n if (\n activeIssue.title === title &&\n activeIssue.body === body &&\n activeIssue.state === 'open'\n ) {\n logger.debug(\n // TODO: types (#22198)\n `Issue #${activeIssue.number!} is open and up to date - nothing to do`,\n );\n return null;\n }\n\n if (shouldReOpen || activeIssue.state === 'open') {\n // Update issue body and re-open\n logger.debug(`Updating Issue #${activeIssue.number}`);\n const existingIssue = await helper.updateIssue(\n http,\n config.repository,\n // TODO #22198\n activeIssue.number!,\n {\n body,\n title,\n state: 'open',\n },\n );\n\n // Test whether the issues need to be updated\n const existingLabelIds = coerceArray(existingIssue.labels).map(\n (label) => label.id,\n );\n if (\n labels &&\n (labels.length !== existingLabelIds.length ||\n labels.filter((labelId) => !existingLabelIds.includes(labelId))\n .length !== 0)\n ) {\n await helper.updateIssueLabels(\n http,\n config.repository,\n // TODO #22198\n activeIssue.number!,\n {\n labels,\n },\n );\n }\n\n return 'updated';\n }\n }\n\n // Create new issue and reset cache\n const issue = await helper.createIssue(http, config.repository, {\n body,\n title,\n labels,\n });\n logger.debug(`Created new Issue #${issue.number}`);\n config.issueList = null;\n\n return 'created';\n } catch (err) {\n logger.warn({ err }, 'Could not ensure issue');\n }\n\n return null;\n },\n\n async ensureIssueClosing(title: string): Promise<void> {\n logger.debug(`ensureIssueClosing(${title})`);\n if (config.hasIssuesEnabled === false) {\n return;\n }\n const issueList = await platform.getIssueList();\n for (const issue of issueList) {\n if (issue.state === 'open' && issue.title === title) {\n logger.debug(`Closing issue...issueNo: ${issue.number!}`);\n // TODO #22198\n await helper.closeIssue(http, config.repository, issue.number!);\n }\n }\n },\n\n async deleteLabel(issue: number, labelName: string): Promise<void> {\n logger.debug(`Deleting label ${labelName} from Issue #${issue}`);\n const label = await lookupLabelByName(http, config, labelName);\n if (label) {\n await helper.unassignLabel(http, config.repository, issue, label);\n } else {\n logger.warn(\n { issue, labelName },\n 'Failed to lookup label for deletion',\n );\n }\n },\n\n async ensureComment({\n number: issue,\n topic,\n content,\n }: EnsureCommentConfig): Promise<boolean> {\n try {\n let body = sanitize(content);\n const commentList = await helper.getComments(\n http,\n config.repository,\n issue,\n );\n\n // Search comment by either topic or exact body\n let comment: Comment | null = null;\n if (topic) {\n comment = findCommentByTopic(commentList, topic);\n body = `### ${topic}\\n\\n${body}`;\n } else {\n comment = findCommentByContent(commentList, body);\n }\n\n // Create a new comment if no match has been found, otherwise update if necessary\n if (!comment) {\n comment = await helper.createComment(\n http,\n config.repository,\n issue,\n body,\n );\n logger.info(\n { repository: config.repository, issue, comment: comment.id },\n 'Comment added',\n );\n } else if (comment.body === body) {\n logger.debug(`Comment #${comment.id} is already up-to-date`);\n } else {\n await helper.updateComment(http, config.repository, comment.id, body);\n logger.debug(\n { repository: config.repository, issue, comment: comment.id },\n 'Comment updated',\n );\n }\n\n return true;\n } catch (err) {\n logger.warn({ err, issue, subject: topic }, 'Error ensuring comment');\n return false;\n }\n },\n\n async ensureCommentRemoval(\n deleteConfig: EnsureCommentRemovalConfig,\n ): Promise<void> {\n const { number: issue } = deleteConfig;\n const key =\n deleteConfig.type === 'by-topic'\n ? deleteConfig.topic\n : deleteConfig.content;\n logger.debug(`Ensuring comment \"${key}\" in #${issue} is removed`);\n const commentList = await helper.getComments(\n http,\n config.repository,\n issue,\n );\n\n let comment: Comment | null = null;\n // v8 ignore else -- TODO: add test #40625\n if (deleteConfig.type === 'by-topic') {\n comment = findCommentByTopic(commentList, deleteConfig.topic);\n } else if (deleteConfig.type === 'by-content') {\n const body = sanitize(deleteConfig.content);\n comment = findCommentByContent(commentList, body);\n }\n\n // Abort and do nothing if no matching comment was found\n if (!comment) {\n return;\n }\n\n // Try to delete comment\n try {\n await helper.deleteComment(http, config.repository, comment.id);\n } catch (err) {\n logger.warn(\n { err, issue, config: deleteConfig },\n 'Error deleting comment',\n );\n }\n },\n\n async getBranchPr(branchName: string): Promise<Pr | null> {\n logger.debug(`getBranchPr(${branchName})`);\n const pr = await platform.findPr({ branchName, state: 'open' });\n return pr ? platform.getPr(pr.number) : null;\n },\n\n async addAssignees(number: number, assignees: string[]): Promise<void> {\n logger.debug(\n `Updating assignees '${assignees?.join(', ')}' on Issue #${number}`,\n );\n await helper.updateIssue(http, config.repository, number, {\n assignees,\n });\n },\n\n async addReviewers(number: number, reviewers: string[]): Promise<void> {\n logger.debug(`Adding reviewers '${reviewers?.join(', ')}' to #${number}`);\n if (\n minReviewerVersion &&\n semver.lt(defaults.version, minReviewerVersion)\n ) {\n logger.debug(\n { version: defaults.version },\n 'Adding reviewer not yet supported.',\n );\n return;\n }\n try {\n const teamReviewers = new Set(\n reviewers\n .filter((r) => r.startsWith('team:'))\n .map((r) => r.substring(5)),\n );\n const userReviewers = new Set(\n reviewers.filter((r) => !r.startsWith('team:')),\n );\n\n await helper.requestPrReviewers(http, config.repository, number, {\n reviewers: [...userReviewers],\n ...(teamReviewers.size && {\n team_reviewers: [...teamReviewers],\n }),\n });\n } catch (err) {\n logger.warn({ err, number, reviewers }, 'Failed to assign reviewer');\n }\n },\n\n massageMarkdown(prBody: string): string {\n return smartTruncate(smartLinks(prBody), maxBodyLength());\n },\n\n maxBodyLength,\n };\n\n function maxBodyLength(): number {\n return 1000000;\n }\n\n return { platform, resetPlatform };\n}\n\n/**\n * Forgejo reports the Gitea version it is compatible with as part of its own\n * version, for example `11.0.1-99-c504062+gitea-1.22.0`.\n */\nfunction isForgejo(version: string): boolean {\n return version.includes('gitea-');\n}\n\nfunction logDetectedVersion(version: string): void {\n if (isForgejo(version)) {\n logger.info(\n `Detected Forgejo instance, please use 'forgejo' platform instead`,\n );\n }\n logger.debug(\n `${isForgejo(version) ? 'Forgejo' : 'Gitea'} version: ${version}`,\n );\n}\n\nfunction checkNativeAutomerge(version: string): string | null {\n // Only Gitea v1.24.0+ and Forgejo v10.0.0+ support delete_branch_after_merge.\n const minVersion = isForgejo(version) ? '10.0.0' : '1.24.0';\n if (semver.gte(version, minVersion)) {\n return null;\n }\n return `Gitea-native automerge: not supported on this version of ${isForgejo(version) ? 'Forgejo' : 'Gitea'}. Use ${minVersion} or newer.`;\n}\n\nconst { platform, resetPlatform } = createPlatform({\n id,\n defaultEndpoint: 'https://gitea.com/',\n http: giteaHttp,\n setBaseUrl,\n logDetectedVersion,\n checkNativeAutomerge,\n // Requesting reviewers is only supported since Gitea v1.14.0.\n minReviewerVersion: '1.14.0',\n});\n\nexport { resetPlatform };\n\n/* oxlint-disable typescript/unbound-method */\nexport const {\n addAssignees,\n addReviewers,\n createPr,\n deleteLabel,\n ensureComment,\n ensureCommentRemoval,\n ensureIssue,\n ensureIssueClosing,\n findIssue,\n findPr,\n getBranchPr,\n getBranchStatus,\n getBranchStatusCheck,\n getIssue,\n getRawFile,\n getJsonFile,\n getIssueList,\n getPr,\n massageMarkdown,\n maxBodyLength,\n getPrList,\n getRepos,\n initPlatform,\n initRepo,\n mergePr,\n setBranchStatus,\n updatePr,\n}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AO,YAAY,QAAQ;KAC/D,WAAW,CAAC,GAAG,aAAa;KAC5B,GAAI,cAAc,QAAQ,EACxB,gBAAgB,CAAC,GAAG,aAAa,EACnC;IACF,CAAC;GACH,SAAS,KAAK;IACZ,OAAO,KAAK;KAAE;KAAK;KAAQ;IAAU,GAAG,2BAA2B;GACrE;EACF;EAEA,gBAAgB,QAAwB;GACtC,OAAO,cAAc,WAAW,MAAM,GAAG,cAAc,CAAC;EAC1D;EAEA;CACF;CAEA,SAAS,gBAAwB;EAC/B,OAAO;CACT;CAEA,OAAO;EAAE;EAAU;CAAc;AACnC;;;;;AAMA,SAAS,UAAU,SAA0B;CAC3C,OAAO,QAAQ,SAAS,QAAQ;AAClC;AAEA,SAAS,mBAAmB,SAAuB;CACjD,IAAI,UAAU,OAAO,GACnB,OAAO,KACL,kEACF;CAEF,OAAO,MACL,GAAG,UAAU,OAAO,IAAI,YAAY,QAAQ,YAAY,SAC1D;AACF;AAEA,SAAS,qBAAqB,SAAgC;CAE5D,MAAM,aAAa,UAAU,OAAO,IAAI,WAAW;CACnD,IAAI,OAAO,IAAI,SAAS,UAAU,GAChC,OAAO;CAET,OAAO,4DAA4D,UAAU,OAAO,IAAI,YAAY,QAAQ,QAAQ,WAAW;AACjI;AAEA,MAAM,EAAE,UAAU,kBAAkB,eAAe;CACjD;CACA,iBAAiB;CACjB,MAAM;CACN;CACA;CACA;CAEA,oBAAoB;AACtB,CAAC;AAKD,MAAa,EACX,cACA,cACA,UACA,aACA,eACA,sBACA,aACA,oBACA,WACA,QACA,aACA,iBACA,sBACA,UACA,YACA,aACA,cACA,OACA,iBACA,eACA,WACA,UACA,cACA,UACA,SACA,iBACA,aACE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { logger } from "../../../logger/index.js";
|
|
2
|
+
import { getOrgLabels, getRepoLabels } from "./gitea-helper.js";
|
|
3
|
+
//#region lib/modules/platform/gitea/labels.ts
|
|
4
|
+
async function fetchRepoLabels(http, repository) {
|
|
5
|
+
const labels = await getRepoLabels(http, repository, { memCache: false });
|
|
6
|
+
logger.debug(`Retrieved ${labels.length} repo labels`);
|
|
7
|
+
return labels;
|
|
8
|
+
}
|
|
9
|
+
async function fetchOrgLabels(http, { isOrgRepo, orgName }) {
|
|
10
|
+
if (!isOrgRepo) return [];
|
|
11
|
+
try {
|
|
12
|
+
const labels = await getOrgLabels(http, orgName, { memCache: false });
|
|
13
|
+
logger.debug(`Retrieved ${labels.length} org labels`);
|
|
14
|
+
return labels;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
logger.debug({ err }, `Unable to fetch organization labels`);
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Labels of the repository followed by the labels of its organization, if any.
|
|
22
|
+
*/
|
|
23
|
+
async function fetchLabelList(http, repo) {
|
|
24
|
+
const [repoLabels, orgLabels] = await Promise.all([fetchRepoLabels(http, repo.repository), fetchOrgLabels(http, repo)]);
|
|
25
|
+
return [...repoLabels, ...orgLabels];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Cached labels of the repository. The lookup is stored on the repository,
|
|
29
|
+
* so resetting `labelList` to `null` refetches the labels on next use.
|
|
30
|
+
*/
|
|
31
|
+
function getLabelList(http, repo) {
|
|
32
|
+
repo.labelList ??= fetchLabelList(http, repo);
|
|
33
|
+
return repo.labelList;
|
|
34
|
+
}
|
|
35
|
+
async function lookupLabelByName(http, repo, name) {
|
|
36
|
+
logger.debug(`lookupLabelByName(${name})`);
|
|
37
|
+
return (await getLabelList(http, repo)).find((l) => l.name === name)?.id ?? null;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { getLabelList, lookupLabelByName };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","names":["helper.getRepoLabels","helper.getOrgLabels"],"sources":["../../../../lib/modules/platform/gitea/labels.ts"],"sourcesContent":["import { logger } from '../../../logger/index.ts';\nimport * as helper from './gitea-helper.ts';\nimport type { Label } from './schema.ts';\nimport type { GiteaLikeHttp, LabelListRepo } from './types.ts';\n\nasync function fetchRepoLabels(\n http: GiteaLikeHttp,\n repository: string,\n): Promise<Label[]> {\n const labels = await helper.getRepoLabels(http, repository, {\n memCache: false,\n });\n logger.debug(`Retrieved ${labels.length} repo labels`);\n return labels;\n}\n\nasync function fetchOrgLabels(\n http: GiteaLikeHttp,\n { isOrgRepo, orgName }: LabelListRepo,\n): Promise<Label[]> {\n if (!isOrgRepo) {\n return [];\n }\n try {\n const labels = await helper.getOrgLabels(http, orgName, {\n memCache: false,\n });\n logger.debug(`Retrieved ${labels.length} org labels`);\n return labels;\n } catch (err) {\n // Will fail if owner of repo is not org\n logger.debug({ err }, `Unable to fetch organization labels`);\n return [];\n }\n}\n\n/**\n * Labels of the repository followed by the labels of its organization, if any.\n */\nasync function fetchLabelList(\n http: GiteaLikeHttp,\n repo: LabelListRepo,\n): Promise<Label[]> {\n const [repoLabels, orgLabels] = await Promise.all([\n fetchRepoLabels(http, repo.repository),\n fetchOrgLabels(http, repo),\n ]);\n return [...repoLabels, ...orgLabels];\n}\n\n/**\n * Cached labels of the repository. The lookup is stored on the repository,\n * so resetting `labelList` to `null` refetches the labels on next use.\n */\nexport function getLabelList(\n http: GiteaLikeHttp,\n repo: LabelListRepo,\n): Promise<Label[]> {\n repo.labelList ??= fetchLabelList(http, repo);\n\n return repo.labelList;\n}\n\nexport async function lookupLabelByName(\n http: GiteaLikeHttp,\n repo: LabelListRepo,\n name: string,\n): Promise<number | null> {\n logger.debug(`lookupLabelByName(${name})`);\n const labelList = await getLabelList(http, repo);\n return labelList.find((l) => l.name === name)?.id ?? null;\n}\n"],"mappings":";;;AAKA,eAAe,gBACb,MACA,YACkB;CAClB,MAAM,SAAS,MAAMA,cAAqB,MAAM,YAAY,EAC1D,UAAU,MACZ,CAAC;CACD,OAAO,MAAM,aAAa,OAAO,OAAO,aAAa;CACrD,OAAO;AACT;AAEA,eAAe,eACb,MACA,EAAE,WAAW,WACK;CAClB,IAAI,CAAC,WACH,OAAO,CAAC;CAEV,IAAI;EACF,MAAM,SAAS,MAAMC,aAAoB,MAAM,SAAS,EACtD,UAAU,MACZ,CAAC;EACD,OAAO,MAAM,aAAa,OAAO,OAAO,YAAY;EACpD,OAAO;CACT,SAAS,KAAK;EAEZ,OAAO,MAAM,EAAE,IAAI,GAAG,qCAAqC;EAC3D,OAAO,CAAC;CACV;AACF;;;;AAKA,eAAe,eACb,MACA,MACkB;CAClB,MAAM,CAAC,YAAY,aAAa,MAAM,QAAQ,IAAI,CAChD,gBAAgB,MAAM,KAAK,UAAU,GACrC,eAAe,MAAM,IAAI,CAC3B,CAAC;CACD,OAAO,CAAC,GAAG,YAAY,GAAG,SAAS;AACrC;;;;;AAMA,SAAgB,aACd,MACA,MACkB;CAClB,KAAK,cAAc,eAAe,MAAM,IAAI;CAE5C,OAAO,KAAK;AACd;AAEA,eAAsB,kBACpB,MACA,MACA,MACwB;CACxB,OAAO,MAAM,qBAAqB,KAAK,EAAE;CAEzC,QAAO,MADiB,aAAa,MAAM,IAAI,EAAA,CAC9B,MAAM,MAAM,EAAE,SAAS,IAAI,CAAC,EAAE,MAAM;AACvD"}
|
|
@@ -3,58 +3,52 @@ import { get, set } from "../../../util/cache/memory/index.js";
|
|
|
3
3
|
import { logger } from "../../../logger/index.js";
|
|
4
4
|
import { getQueryString, parseLinkHeader, parseUrl } from "../../../util/url.js";
|
|
5
5
|
import { getCache } from "../../../util/cache/repository/index.js";
|
|
6
|
+
import { PRList } from "./schema.js";
|
|
6
7
|
import { API_PATH, toRenovatePR } from "./utils.js";
|
|
7
8
|
import { isNullOrUndefined } from "@sindresorhus/is";
|
|
8
9
|
import { dequal } from "dequal";
|
|
9
10
|
import { DateTime } from "luxon";
|
|
10
11
|
//#region lib/modules/platform/gitea/pr-cache.ts
|
|
11
|
-
|
|
12
|
+
function syncedCacheKey(platform) {
|
|
13
|
+
return `${platform}-pr-cache-synced`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The PRs of a single repository, backed by the repository cache.
|
|
17
|
+
*/
|
|
18
|
+
var RepoPrCache = class {
|
|
19
|
+
http;
|
|
20
|
+
platform;
|
|
12
21
|
cache;
|
|
13
22
|
items = [];
|
|
14
23
|
repo;
|
|
15
24
|
ignorePrAuthor;
|
|
16
25
|
author;
|
|
17
|
-
constructor(repo, ignorePrAuthor, author) {
|
|
26
|
+
constructor(http, platform, { repo, ignorePrAuthor, author }) {
|
|
27
|
+
this.http = http;
|
|
28
|
+
this.platform = platform;
|
|
18
29
|
this.repo = repo;
|
|
19
30
|
this.ignorePrAuthor = ignorePrAuthor;
|
|
20
31
|
this.author = author;
|
|
21
32
|
const repoCache = getCache();
|
|
22
33
|
repoCache.platform ??= {};
|
|
23
|
-
repoCache.platform
|
|
24
|
-
let pullRequestCache =
|
|
34
|
+
const platformCache = repoCache.platform[platform] ??= {};
|
|
35
|
+
let pullRequestCache = platformCache.pullRequestsCache;
|
|
25
36
|
if (isNullOrUndefined(pullRequestCache) || pullRequestCache.author !== author) pullRequestCache = {
|
|
26
37
|
items: {},
|
|
27
38
|
updated_at: null,
|
|
28
39
|
author
|
|
29
40
|
};
|
|
30
|
-
|
|
41
|
+
platformCache.pullRequestsCache = pullRequestCache;
|
|
31
42
|
this.cache = pullRequestCache;
|
|
32
43
|
this.updateItems();
|
|
33
44
|
}
|
|
34
|
-
|
|
35
|
-
set("gitea-pr-cache-synced", false);
|
|
36
|
-
}
|
|
37
|
-
static async init(http, repo, ignorePrAuthor, author) {
|
|
38
|
-
const res = new GiteaPrCache(repo, ignorePrAuthor, author);
|
|
39
|
-
if (!get("gitea-pr-cache-synced")) {
|
|
40
|
-
await res.sync(http);
|
|
41
|
-
set("gitea-pr-cache-synced", true);
|
|
42
|
-
}
|
|
43
|
-
return res;
|
|
44
|
-
}
|
|
45
|
-
getPrs() {
|
|
45
|
+
get prs() {
|
|
46
46
|
return this.items;
|
|
47
47
|
}
|
|
48
|
-
static async getPrs(http, repo, ignorePrAuthor, author) {
|
|
49
|
-
return (await GiteaPrCache.init(http, repo, ignorePrAuthor, author)).getPrs();
|
|
50
|
-
}
|
|
51
48
|
setPr(item) {
|
|
52
49
|
this.cache.items[item.number] = item;
|
|
53
50
|
this.updateItems();
|
|
54
51
|
}
|
|
55
|
-
static async setPr(http, repo, ignorePrAuthor, author, item) {
|
|
56
|
-
(await GiteaPrCache.init(http, repo, ignorePrAuthor, author)).setPr(item);
|
|
57
|
-
}
|
|
58
52
|
reconcile(rawItems) {
|
|
59
53
|
const { items } = this.cache;
|
|
60
54
|
let { updated_at } = this.cache;
|
|
@@ -62,7 +56,7 @@ var GiteaPrCache = class GiteaPrCache {
|
|
|
62
56
|
let needNextPage = true;
|
|
63
57
|
for (const rawItem of rawItems) {
|
|
64
58
|
if (!rawItem) {
|
|
65
|
-
logger.warn("
|
|
59
|
+
logger.warn({ platform: this.platform }, "PR is empty, throwing temporary error");
|
|
66
60
|
throw new Error(TEMPORARY_ERROR);
|
|
67
61
|
}
|
|
68
62
|
const id = rawItem.number;
|
|
@@ -80,7 +74,7 @@ var GiteaPrCache = class GiteaPrCache {
|
|
|
80
74
|
this.cache.updated_at = updated_at;
|
|
81
75
|
return needNextPage;
|
|
82
76
|
}
|
|
83
|
-
async sync(
|
|
77
|
+
async sync() {
|
|
84
78
|
let query = getQueryString({
|
|
85
79
|
state: "all",
|
|
86
80
|
sort: "recentupdate",
|
|
@@ -88,16 +82,15 @@ var GiteaPrCache = class GiteaPrCache {
|
|
|
88
82
|
...this.ignorePrAuthor ? {} : { poster: this.author }
|
|
89
83
|
});
|
|
90
84
|
while (query) {
|
|
91
|
-
const res = await http.
|
|
85
|
+
const res = await this.http.getJson(`${API_PATH}/repos/${this.repo}/pulls?${query}`, {
|
|
92
86
|
memCache: false,
|
|
93
87
|
paginate: false
|
|
94
|
-
});
|
|
88
|
+
}, PRList);
|
|
95
89
|
if (!this.reconcile(res.body)) break;
|
|
96
90
|
const uri = parseUrl(parseLinkHeader(res.headers.link)?.next?.url);
|
|
97
91
|
query = uri ? uri.search : null;
|
|
98
92
|
}
|
|
99
93
|
this.updateItems();
|
|
100
|
-
return this;
|
|
101
94
|
}
|
|
102
95
|
/**
|
|
103
96
|
* Ensure the pr cache starts with the most recent PRs.
|
|
@@ -107,6 +100,51 @@ var GiteaPrCache = class GiteaPrCache {
|
|
|
107
100
|
this.items = Object.values(this.cache.items).reverse();
|
|
108
101
|
}
|
|
109
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* PR cache of one platform. `initRepo()` records the repository, the
|
|
105
|
+
* repository cache itself is bound on first use because it is initialized
|
|
106
|
+
* after `platform.initRepo()`.
|
|
107
|
+
*/
|
|
108
|
+
var GiteaPrCache = class {
|
|
109
|
+
http;
|
|
110
|
+
platform;
|
|
111
|
+
repoOptions = null;
|
|
112
|
+
repoCache = null;
|
|
113
|
+
constructor(http, platform) {
|
|
114
|
+
this.http = http;
|
|
115
|
+
this.platform = platform;
|
|
116
|
+
}
|
|
117
|
+
initRepo(repo, ignorePrAuthor, author) {
|
|
118
|
+
this.repoOptions = {
|
|
119
|
+
repo,
|
|
120
|
+
ignorePrAuthor,
|
|
121
|
+
author
|
|
122
|
+
};
|
|
123
|
+
this.repoCache = null;
|
|
124
|
+
}
|
|
125
|
+
reset() {
|
|
126
|
+
this.repoOptions = null;
|
|
127
|
+
this.repoCache = null;
|
|
128
|
+
}
|
|
129
|
+
forceSync() {
|
|
130
|
+
set(syncedCacheKey(this.platform), false);
|
|
131
|
+
}
|
|
132
|
+
async open() {
|
|
133
|
+
if (!this.repoOptions) throw new Error("PR cache used before initRepo()");
|
|
134
|
+
this.repoCache ??= new RepoPrCache(this.http, this.platform, this.repoOptions);
|
|
135
|
+
if (!get(syncedCacheKey(this.platform))) {
|
|
136
|
+
await this.repoCache.sync();
|
|
137
|
+
set(syncedCacheKey(this.platform), true);
|
|
138
|
+
}
|
|
139
|
+
return this.repoCache;
|
|
140
|
+
}
|
|
141
|
+
async getPrs() {
|
|
142
|
+
return (await this.open()).prs;
|
|
143
|
+
}
|
|
144
|
+
async setPr(item) {
|
|
145
|
+
(await this.open()).setPr(item);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
110
148
|
//#endregion
|
|
111
149
|
export { GiteaPrCache };
|
|
112
150
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr-cache.js","names":["memCache.get"],"sources":["../../../../lib/modules/platform/gitea/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
|
|
1
|
+
{"version":3,"file":"pr-cache.js","names":["memCache.get"],"sources":["../../../../lib/modules/platform/gitea/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 {\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 { GiteaLikeHttp, GiteaPlatformKey, PrCacheData } from './types.ts';\nimport { API_PATH, toRenovatePR } from './utils.ts';\n\nfunction syncedCacheKey(platform: GiteaPlatformKey): string {\n return `${platform}-pr-cache-synced`;\n}\n\ninterface RepoPrCacheOptions {\n repo: string;\n ignorePrAuthor: boolean;\n author: string;\n}\n\n/**\n * The PRs of a single repository, backed by the repository cache.\n */\nclass RepoPrCache {\n private readonly http: GiteaLikeHttp;\n private readonly platform: GiteaPlatformKey;\n private readonly cache: PrCacheData;\n private items: Pr[] = [];\n private readonly repo: string;\n private readonly ignorePrAuthor: boolean;\n private readonly author: string;\n\n constructor(\n http: GiteaLikeHttp,\n platform: GiteaPlatformKey,\n { repo, ignorePrAuthor, author }: RepoPrCacheOptions,\n ) {\n this.http = http;\n this.platform = platform;\n this.repo = repo;\n this.ignorePrAuthor = ignorePrAuthor;\n this.author = author;\n const repoCache = getCache();\n repoCache.platform ??= {};\n const platformCache = (repoCache.platform[platform] ??= {});\n let pullRequestCache = platformCache.pullRequestsCache as\n PrCacheData | undefined;\n if (\n isNullOrUndefined(pullRequestCache) ||\n pullRequestCache.author !== author\n ) {\n pullRequestCache = {\n items: {},\n updated_at: null,\n author,\n };\n }\n platformCache.pullRequestsCache = pullRequestCache;\n this.cache = pullRequestCache;\n this.updateItems();\n }\n\n get prs(): Pr[] {\n return this.items;\n }\n\n setPr(item: Pr): void {\n this.cache.items[item.number] = item;\n this.updateItems();\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(\n { platform: this.platform },\n 'PR is empty, throwing temporary error',\n );\n // Gitea API sometimes returns empty PRs, so we throw a temporary error\n // https://github.com/go-gitea/gitea/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 async sync(): Promise<void> {\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 // Gitea / Forgejo will cap appropriate (50 by default, see `MAX_RESPONSE_ITEMS`).\n // https://docs.gitea.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 Gitea 1.23.0 and 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 this.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\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\n/**\n * PR cache of one platform. `initRepo()` records the repository, the\n * repository cache itself is bound on first use because it is initialized\n * after `platform.initRepo()`.\n */\nexport class GiteaPrCache {\n private readonly http: GiteaLikeHttp;\n private readonly platform: GiteaPlatformKey;\n private repoOptions: RepoPrCacheOptions | null = null;\n private repoCache: RepoPrCache | null = null;\n\n constructor(http: GiteaLikeHttp, platform: GiteaPlatformKey) {\n this.http = http;\n this.platform = platform;\n }\n\n initRepo(repo: string, ignorePrAuthor: boolean, author: string): void {\n this.repoOptions = { repo, ignorePrAuthor, author };\n this.repoCache = null;\n }\n\n reset(): void {\n this.repoOptions = null;\n this.repoCache = null;\n }\n\n forceSync(): void {\n memCache.set(syncedCacheKey(this.platform), false);\n }\n\n private async open(): Promise<RepoPrCache> {\n if (!this.repoOptions) {\n throw new Error('PR cache used before initRepo()');\n }\n this.repoCache ??= new RepoPrCache(\n this.http,\n this.platform,\n this.repoOptions,\n );\n const isSynced = memCache.get<true | undefined>(\n syncedCacheKey(this.platform),\n );\n if (!isSynced) {\n await this.repoCache.sync();\n memCache.set(syncedCacheKey(this.platform), true);\n }\n return this.repoCache;\n }\n\n async getPrs(): Promise<Pr[]> {\n const repoCache = await this.open();\n return repoCache.prs;\n }\n\n async setPr(item: Pr): Promise<void> {\n const repoCache = await this.open();\n repoCache.setPr(item);\n }\n}\n"],"mappings":";;;;;;;;;;;AAkBA,SAAS,eAAe,UAAoC;CAC1D,OAAO,GAAG,SAAS;AACrB;;;;AAWA,IAAM,cAAN,MAAkB;CAChB;CACA;CACA;CACA,QAAsB,CAAC;CACvB;CACA;CACA;CAEA,YACE,MACA,UACA,EAAE,MAAM,gBAAgB,UACxB;EACA,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,OAAO;EACZ,KAAK,iBAAiB;EACtB,KAAK,SAAS;EACd,MAAM,YAAY,SAAS;EAC3B,UAAU,aAAa,CAAC;EACxB,MAAM,gBAAiB,UAAU,SAAS,cAAc,CAAC;EACzD,IAAI,mBAAmB,cAAc;EAErC,IACE,kBAAkB,gBAAgB,KAClC,iBAAiB,WAAW,QAE5B,mBAAmB;GACjB,OAAO,CAAC;GACR,YAAY;GACZ;EACF;EAEF,cAAc,oBAAoB;EAClC,KAAK,QAAQ;EACb,KAAK,YAAY;CACnB;CAEA,IAAI,MAAY;EACd,OAAO,KAAK;CACd;CAEA,MAAM,MAAgB;EACpB,KAAK,MAAM,MAAM,KAAK,UAAU;EAChC,KAAK,YAAY;CACnB;CAEA,UAAkB,UAAkC;EAClD,MAAM,EAAE,UAAU,KAAK;EACvB,IAAI,EAAE,eAAe,KAAK;EAC1B,MAAM,YAAY,aAAa,SAAS,QAAQ,UAAU,IAAI;EAE9D,IAAI,eAAe;EAEnB,KAAK,MAAM,WAAW,UAAU;GAC9B,IAA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