@paklo/runner 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/job-runner-BUl_fCJS.js +770 -0
- package/dist/job-runner-BUl_fCJS.js.map +1 -0
- package/dist/local/azure.d.ts +53 -0
- package/dist/local/azure.js +424 -0
- package/dist/local/azure.js.map +1 -0
- package/dist/local/index.d.ts +2 -0
- package/dist/local/index.js +4 -0
- package/dist/logger-Bekleunx.js +3 -0
- package/dist/server-Dcc7bD60.js +203 -0
- package/dist/server-Dcc7bD60.js.map +1 -0
- package/dist/server-Ri18zAcc.d.ts +229 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure.js","names":["updates: DependabotUpdate[]","results: RunJobsResult","jobId: number | undefined","job: DependabotJobConfig | undefined","credentials: DependabotCredential[] | undefined","jobToken: string","credentialsToken: string","securityVulnerabilities: SecurityVulnerability[]","dependencyNamesToUpdate: string[]","packagesToCheckForVulnerabilities: Package[] | undefined"],"sources":["../../src/local/azure/server.ts","../../src/local/azure/runner.ts"],"sourcesContent":["import type { AzureDevOpsUrl, AzureDevOpsWebApiClient, IPullRequestProperties } from '@paklo/core/azure';\nimport {\n buildPullRequestProperties,\n GitPullRequestMergeStrategy,\n getPullRequestChangedFilesForOutputData,\n getPullRequestCloseReasonForOutputData,\n getPullRequestDependenciesPropertyValueForOutputData,\n getPullRequestDescription,\n getPullRequestForDependencyNames,\n parsePullRequestProperties,\n} from '@paklo/core/azure';\nimport { type DependabotRequest, getBranchNameForUpdate } from '@paklo/core/dependabot';\nimport { logger } from '@/logger';\nimport { LocalDependabotServer, type LocalDependabotServerOptions } from '../server';\n\nexport type AzureLocalDependabotServerOptions = LocalDependabotServerOptions & {\n url: AzureDevOpsUrl;\n authorClient: AzureDevOpsWebApiClient;\n autoApprove: boolean;\n approverClient?: AzureDevOpsWebApiClient;\n setAutoComplete: boolean;\n mergeStrategy?: string;\n autoCompleteIgnoreConfigIds: number[];\n existingBranchNames: string[] | undefined;\n existingPullRequests: IPullRequestProperties[];\n};\n\nexport class AzureLocalDependabotServer extends LocalDependabotServer {\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: options is used\n private readonly options: AzureLocalDependabotServerOptions;\n\n constructor(options: AzureLocalDependabotServerOptions) {\n super(options);\n this.options = options;\n }\n\n protected override async handle(id: number, request: DependabotRequest): Promise<boolean> {\n await super.handle(id, request); // common logic\n\n const { options, affectedPullRequestIds } = this;\n const {\n url,\n authorClient,\n approverClient,\n existingBranchNames,\n existingPullRequests,\n autoApprove,\n mergeStrategy,\n setAutoComplete,\n autoCompleteIgnoreConfigIds,\n author,\n debug,\n dryRun,\n } = options;\n\n const { type, data } = request;\n const job = await this.job(id);\n if (!job) {\n logger.error(`No job found for ID '${id}', cannot process request of type '${type}'`);\n return false;\n }\n const { 'package-manager': packageManager } = job;\n logger.info(`Processing '${type}' for job ID '${id}'`);\n if (debug) {\n logger.debug(JSON.stringify(data));\n }\n\n const update = this.update(id)!; // exists because job exists\n const { project, repository } = url;\n\n switch (type) {\n // Documentation on the 'data' model for each output type can be found here:\n // See: https://github.com/dependabot/cli/blob/main/internal/model/update.go\n\n case 'create_pull_request': {\n const title = data['pr-title'];\n if (dryRun) {\n logger.warn(`Skipping pull request creation of '${title}' as 'dryRun' is set to 'true'`);\n return true;\n }\n\n // Skip if active pull request limit reached.\n const openPullRequestsLimit = update['open-pull-requests-limit']!;\n\n // Parse the Dependabot metadata for the existing pull requests that are related to this update\n // Dependabot will use this to determine if we need to create new pull requests or update/close existing ones\n const existingPullRequestsForPackageManager = parsePullRequestProperties(existingPullRequests, packageManager);\n const existingPullRequestsCount = Object.entries(existingPullRequestsForPackageManager).length;\n const openPullRequestsCount = affectedPullRequestIds.get(id)!.created.length + existingPullRequestsCount;\n const hasReachedOpenPullRequestLimit =\n openPullRequestsLimit > 0 && openPullRequestsCount >= openPullRequestsLimit;\n\n if (hasReachedOpenPullRequestLimit) {\n logger.warn(\n `Skipping pull request creation of '${title}' as the open pull requests limit (${openPullRequestsLimit}) has been reached`,\n );\n return true;\n }\n\n const changedFiles = getPullRequestChangedFilesForOutputData(data);\n const dependencies = getPullRequestDependenciesPropertyValueForOutputData(data);\n const targetBranch = update['target-branch'] || (await authorClient.getDefaultBranch(project, repository));\n const sourceBranch = getBranchNameForUpdate(\n update['package-ecosystem'],\n targetBranch,\n update.directory || update.directories?.find((dir) => changedFiles[0]?.path?.startsWith(dir)),\n !Array.isArray(dependencies) ? dependencies['dependency-group-name'] : undefined,\n !Array.isArray(dependencies) ? dependencies.dependencies : dependencies,\n update['pull-request-branch-name']?.separator,\n );\n\n // Check if the source branch already exists or conflicts with an existing branch\n const existingBranch = existingBranchNames?.find((branch) => sourceBranch === branch) || [];\n if (existingBranch.length) {\n logger.error(\n `Unable to create pull request '${title}' as source branch '${sourceBranch}' already exists; Delete the existing branch and try again.`,\n );\n return false;\n }\n const conflictingBranches = existingBranchNames?.filter((branch) => sourceBranch.startsWith(branch)) || [];\n if (conflictingBranches.length) {\n logger.error(\n `Unable to create pull request '${title}' as source branch '${sourceBranch}' would conflict with existing branch(es) '${conflictingBranches.join(', ')}'; Delete the conflicting branch(es) and try again.`,\n );\n return false;\n }\n\n // Create a new pull request\n const newPullRequestId = await authorClient.createPullRequest({\n project: project,\n repository: repository,\n source: {\n commit: data['base-commit-sha'] || job.source.commit!,\n branch: sourceBranch,\n },\n target: {\n branch: targetBranch!,\n },\n author,\n title,\n description: getPullRequestDescription(packageManager, data['pr-body'], data.dependencies),\n commitMessage: data['commit-message'],\n autoComplete: setAutoComplete\n ? {\n ignorePolicyConfigIds: autoCompleteIgnoreConfigIds,\n mergeStrategy: (() => {\n switch (mergeStrategy) {\n case 'noFastForward':\n return GitPullRequestMergeStrategy.NoFastForward;\n case 'squash':\n return GitPullRequestMergeStrategy.Squash;\n case 'rebase':\n return GitPullRequestMergeStrategy.Rebase;\n case 'rebaseMerge':\n return GitPullRequestMergeStrategy.RebaseMerge;\n default:\n return GitPullRequestMergeStrategy.Squash;\n }\n })(),\n }\n : undefined,\n assignees: update.assignees,\n labels: update.labels?.map((label) => label?.trim()) || [],\n workItems: update.milestone ? [update.milestone] : [],\n changes: changedFiles,\n properties: buildPullRequestProperties(packageManager, dependencies),\n });\n\n // Auto-approve the pull request, if required\n if (autoApprove && approverClient && newPullRequestId) {\n await approverClient.approvePullRequest({\n project: project,\n repository: repository,\n pullRequestId: newPullRequestId,\n });\n }\n\n // Store the new pull request ID, so we can keep track of the total number of open pull requests\n if (newPullRequestId && newPullRequestId > 0) {\n affectedPullRequestIds.get(id)!.created.push(newPullRequestId);\n return true;\n } else {\n return false;\n }\n }\n\n case 'update_pull_request': {\n if (dryRun) {\n logger.warn(`Skipping pull request update as 'dryRun' is set to 'true'`);\n return true;\n }\n\n // Find the pull request to update\n const pullRequestToUpdate = getPullRequestForDependencyNames(\n existingPullRequests,\n packageManager,\n data['dependency-names'],\n );\n if (!pullRequestToUpdate) {\n logger.error(\n `Could not find pull request to update for package manager '${packageManager}' with dependencies '${data['dependency-names'].join(', ')}'`,\n );\n return false;\n }\n\n // Update the pull request\n const pullRequestWasUpdated = await authorClient.updatePullRequest({\n project: project,\n repository: repository,\n pullRequestId: pullRequestToUpdate.id,\n commit: data['base-commit-sha'] || job.source.commit!,\n author,\n changes: getPullRequestChangedFilesForOutputData(data),\n skipIfDraft: true,\n skipIfCommitsFromAuthorsOtherThan: author.email,\n skipIfNotBehindTargetBranch: true,\n });\n\n // Re-approve the pull request, if required\n if (autoApprove && approverClient && pullRequestWasUpdated) {\n await approverClient.approvePullRequest({\n project: project,\n repository: repository,\n pullRequestId: pullRequestToUpdate.id,\n });\n }\n\n if (pullRequestWasUpdated) {\n affectedPullRequestIds.get(id)!.updated.push(pullRequestToUpdate.id);\n return true;\n }\n return false;\n }\n\n case 'close_pull_request': {\n if (dryRun) {\n logger.warn(`Skipping pull request closure as 'dryRun' is set to 'true'`);\n return true;\n }\n\n // Find the pull request to close\n const pullRequestToClose = getPullRequestForDependencyNames(\n existingPullRequests,\n packageManager,\n data['dependency-names'],\n );\n if (!pullRequestToClose) {\n logger.error(\n `Could not find pull request to close for package manager '${packageManager}' with dependencies '${data['dependency-names'].join(', ')}'`,\n );\n return false;\n }\n\n // TODO: GitHub Dependabot will close with reason \"Superseded by ${new_pull_request_id}\" when another PR supersedes it.\n // How do we detect this? Do we need to?\n\n // Close the pull request\n const success = await authorClient.abandonPullRequest({\n project: project,\n repository: repository,\n pullRequestId: pullRequestToClose.id,\n comment: getPullRequestCloseReasonForOutputData(data),\n deleteSourceBranch: true,\n });\n if (success) {\n affectedPullRequestIds.get(id)!.closed.push(pullRequestToClose.id);\n return true;\n }\n return false;\n }\n\n // No action required\n case 'update_dependency_list':\n case 'mark_as_processed':\n case 'record_ecosystem_versions':\n case 'record_ecosystem_meta':\n case 'increment_metric':\n case 'record_metrics':\n return true;\n\n case 'record_update_job_error':\n logger.error(`Update job error: ${data['error-type']} ${JSON.stringify(data['error-details'])}`);\n return true;\n\n case 'record_update_job_unknown_error':\n logger.error(`Update job unknown error: ${data['error-type']}, ${JSON.stringify(data['error-details'])}`);\n return true;\n\n default:\n logger.warn(`Unknown dependabot output type '${type}', ignoring...`);\n return true;\n }\n }\n}\n","import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport {\n AzureDevOpsWebApiClient,\n DEVOPS_PR_PROPERTY_MICROSOFT_GIT_SOURCE_REF_NAME,\n type IPullRequestProperties,\n normalizeBranchName,\n parsePullRequestProperties,\n} from '@paklo/core/azure';\nimport {\n type DependabotCredential,\n DependabotJobBuilder,\n type DependabotJobConfig,\n type DependabotUpdate,\n mapPackageEcosystemToPackageManager,\n} from '@paklo/core/dependabot';\nimport {\n filterVulnerabilities,\n GitHubGraphClient,\n getGhsaPackageEcosystemFromDependabotPackageManager,\n type Package,\n type SecurityVulnerability,\n SecurityVulnerabilitySchema,\n} from '@paklo/core/github';\nimport { logger } from '@/logger';\nimport { type RunJobOptions, runJob } from '../../job-runner';\nimport { LocalJobsRunner, type LocalJobsRunnerOptions, type RunJobsResult } from '../runner';\nimport { AzureLocalDependabotServer, type AzureLocalDependabotServerOptions } from './server';\n\nexport type AzureLocalJobsRunnerOptions = LocalJobsRunnerOptions &\n Omit<\n AzureLocalDependabotServerOptions,\n 'authorClient' | 'approverClient' | 'existingBranchNames' | 'existingPullRequests'\n > & {\n port?: number;\n securityAdvisoriesFile?: string;\n gitToken: string;\n githubToken?: string;\n autoApproveToken?: string;\n };\n\nexport class AzureLocalJobsRunner extends LocalJobsRunner {\n // biome-ignore-start lint/correctness/noUnusedPrivateClassMembers: variables are used\n private readonly options: AzureLocalJobsRunnerOptions;\n private readonly authorClient: AzureDevOpsWebApiClient;\n private readonly approverClient?: AzureDevOpsWebApiClient;\n // biome-ignore-end lint/correctness/noUnusedPrivateClassMembers: variables are used\n\n constructor(options: AzureLocalJobsRunnerOptions) {\n super({ ...options });\n this.options = options;\n const { url, gitToken, autoApprove, debug } = this.options;\n\n // Initialise the DevOps API clients (one for authoring the other for auto-approving (if configured))\n this.authorClient = new AzureDevOpsWebApiClient(url, gitToken, debug);\n this.approverClient = autoApprove\n ? new AzureDevOpsWebApiClient(url, options.autoApproveToken || gitToken, debug)\n : undefined;\n }\n\n public override async run(): Promise<RunJobsResult> {\n await super.run(); // common logic\n\n const {\n options: { url, port, config, targetUpdateIds, command },\n authorClient,\n approverClient,\n } = this;\n\n // Print a warning about the required workarounds for security-only updates, if any update is configured as such\n // TODO: If and when Dependabot supports a better way to do security-only updates, remove this.\n if (config.updates?.some((u) => u['open-pull-requests-limit'] === 0)) {\n logger.warn(\n 'Security-only updates incur a slight performance overhead due to limitations in Dependabot CLI. For more info, see: https://github.com/mburumaxwell/dependabot-azure-devops/blob/main/README.md#configuring-security-advisories-and-known-vulnerabilities',\n );\n }\n\n // Fetch the active pull requests created by the author user\n const existingBranchNames = await authorClient.getBranchNames(url.project, url.repository);\n const existingPullRequests = await authorClient.getActivePullRequestProperties(\n url.project,\n url.repository,\n await authorClient.getUserId(),\n );\n\n // Prepare local server\n const serverOptions: AzureLocalDependabotServerOptions = {\n authorClient,\n approverClient,\n existingBranchNames,\n existingPullRequests,\n ...this.options,\n };\n const server = new AzureLocalDependabotServer(serverOptions);\n server.start(port);\n // give the server a second to start\n await new Promise((resolve) => setTimeout(resolve, 1000));\n\n // The API urls is constant when working in this CLI. Asking people to setup NGROK or similar just to get\n // HTTPS for the job token to be used is too much hassle.\n // Using same value for dependabotApiUrl and dependabotApiDockerUrl so as to capture /record_metrics calls.\n const dependabotApiUrl = `http://host.docker.internal:${server.port}/api`;\n const dependabotApiDockerUrl = dependabotApiUrl;\n\n // If update identifiers are specified, select them; otherwise handle all\n let updates: DependabotUpdate[] = [];\n if (targetUpdateIds && targetUpdateIds.length > 0) {\n for (const id of targetUpdateIds) {\n const upd = config.updates[id];\n if (!upd) {\n logger.warn(\n `\n Unable to find target update id '${id}'.\n This value should be a zero based index of the update in your config file.\n Expected range: 0-${config.updates.length - 1}\n `,\n );\n } else {\n updates.push(upd);\n }\n }\n } else {\n updates = config.updates;\n }\n\n try {\n // Abandon all pull requests where the source branch has been deleted\n await this.abandonPullRequestsWhereSourceRefIsDeleted(existingBranchNames, existingPullRequests);\n\n // Perform updates for each of the [targeted] update blocks in dependabot.yaml\n return await this.performUpdates(\n server,\n updates,\n existingPullRequests,\n dependabotApiUrl,\n dependabotApiDockerUrl,\n command,\n );\n } finally {\n server.stop();\n }\n }\n\n /**\n * Abandon all pull requests where the source branch has been deleted.\n * @param existingBranchNames The names of the existing branches.\n * @param existingPullRequests The existing pull requests.\n */\n private async abandonPullRequestsWhereSourceRefIsDeleted(\n existingBranchNames?: string[],\n existingPullRequests?: IPullRequestProperties[],\n ): Promise<void> {\n if (!existingBranchNames || !existingPullRequests) return;\n\n const {\n options: { url, dryRun },\n authorClient,\n } = this;\n for (const pullRequestIndex in existingPullRequests) {\n const pullRequest = existingPullRequests[pullRequestIndex]!;\n const pullRequestSourceRefName = normalizeBranchName(\n pullRequest.properties?.find((x) => x.name === DEVOPS_PR_PROPERTY_MICROSOFT_GIT_SOURCE_REF_NAME)?.value,\n );\n if (pullRequestSourceRefName && !existingBranchNames.includes(pullRequestSourceRefName)) {\n // The source branch for the pull request has been deleted; abandon the pull request (if not dry run)\n if (!dryRun) {\n logger.warn(\n `Detected source branch for PR #${pullRequest.id} has been deleted; The pull request will be abandoned`,\n );\n await authorClient.abandonPullRequest({\n project: url.project,\n repository: url.repository,\n pullRequestId: pullRequest.id,\n // comment:\n // 'OK, I won't notify you again about this release, but will get in touch when a new version is available. ' +\n // 'If you'd rather skip all updates until the next major or minor version, add an ' +\n // '[`ignore` condition](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#ignore--) ' +\n // 'with the desired `update-types` to your config file.',\n comment:\n 'It might be a good idea to add an ' +\n '[`ignore` condition](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#ignore--) ' +\n 'with the desired `update-types` to your config file.',\n });\n }\n // Remove the pull request from the list of existing pull requests to ensures that we don't attempt to update it later in the process.\n existingPullRequests.splice(existingPullRequests.indexOf(pullRequest), 1);\n }\n }\n }\n\n /**\n * Performs the updates.\n * @param server The local Dependabot server.\n * @param updates The updates to perform.\n * @param existingPullRequests The existing pull requests.\n */\n private async performUpdates(\n server: AzureLocalDependabotServer,\n updates: DependabotUpdate[],\n existingPullRequests: IPullRequestProperties[],\n dependabotApiUrl: string,\n dependabotApiDockerUrl?: string,\n command?: DependabotJobConfig['command'],\n ): Promise<RunJobsResult> {\n const {\n options: { url, gitToken, githubToken, experiments, config, dryRun, securityAdvisoriesFile, secretMasker },\n } = this;\n\n const results: RunJobsResult = [];\n\n function makeUsageData(job: DependabotJobConfig): RunJobOptions['usage'] {\n return {\n trigger: 'user',\n provider: job.source.provider,\n owner: url.url.toString(),\n project: `${url.url.toString().replace(/\\/$/, '')}/${url.project}`,\n 'package-manager': job['package-manager'],\n };\n }\n\n for (const update of updates) {\n const packageEcosystem = update['package-ecosystem'];\n const packageManager = mapPackageEcosystemToPackageManager(packageEcosystem);\n\n // If there is an updater image, replace the placeholder in it\n let { updaterImage } = this.options;\n updaterImage = updaterImage?.replace(/\\{ecosystem\\}/i, packageEcosystem);\n\n // Parse the Dependabot metadata for the existing pull requests that are related to this update\n // Dependabot will use this to determine if we need to create new pull requests or update/close existing ones\n const existingPullRequestsForPackageManager = parsePullRequestProperties(existingPullRequests, packageManager);\n const existingPullRequestDependenciesForPackageManager = Object.values(existingPullRequestsForPackageManager);\n\n const builder = new DependabotJobBuilder({\n source: { provider: 'azure', ...url },\n config,\n update,\n systemAccessToken: gitToken,\n githubToken,\n experiments,\n debug: false,\n });\n\n let jobId: number | undefined;\n let job: DependabotJobConfig | undefined;\n let credentials: DependabotCredential[] | undefined;\n let jobToken: string;\n let credentialsToken: string;\n\n // If this is a security-only update (i.e. 'open-pull-requests-limit: 0'), then we first need to discover the dependencies\n // that need updating and check each one for vulnerabilities. This is because Dependabot requires the list of vulnerable dependencies\n // to be supplied in the job definition of security-only update job, it will not automatically discover them like a versioned update does.\n // https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates#overriding-the-default-behavior-with-a-configuration-file\n let securityVulnerabilities: SecurityVulnerability[] = [];\n let dependencyNamesToUpdate: string[] = [];\n const securityUpdatesOnly = update['open-pull-requests-limit'] === 0;\n if (securityUpdatesOnly) {\n // Run an update job to discover all dependencies\n ({ jobId, job, credentials } = builder.forDependenciesList({ command }));\n ({ jobToken, credentialsToken } = this.makeTokens());\n server.add({ id: jobId, update, job, jobToken, credentialsToken, credentials });\n await runJob({\n dependabotApiUrl,\n dependabotApiDockerUrl,\n jobId,\n jobToken,\n credentialsToken,\n updaterImage,\n secretMasker,\n usage: makeUsageData(job),\n });\n\n const outputs = server.requests(jobId);\n const packagesToCheckForVulnerabilities: Package[] | undefined = outputs!\n .find((o) => o.type === 'update_dependency_list')\n ?.data.dependencies?.map((d) => ({ name: d.name, version: d.version }));\n if (packagesToCheckForVulnerabilities?.length) {\n logger.info(\n `Detected ${packagesToCheckForVulnerabilities.length} dependencies; Checking for vulnerabilities...`,\n );\n\n // parse security advisories from file (private)\n if (securityAdvisoriesFile) {\n const filePath = securityAdvisoriesFile;\n if (existsSync(filePath)) {\n const fileContents = await readFile(filePath, 'utf-8');\n securityVulnerabilities = await SecurityVulnerabilitySchema.array().parseAsync(JSON.parse(fileContents));\n } else {\n logger.info(`Private security advisories file '${filePath}' does not exist`);\n }\n }\n if (githubToken) {\n const ghsaClient = new GitHubGraphClient(githubToken);\n const githubVulnerabilities = await ghsaClient.getSecurityVulnerabilitiesAsync(\n getGhsaPackageEcosystemFromDependabotPackageManager(packageManager),\n packagesToCheckForVulnerabilities || [],\n );\n securityVulnerabilities.push(...githubVulnerabilities);\n } else {\n logger.info(\n 'GitHub access token is not provided; Checking for vulnerabilities from GitHub is skipped. ' +\n 'This is not an issue if you are using private security advisories file.',\n );\n }\n\n securityVulnerabilities = filterVulnerabilities(securityVulnerabilities);\n\n // Only update dependencies that have vulnerabilities\n dependencyNamesToUpdate = Array.from(new Set(securityVulnerabilities.map((v) => v.package.name)));\n logger.info(\n `Detected ${securityVulnerabilities.length} vulnerabilities affecting ${dependencyNamesToUpdate.length} dependencies`,\n );\n if (dependencyNamesToUpdate.length) {\n logger.trace(dependencyNamesToUpdate);\n }\n } else {\n logger.info(`No vulnerabilities detected for update ${update['package-ecosystem']} in ${update.directory}`);\n server.clear(jobId);\n continue; // nothing more to do for this update\n }\n\n server.clear(jobId);\n }\n\n // Run an update job for \"all dependencies\"; this will create new pull requests for dependencies that need updating\n const openPullRequestsLimit = update['open-pull-requests-limit']!;\n const openPullRequestsCount = Object.entries(existingPullRequestsForPackageManager).length;\n const hasReachedOpenPullRequestLimit =\n openPullRequestsLimit > 0 && openPullRequestsCount >= openPullRequestsLimit;\n if (!hasReachedOpenPullRequestLimit) {\n const dependenciesHaveVulnerabilities = dependencyNamesToUpdate.length && securityVulnerabilities.length;\n if (!securityUpdatesOnly || dependenciesHaveVulnerabilities) {\n ({ jobId, job, credentials } = builder.forUpdate({\n command,\n dependencyNamesToUpdate,\n existingPullRequests: existingPullRequestDependenciesForPackageManager,\n securityVulnerabilities,\n }));\n ({ jobToken, credentialsToken } = this.makeTokens());\n server.add({ id: jobId, update, job, jobToken, credentialsToken, credentials });\n const { success, message } = await runJob({\n dependabotApiUrl,\n dependabotApiDockerUrl,\n jobId,\n jobToken,\n credentialsToken,\n updaterImage,\n secretMasker,\n usage: makeUsageData(job),\n });\n const affectedPrs = server.allAffectedPrs(jobId);\n server.clear(jobId);\n results.push({ id: jobId, success, message, affectedPrs });\n } else {\n logger.info('Nothing to update; dependencies are not affected by any known vulnerability');\n }\n } else {\n logger.warn(\n `Skipping update for ${packageEcosystem} packages as the open pull requests limit (${openPullRequestsLimit}) has already been reached`,\n );\n }\n\n // If there are existing pull requests, run an update job for each one; this will resolve merge conflicts and close pull requests that are no longer needed\n const numberOfPullRequestsToUpdate = Object.keys(existingPullRequestsForPackageManager).length;\n if (numberOfPullRequestsToUpdate > 0) {\n if (!dryRun) {\n for (const pullRequestId in existingPullRequestsForPackageManager) {\n ({ jobId, job, credentials } = builder.forUpdate({\n command,\n existingPullRequests: existingPullRequestDependenciesForPackageManager,\n pullRequestToUpdate: existingPullRequestsForPackageManager[pullRequestId]!,\n securityVulnerabilities,\n }));\n ({ jobToken, credentialsToken } = this.makeTokens());\n server.add({ id: jobId, update, job, jobToken, credentialsToken, credentials });\n const { success, message } = await runJob({\n dependabotApiUrl,\n dependabotApiDockerUrl,\n jobId,\n jobToken,\n credentialsToken,\n updaterImage,\n secretMasker,\n usage: makeUsageData(job),\n });\n const affectedPrs = server.allAffectedPrs(jobId);\n server.clear(jobId);\n results.push({ id: jobId, success, message, affectedPrs });\n }\n } else {\n logger.warn(\n `Skipping update of ${numberOfPullRequestsToUpdate} existing ${packageEcosystem} package pull request(s) as 'dryRun' is set to 'true'`,\n );\n }\n }\n }\n\n return results;\n }\n}\n"],"mappings":";;;;;;;;;;AA2BA,IAAa,6BAAb,cAAgD,sBAAsB;CAEpE,AAAiB;CAEjB,YAAY,SAA4C;AACtD,QAAM,QAAQ;AACd,OAAK,UAAU;;CAGjB,MAAyB,OAAO,IAAY,SAA8C;AACxF,QAAM,MAAM,OAAO,IAAI,QAAQ;EAE/B,MAAM,EAAE,SAAS,2BAA2B;EAC5C,MAAM,EACJ,KACA,cACA,gBACA,qBACA,sBACA,aACA,eACA,iBACA,6BACA,QACA,OACA,WACE;EAEJ,MAAM,EAAE,MAAM,SAAS;EACvB,MAAM,MAAM,MAAM,KAAK,IAAI,GAAG;AAC9B,MAAI,CAAC,KAAK;AACR,UAAO,MAAM,wBAAwB,GAAG,qCAAqC,KAAK,GAAG;AACrF,UAAO;;EAET,MAAM,EAAE,mBAAmB,mBAAmB;AAC9C,SAAO,KAAK,eAAe,KAAK,gBAAgB,GAAG,GAAG;AACtD,MAAI,MACF,QAAO,MAAM,KAAK,UAAU,KAAK,CAAC;EAGpC,MAAM,SAAS,KAAK,OAAO,GAAG;EAC9B,MAAM,EAAE,SAAS,eAAe;AAEhC,UAAQ,MAAR;GAIE,KAAK,uBAAuB;IAC1B,MAAM,QAAQ,KAAK;AACnB,QAAI,QAAQ;AACV,YAAO,KAAK,sCAAsC,MAAM,gCAAgC;AACxF,YAAO;;IAIT,MAAM,wBAAwB,OAAO;IAIrC,MAAM,wCAAwC,2BAA2B,sBAAsB,eAAe;IAC9G,MAAM,4BAA4B,OAAO,QAAQ,sCAAsC,CAAC;IACxF,MAAM,wBAAwB,uBAAuB,IAAI,GAAG,CAAE,QAAQ,SAAS;AAI/E,QAFE,wBAAwB,KAAK,yBAAyB,uBAEpB;AAClC,YAAO,KACL,sCAAsC,MAAM,qCAAqC,sBAAsB,oBACxG;AACD,YAAO;;I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er, o as LocalJobsRunnerOptions, r as LocalDependabotServerAddOptions, s as RunJobsResult, t as AffectedPullRequestIds } from "../server-Ri18zAcc.js";
|
|
2
|
+
export { AffectedPullRequestIds, LocalDependabotServer, LocalDependabotServerAddOptions, LocalDependabotServerOptions, LocalJobsRunner, LocalJobsRunnerOptions, RunJobsResult };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { t as logger } from "./logger-Bekleunx.js";
|
|
2
|
+
import { createApiServerApp, makeRandomJobToken } from "@paklo/core/dependabot";
|
|
3
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
4
|
+
|
|
5
|
+
//#region src/local/runner.ts
|
|
6
|
+
var LocalJobsRunner = class {
|
|
7
|
+
opt;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.opt = options;
|
|
10
|
+
}
|
|
11
|
+
makeTokens() {
|
|
12
|
+
const { jobTokenOverride, credentialsTokenOverride } = this.opt;
|
|
13
|
+
return {
|
|
14
|
+
jobToken: jobTokenOverride ?? makeRandomJobToken(),
|
|
15
|
+
credentialsToken: credentialsTokenOverride ?? makeRandomJobToken()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
run() {
|
|
19
|
+
return Promise.resolve([{
|
|
20
|
+
id: -1,
|
|
21
|
+
success: false,
|
|
22
|
+
affectedPrs: []
|
|
23
|
+
}]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/local/server.ts
|
|
29
|
+
var LocalDependabotServer = class {
|
|
30
|
+
hostname = "localhost";
|
|
31
|
+
server;
|
|
32
|
+
trackedJobs = /* @__PURE__ */ new Map();
|
|
33
|
+
updates = /* @__PURE__ */ new Map();
|
|
34
|
+
jobTokens = /* @__PURE__ */ new Map();
|
|
35
|
+
credentialTokens = /* @__PURE__ */ new Map();
|
|
36
|
+
jobCredentials = /* @__PURE__ */ new Map();
|
|
37
|
+
receivedRequests = /* @__PURE__ */ new Map();
|
|
38
|
+
affectedPullRequestIds = /* @__PURE__ */ new Map();
|
|
39
|
+
constructor(options) {
|
|
40
|
+
const app = createApiServerApp({
|
|
41
|
+
...options,
|
|
42
|
+
authenticate: this.authenticate.bind(this),
|
|
43
|
+
getJob: this.job.bind(this),
|
|
44
|
+
getCredentials: this.credentials.bind(this),
|
|
45
|
+
handle: this.handle.bind(this)
|
|
46
|
+
});
|
|
47
|
+
this.server = createAdaptorServer({
|
|
48
|
+
...app,
|
|
49
|
+
fetch: (req) => {
|
|
50
|
+
const url = new URL(req.url);
|
|
51
|
+
url.protocol = req.headers.get("x-forwarded-proto") ?? url.protocol;
|
|
52
|
+
return app.fetch(new Request(url, req));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
start(port) {
|
|
57
|
+
this.server.listen(port, "0.0.0.0", () => {
|
|
58
|
+
const info = this.server.address();
|
|
59
|
+
logger.info(`API server listening on http://${this.hostname}:${info.port}`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
stop() {
|
|
63
|
+
this.server.close(() => logger.info("API server closed"));
|
|
64
|
+
}
|
|
65
|
+
get url() {
|
|
66
|
+
const info = this.server.address();
|
|
67
|
+
return `http://${this.hostname}:${info.port}`;
|
|
68
|
+
}
|
|
69
|
+
get port() {
|
|
70
|
+
return this.server.address().port;
|
|
71
|
+
}
|
|
72
|
+
get jobs() {
|
|
73
|
+
return this.trackedJobs;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a dependabot job.
|
|
77
|
+
* @param value - The dependabot job details.
|
|
78
|
+
*/
|
|
79
|
+
add(value) {
|
|
80
|
+
const { id, update, job, jobToken, credentialsToken, credentials } = value;
|
|
81
|
+
const { trackedJobs, updates, jobTokens, credentialTokens, jobCredentials, receivedRequests, affectedPullRequestIds } = this;
|
|
82
|
+
trackedJobs.set(id, job);
|
|
83
|
+
updates.set(id, update);
|
|
84
|
+
jobTokens.set(id, jobToken);
|
|
85
|
+
credentialTokens.set(id, credentialsToken);
|
|
86
|
+
jobCredentials.set(id, credentials);
|
|
87
|
+
receivedRequests.set(id, []);
|
|
88
|
+
affectedPullRequestIds.set(id, {
|
|
89
|
+
created: [],
|
|
90
|
+
updated: [],
|
|
91
|
+
closed: []
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets a dependabot job by ID.
|
|
96
|
+
* @param id - The ID of the dependabot job to get.
|
|
97
|
+
* @returns The dependabot job, or undefined if not found.
|
|
98
|
+
*/
|
|
99
|
+
job(id) {
|
|
100
|
+
return Promise.resolve(this.trackedJobs.get(id));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets a dependabot update by ID of the job.
|
|
104
|
+
* @param id - The ID of the dependabot job to get.
|
|
105
|
+
* @returns The dependabot update, or undefined if not found.
|
|
106
|
+
*/
|
|
107
|
+
update(id) {
|
|
108
|
+
return this.updates.get(id);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets a token by ID of the job.
|
|
112
|
+
* @param id - The ID of the dependabot job to get.
|
|
113
|
+
* @returns The job token, or undefined if not found.
|
|
114
|
+
*/
|
|
115
|
+
token(id, type) {
|
|
116
|
+
return type === "job" ? this.jobTokens.get(id) : this.credentialTokens.get(id);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the credentials for a dependabot job by ID.
|
|
120
|
+
* @param id - The ID of the dependabot job to get credentials for.
|
|
121
|
+
* @returns The credentials for the job, or undefined if not found.
|
|
122
|
+
*/
|
|
123
|
+
credentials(id) {
|
|
124
|
+
return Promise.resolve(this.jobCredentials.get(id));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets the received requests for a dependabot job by ID.
|
|
128
|
+
* @param id - The ID of the dependabot job to get requests for.
|
|
129
|
+
* @returns The received requests for the job, or undefined if not found.
|
|
130
|
+
*/
|
|
131
|
+
requests(id) {
|
|
132
|
+
return this.receivedRequests.get(id);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the IDs of pull requests affected by a dependabot job by ID.
|
|
136
|
+
* @param id - The ID of the dependabot job to get affected pull request IDs for.
|
|
137
|
+
* @returns The affected pull request IDs for the job, or undefined if not found.
|
|
138
|
+
*/
|
|
139
|
+
affectedPrs(id) {
|
|
140
|
+
const { affectedPullRequestIds } = this;
|
|
141
|
+
return affectedPullRequestIds.get(id);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gets all IDs of pull requests affected by a dependabot job by ID.
|
|
145
|
+
* @param id - The ID of the dependabot job to get affected pull request IDs for.
|
|
146
|
+
* @returns The affected pull request IDs for the job, or undefined if not found.
|
|
147
|
+
*/
|
|
148
|
+
allAffectedPrs(id) {
|
|
149
|
+
const affected = this.affectedPrs(id);
|
|
150
|
+
if (!affected) return [];
|
|
151
|
+
return [
|
|
152
|
+
...affected.created,
|
|
153
|
+
...affected.updated,
|
|
154
|
+
...affected.closed
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Clears all data associated with a dependabot job by ID.
|
|
159
|
+
* This should be called when the job is no longer needed.
|
|
160
|
+
* @param id - The ID of the dependabot job to clear.
|
|
161
|
+
*/
|
|
162
|
+
clear(id) {
|
|
163
|
+
this.trackedJobs.delete(id);
|
|
164
|
+
this.updates.delete(id);
|
|
165
|
+
this.jobTokens.delete(id);
|
|
166
|
+
this.credentialTokens.delete(id);
|
|
167
|
+
this.jobCredentials.delete(id);
|
|
168
|
+
this.receivedRequests.delete(id);
|
|
169
|
+
this.affectedPullRequestIds.delete(id);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Authenticates a dependabot job.
|
|
173
|
+
* @param id - The ID of the dependabot job.
|
|
174
|
+
* @param value - The authentication value (e.g., API key).
|
|
175
|
+
* @returns A promise that resolves to a boolean indicating whether the authentication was successful.
|
|
176
|
+
*/
|
|
177
|
+
async authenticate(type, id, value) {
|
|
178
|
+
const token = type === "job" ? this.jobTokens.get(id) : this.credentialTokens.get(id);
|
|
179
|
+
if (!token) {
|
|
180
|
+
logger.debug(`Authentication failed: ${type} token ${id} not found`);
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (token !== value) {
|
|
184
|
+
logger.debug(`Authentication failed: invalid token for ${type} token ${id}`);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Handles a dependabot request.
|
|
191
|
+
* @param id - The ID of the dependabot job.
|
|
192
|
+
* @param request - The dependabot request to handle.
|
|
193
|
+
* @returns A promise that resolves to the result of handling the request.
|
|
194
|
+
*/
|
|
195
|
+
handle(id, request) {
|
|
196
|
+
this.receivedRequests.get(id).push(request);
|
|
197
|
+
return Promise.resolve(true);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
export { LocalJobsRunner as n, LocalDependabotServer as t };
|
|
203
|
+
//# sourceMappingURL=server-Dcc7bD60.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-Dcc7bD60.js","names":[],"sources":["../src/local/runner.ts","../src/local/server.ts"],"sourcesContent":["import {\n type DependabotConfig,\n type DependabotExperiments,\n type DependabotJobConfig,\n makeRandomJobToken,\n} from '@paklo/core/dependabot';\nimport type { SecretMasker } from '@paklo/runner';\n\nexport type RunJobsResult = { id: number; success: boolean; message?: string; affectedPrs: number[] }[];\n\nexport type LocalJobsRunnerOptions = {\n jobTokenOverride?: string;\n credentialsTokenOverride?: string;\n secretMasker: SecretMasker;\n\n config: DependabotConfig;\n targetUpdateIds?: number[];\n experiments: DependabotExperiments;\n updaterImage?: string;\n command?: DependabotJobConfig['command'];\n};\n\nexport abstract class LocalJobsRunner {\n private readonly opt: LocalJobsRunnerOptions;\n\n constructor(options: LocalJobsRunnerOptions) {\n this.opt = options;\n }\n\n protected makeTokens() {\n const { jobTokenOverride, credentialsTokenOverride } = this.opt;\n return {\n jobToken: jobTokenOverride ?? makeRandomJobToken(),\n credentialsToken: credentialsTokenOverride ?? makeRandomJobToken(),\n };\n }\n\n public run(): Promise<RunJobsResult> {\n return Promise.resolve([{ id: -1, success: false, affectedPrs: [] }]);\n }\n}\n","import type { AddressInfo } from 'node:net';\nimport { createAdaptorServer } from '@hono/node-server';\nimport {\n type CreateApiServerAppOptions,\n createApiServerApp,\n type DependabotCredential,\n type DependabotJobConfig,\n type DependabotRequest,\n type DependabotTokenType,\n type DependabotUpdate,\n type GitAuthor,\n} from '@paklo/core/dependabot';\nimport { logger } from '@/logger';\n\nexport type LocalDependabotServerAddOptions = {\n /** The ID of the dependabot job. */\n id: number;\n /** The dependabot update associated with the job. */\n update: DependabotUpdate;\n /** The dependabot job configuration. */\n job: DependabotJobConfig;\n /** The authentication token for the job. */\n jobToken: string;\n /** The authentication token for the job. */\n credentialsToken: string;\n /** The credentials associated with the job. */\n credentials: DependabotCredential[];\n};\n\nexport type AffectedPullRequestIds = {\n created: number[];\n updated: number[];\n closed: number[];\n};\n\nexport type LocalDependabotServerOptions = Omit<\n CreateApiServerAppOptions,\n 'authenticate' | 'getJob' | 'getCredentials' | 'handle'\n> & {\n author: GitAuthor;\n debug: boolean;\n dryRun: boolean;\n};\nexport abstract class LocalDependabotServer {\n private readonly hostname = 'localhost';\n private readonly server: ReturnType<typeof createAdaptorServer>;\n private readonly trackedJobs = new Map<number, DependabotJobConfig>();\n private readonly updates = new Map<number, DependabotUpdate>();\n private readonly jobTokens = new Map<number, string>();\n private readonly credentialTokens = new Map<number, string>();\n private readonly jobCredentials = new Map<number, DependabotCredential[]>();\n private readonly receivedRequests = new Map<number, DependabotRequest[]>();\n\n protected readonly affectedPullRequestIds = new Map<number, AffectedPullRequestIds>();\n\n constructor(options: LocalDependabotServerOptions) {\n const app = createApiServerApp({\n ...options,\n authenticate: this.authenticate.bind(this),\n getJob: this.job.bind(this),\n getCredentials: this.credentials.bind(this),\n handle: this.handle.bind(this),\n });\n this.server = createAdaptorServer({\n ...app,\n // Workaround for hono not respecting x-forwarded-proto header\n // https://github.com/honojs/node-server/issues/146#issuecomment-3153435672\n fetch: (req) => {\n const url = new URL(req.url);\n url.protocol = req.headers.get('x-forwarded-proto') ?? url.protocol;\n return app.fetch(new Request(url, req));\n },\n });\n }\n\n start(port?: number) {\n // listening to 'localhost' will result to IpV6 only but we need it to be all local\n // interfaces, otherwise containers cannot reach it using host.docker.internal\n this.server.listen(port, '0.0.0.0', () => {\n const info = this.server.address() as AddressInfo;\n logger.info(`API server listening on http://${this.hostname}:${info.port}`);\n });\n }\n\n stop() {\n this.server.close(() => logger.info('API server closed'));\n }\n\n get url() {\n const info = this.server.address() as AddressInfo;\n return `http://${this.hostname}:${info.port}`;\n }\n\n get port() {\n const info = this.server.address() as AddressInfo;\n return info.port;\n }\n\n get jobs() {\n return this.trackedJobs;\n }\n\n /**\n * Adds a dependabot job.\n * @param value - The dependabot job details.\n */\n add(value: LocalDependabotServerAddOptions) {\n const { id, update, job, jobToken, credentialsToken, credentials } = value;\n const {\n trackedJobs,\n updates,\n jobTokens,\n credentialTokens,\n jobCredentials,\n receivedRequests,\n affectedPullRequestIds,\n } = this;\n trackedJobs.set(id, job);\n updates.set(id, update);\n jobTokens.set(id, jobToken);\n credentialTokens.set(id, credentialsToken);\n jobCredentials.set(id, credentials);\n receivedRequests.set(id, []);\n affectedPullRequestIds.set(id, { created: [], updated: [], closed: [] });\n }\n\n /**\n * Gets a dependabot job by ID.\n * @param id - The ID of the dependabot job to get.\n * @returns The dependabot job, or undefined if not found.\n */\n job(id: number): Promise<DependabotJobConfig | undefined> {\n return Promise.resolve(this.trackedJobs.get(id));\n }\n\n /**\n * Gets a dependabot update by ID of the job.\n * @param id - The ID of the dependabot job to get.\n * @returns The dependabot update, or undefined if not found.\n */\n update(id: number): DependabotUpdate | undefined {\n return this.updates.get(id);\n }\n\n /**\n * Gets a token by ID of the job.\n * @param id - The ID of the dependabot job to get.\n * @returns The job token, or undefined if not found.\n */\n token(id: number, type: DependabotTokenType): string | undefined {\n return type === 'job' ? this.jobTokens.get(id) : this.credentialTokens.get(id);\n }\n\n /**\n * Gets the credentials for a dependabot job by ID.\n * @param id - The ID of the dependabot job to get credentials for.\n * @returns The credentials for the job, or undefined if not found.\n */\n credentials(id: number): Promise<DependabotCredential[] | undefined> {\n return Promise.resolve(this.jobCredentials.get(id));\n }\n\n /**\n * Gets the received requests for a dependabot job by ID.\n * @param id - The ID of the dependabot job to get requests for.\n * @returns The received requests for the job, or undefined if not found.\n */\n requests(id: number): DependabotRequest[] | undefined {\n return this.receivedRequests.get(id);\n }\n\n /**\n * Gets the IDs of pull requests affected by a dependabot job by ID.\n * @param id - The ID of the dependabot job to get affected pull request IDs for.\n * @returns The affected pull request IDs for the job, or undefined if not found.\n */\n affectedPrs(id: number): AffectedPullRequestIds | undefined {\n const { affectedPullRequestIds } = this;\n return affectedPullRequestIds.get(id);\n }\n\n /**\n * Gets all IDs of pull requests affected by a dependabot job by ID.\n * @param id - The ID of the dependabot job to get affected pull request IDs for.\n * @returns The affected pull request IDs for the job, or undefined if not found.\n */\n allAffectedPrs(id: number): number[] {\n const affected = this.affectedPrs(id);\n if (!affected) return [];\n return [...affected.created, ...affected.updated, ...affected.closed];\n }\n\n /**\n * Clears all data associated with a dependabot job by ID.\n * This should be called when the job is no longer needed.\n * @param id - The ID of the dependabot job to clear.\n */\n clear(id: number) {\n this.trackedJobs.delete(id);\n this.updates.delete(id);\n this.jobTokens.delete(id);\n this.credentialTokens.delete(id);\n this.jobCredentials.delete(id);\n this.receivedRequests.delete(id);\n this.affectedPullRequestIds.delete(id);\n }\n\n /**\n * Authenticates a dependabot job.\n * @param id - The ID of the dependabot job.\n * @param value - The authentication value (e.g., API key).\n * @returns A promise that resolves to a boolean indicating whether the authentication was successful.\n */\n protected async authenticate(type: DependabotTokenType, id: number, value: string): Promise<boolean> {\n const token = type === 'job' ? this.jobTokens.get(id) : this.credentialTokens.get(id);\n if (!token) {\n logger.debug(`Authentication failed: ${type} token ${id} not found`);\n return false;\n }\n if (token !== value) {\n logger.debug(`Authentication failed: invalid token for ${type} token ${id}`);\n return false;\n }\n return true;\n }\n\n /**\n * Handles a dependabot request.\n * @param id - The ID of the dependabot job.\n * @param request - The dependabot request to handle.\n * @returns A promise that resolves to the result of handling the request.\n */\n protected handle(id: number, request: DependabotRequest): Promise<boolean> {\n this.receivedRequests.get(id)!.push(request);\n return Promise.resolve(true);\n }\n}\n"],"mappings":";;;;;AAsBA,IAAsB,kBAAtB,MAAsC;CACpC,AAAiB;CAEjB,YAAY,SAAiC;AAC3C,OAAK,MAAM;;CAGb,AAAU,aAAa;EACrB,MAAM,EAAE,kBAAkB,6BAA6B,KAAK;AAC5D,SAAO;GACL,UAAU,oBAAoB,oBAAoB;GAClD,kBAAkB,4BAA4B,oBAAoB;GACnE;;CAGH,AAAO,MAA8B;AACnC,SAAO,QAAQ,QAAQ,CAAC;GAAE,IAAI;GAAI,SAAS;GAAO,aAAa,EAAE;GAAE,CAAC,CAAC;;;;;;ACKzE,IAAsB,wBAAtB,MAA4C;CAC1C,AAAiB,WAAW;CAC5B,AAAiB;CACjB,AAAiB,8BAAc,IAAI,KAAkC;CACrE,AAAiB,0BAAU,IAAI,KAA+B;CAC9D,AAAiB,4BAAY,IAAI,KAAqB;CACtD,AAAiB,mCAAmB,IAAI,KAAqB;CAC7D,AAAiB,iCAAiB,IAAI,KAAqC;CAC3E,AAAiB,mCAAmB,IAAI,KAAkC;CAE1E,AAAmB,yCAAyB,IAAI,KAAqC;CAErF,YAAY,SAAuC;EACjD,MAAM,MAAM,mBAAmB;GAC7B,GAAG;GACH,cAAc,KAAK,aAAa,KAAK,KAAK;GAC1C,QAAQ,KAAK,IAAI,KAAK,KAAK;GAC3B,gBAAgB,KAAK,YAAY,KAAK,KAAK;GAC3C,QAAQ,KAAK,OAAO,KAAK,KAAK;GAC/B,CAAC;AACF,OAAK,SAAS,oBAAoB;GAChC,GA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ppOptions, DependabotConfig, DependabotCredential, DependabotExperiments, DependabotJobConfig, DependabotRequest, DependabotTokenType, DependabotUpdate, GitAuthor } from "@paklo/core/dependabot";
|
|
2
|
+
import { SecretMasker } from "@paklo/runner";
|
|
3
|
+
|
|
4
|
+
//#region src/local/runner.d.ts
|
|
5
|
+
type RunJobsResult = {
|
|
6
|
+
id: number;
|
|
7
|
+
success: boolean;
|
|
8
|
+
message?: string;
|
|
9
|
+
affectedPrs: number[];
|
|
10
|
+
}[];
|
|
11
|
+
type LocalJobsRunnerOptions = {
|
|
12
|
+
jobTokenOverride?: string;
|
|
13
|
+
credentialsTokenOverride?: string;
|
|
14
|
+
secretMasker: SecretMasker;
|
|
15
|
+
config: DependabotConfig;
|
|
16
|
+
targetUpdateIds?: number[];
|
|
17
|
+
experiments: DependabotExperiments;
|
|
18
|
+
updaterImage?: string;
|
|
19
|
+
command?: DependabotJobConfig['command'];
|
|
20
|
+
};
|
|
21
|
+
declare abstract class LocalJobsRunner {
|
|
22
|
+
private readonly opt;
|
|
23
|
+
constructor(options: LocalJobsRunnerOptions);
|
|
24
|
+
protected makeTokens(): {
|
|
25
|
+
jobToken: string;
|
|
26
|
+
credentialsToken: string;
|
|
27
|
+
};
|
|
28
|
+
run(): Promise<RunJobsResult>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/local/server.d.ts
|
|
32
|
+
type LocalDependabotServerAddOptions = {
|
|
33
|
+
/** The ID of the dependabot job. */
|
|
34
|
+
id: number;
|
|
35
|
+
/** The dependabot update associated with the job. */
|
|
36
|
+
update: DependabotUpdate;
|
|
37
|
+
/** The dependabot job configuration. */
|
|
38
|
+
job: DependabotJobConfig;
|
|
39
|
+
/** The authentication token for the job. */
|
|
40
|
+
jobToken: string;
|
|
41
|
+
/** The authentication token for the job. */
|
|
42
|
+
credentialsToken: string;
|
|
43
|
+
/** The credentials associated with the job. */
|
|
44
|
+
credentials: DependabotCredential[];
|
|
45
|
+
};
|
|
46
|
+
type AffectedPullRequestIds = {
|
|
47
|
+
created: number[];
|
|
48
|
+
updated: number[];
|
|
49
|
+
closed: number[];
|
|
50
|
+
};
|
|
51
|
+
type LocalDependabotServerOptions = Omit<CreateApiServerAppOptions, 'authenticate' | 'getJob' | 'getCredentials' | 'handle'> & {
|
|
52
|
+
author: GitAuthor;
|
|
53
|
+
debug: boolean;
|
|
54
|
+
dryRun: boolean;
|
|
55
|
+
};
|
|
56
|
+
declare abstract class LocalDependabotServer {
|
|
57
|
+
private readonly hostname;
|
|
58
|
+
private readonly server;
|
|
59
|
+
private readonly trackedJobs;
|
|
60
|
+
private readonly updates;
|
|
61
|
+
private readonly jobTokens;
|
|
62
|
+
private readonly credentialTokens;
|
|
63
|
+
private readonly jobCredentials;
|
|
64
|
+
private readonly receivedRequests;
|
|
65
|
+
protected readonly affectedPullRequestIds: Map<number, AffectedPullRequestIds>;
|
|
66
|
+
constructor(options: LocalDependabotServerOptions);
|
|
67
|
+
start(port?: number): void;
|
|
68
|
+
stop(): void;
|
|
69
|
+
get url(): string;
|
|
70
|
+
get port(): number;
|
|
71
|
+
get jobs(): Map<number, {
|
|
72
|
+
'package-manager': "bun" | "bundler" | "cargo" | "composer" | "devcontainers" | "docker" | "docker_compose" | "dotnet_sdk" | "helm" | "hex" | "elm" | "submodules" | "github_actions" | "go_modules" | "gradle" | "maven" | "npm_and_yarn" | "nuget" | "pip" | "pub" | "swift" | "terraform" | "uv";
|
|
73
|
+
'allowed-updates': {
|
|
74
|
+
'dependency-name'?: string | null | undefined;
|
|
75
|
+
'dependency-type'?: string | null | undefined;
|
|
76
|
+
'update-type'?: "all" | "security" | undefined;
|
|
77
|
+
}[];
|
|
78
|
+
debug: boolean | null;
|
|
79
|
+
dependencies: string[] | null;
|
|
80
|
+
'existing-pull-requests': {
|
|
81
|
+
'dependency-name': string;
|
|
82
|
+
'dependency-version'?: string | null | undefined;
|
|
83
|
+
directory?: string | null | undefined;
|
|
84
|
+
removed?: boolean | null | undefined;
|
|
85
|
+
}[][];
|
|
86
|
+
'existing-group-pull-requests': {
|
|
87
|
+
'dependency-group-name': string;
|
|
88
|
+
dependencies: {
|
|
89
|
+
'dependency-name': string;
|
|
90
|
+
'dependency-version'?: string | null | undefined;
|
|
91
|
+
directory?: string | null | undefined;
|
|
92
|
+
removed?: boolean | null | undefined;
|
|
93
|
+
}[];
|
|
94
|
+
}[];
|
|
95
|
+
experiments: Record<string, string | boolean>;
|
|
96
|
+
'ignore-conditions': {
|
|
97
|
+
'dependency-name': string;
|
|
98
|
+
source?: string | null | undefined;
|
|
99
|
+
'update-types'?: string[] | null | undefined;
|
|
100
|
+
'updated-at'?: string | null | undefined;
|
|
101
|
+
'version-requirement'?: string | null | undefined;
|
|
102
|
+
}[];
|
|
103
|
+
'lockfile-only': boolean;
|
|
104
|
+
'requirements-update-strategy': string | null;
|
|
105
|
+
'security-advisories': {
|
|
106
|
+
'dependency-name': string;
|
|
107
|
+
'affected-versions': string[];
|
|
108
|
+
'unaffected-versions': string[];
|
|
109
|
+
'patched-versions'?: string[] | null | undefined;
|
|
110
|
+
}[];
|
|
111
|
+
'security-updates-only': boolean;
|
|
112
|
+
source: {
|
|
113
|
+
provider: "azure";
|
|
114
|
+
repo: string;
|
|
115
|
+
directory?: string | null | undefined;
|
|
116
|
+
directories?: string[] | null | undefined;
|
|
117
|
+
branch?: string | null | undefined;
|
|
118
|
+
commit?: string | null | undefined;
|
|
119
|
+
hostname?: string | null | undefined;
|
|
120
|
+
'api-endpoint'?: string | null | undefined;
|
|
121
|
+
};
|
|
122
|
+
'update-subdependencies': boolean;
|
|
123
|
+
'updating-a-pull-request': boolean;
|
|
124
|
+
'vendor-dependencies': boolean;
|
|
125
|
+
'repo-private': boolean;
|
|
126
|
+
'commit-message-options': {
|
|
127
|
+
prefix?: string | null | undefined;
|
|
128
|
+
'prefix-development'?: string | null | undefined;
|
|
129
|
+
'include-scope'?: boolean | null | undefined;
|
|
130
|
+
};
|
|
131
|
+
id?: number | undefined;
|
|
132
|
+
command?: "version" | "graph" | "recreate" | undefined;
|
|
133
|
+
'dependency-groups'?: {
|
|
134
|
+
name: string;
|
|
135
|
+
rules: {
|
|
136
|
+
patterns?: string[] | null | undefined;
|
|
137
|
+
'exclude-patterns'?: string[] | null | undefined;
|
|
138
|
+
'dependency-type'?: string | null | undefined;
|
|
139
|
+
'update-types'?: string[] | null | undefined;
|
|
140
|
+
};
|
|
141
|
+
'applies-to'?: string | null | undefined;
|
|
142
|
+
}[] | null | undefined;
|
|
143
|
+
'dependency-group-to-refresh'?: string | null | undefined;
|
|
144
|
+
'reject-external-code'?: boolean | null | undefined;
|
|
145
|
+
'credentials-metadata'?: Record<string, any>[] | null | undefined;
|
|
146
|
+
'max-updater-run-time'?: number | null | undefined;
|
|
147
|
+
cooldown?: {
|
|
148
|
+
'default-days'?: number | undefined;
|
|
149
|
+
'semver-major-days'?: number | undefined;
|
|
150
|
+
'semver-minor-days'?: number | undefined;
|
|
151
|
+
'semver-patch-days'?: number | undefined;
|
|
152
|
+
include?: string[] | undefined;
|
|
153
|
+
exclude?: string[] | undefined;
|
|
154
|
+
} | null | undefined;
|
|
155
|
+
'proxy-log-response-body-on-auth-failure'?: boolean | null | undefined;
|
|
156
|
+
'enable-beta-ecosystems'?: boolean | null | undefined;
|
|
157
|
+
'multi-ecosystem-update'?: boolean | null | undefined;
|
|
158
|
+
}>;
|
|
159
|
+
/**
|
|
160
|
+
* Adds a dependabot job.
|
|
161
|
+
* @param value - The dependabot job details.
|
|
162
|
+
*/
|
|
163
|
+
add(value: LocalDependabotServerAddOptions): void;
|
|
164
|
+
/**
|
|
165
|
+
* Gets a dependabot job by ID.
|
|
166
|
+
* @param id - The ID of the dependabot job to get.
|
|
167
|
+
* @returns The dependabot job, or undefined if not found.
|
|
168
|
+
*/
|
|
169
|
+
job(id: number): Promise<DependabotJobConfig | undefined>;
|
|
170
|
+
/**
|
|
171
|
+
* Gets a dependabot update by ID of the job.
|
|
172
|
+
* @param id - The ID of the dependabot job to get.
|
|
173
|
+
* @returns The dependabot update, or undefined if not found.
|
|
174
|
+
*/
|
|
175
|
+
update(id: number): DependabotUpdate | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Gets a token by ID of the job.
|
|
178
|
+
* @param id - The ID of the dependabot job to get.
|
|
179
|
+
* @returns The job token, or undefined if not found.
|
|
180
|
+
*/
|
|
181
|
+
token(id: number, type: DependabotTokenType): string | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Gets the credentials for a dependabot job by ID.
|
|
184
|
+
* @param id - The ID of the dependabot job to get credentials for.
|
|
185
|
+
* @returns The credentials for the job, or undefined if not found.
|
|
186
|
+
*/
|
|
187
|
+
credentials(id: number): Promise<DependabotCredential[] | undefined>;
|
|
188
|
+
/**
|
|
189
|
+
* Gets the received requests for a dependabot job by ID.
|
|
190
|
+
* @param id - The ID of the dependabot job to get requests for.
|
|
191
|
+
* @returns The received requests for the job, or undefined if not found.
|
|
192
|
+
*/
|
|
193
|
+
requests(id: number): DependabotRequest[] | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Gets the IDs of pull requests affected by a dependabot job by ID.
|
|
196
|
+
* @param id - The ID of the dependabot job to get affected pull request IDs for.
|
|
197
|
+
* @returns The affected pull request IDs for the job, or undefined if not found.
|
|
198
|
+
*/
|
|
199
|
+
affectedPrs(id: number): AffectedPullRequestIds | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Gets all IDs of pull requests affected by a dependabot job by ID.
|
|
202
|
+
* @param id - The ID of the dependabot job to get affected pull request IDs for.
|
|
203
|
+
* @returns The affected pull request IDs for the job, or undefined if not found.
|
|
204
|
+
*/
|
|
205
|
+
allAffectedPrs(id: number): number[];
|
|
206
|
+
/**
|
|
207
|
+
* Clears all data associated with a dependabot job by ID.
|
|
208
|
+
* This should be called when the job is no longer needed.
|
|
209
|
+
* @param id - The ID of the dependabot job to clear.
|
|
210
|
+
*/
|
|
211
|
+
clear(id: number): void;
|
|
212
|
+
/**
|
|
213
|
+
* Authenticates a dependabot job.
|
|
214
|
+
* @param id - The ID of the dependabot job.
|
|
215
|
+
* @param value - The authentication value (e.g., API key).
|
|
216
|
+
* @returns A promise that resolves to a boolean indicating whether the authentication was successful.
|
|
217
|
+
*/
|
|
218
|
+
protected authenticate(type: DependabotTokenType, id: number, value: string): Promise<boolean>;
|
|
219
|
+
/**
|
|
220
|
+
* Handles a dependabot request.
|
|
221
|
+
* @param id - The ID of the dependabot job.
|
|
222
|
+
* @param request - The dependabot request to handle.
|
|
223
|
+
* @returns A promise that resolves to the result of handling the request.
|
|
224
|
+
*/
|
|
225
|
+
protected handle(id: number, request: DependabotRequest): Promise<boolean>;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { LocalJobsRunner as a, LocalDependabotServerOptions as i, LocalDependabotServer as n, LocalJobsRunnerOptions as o, LocalDependabotServerAddOptions as r, RunJobsResult as s, AffectedPullRequestIds as t };
|
|
229
|
+
//# sourceMappingURL=server-Ri18zAcc.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paklo/runner",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "mburumaxwell",
|
|
7
|
+
"license": "AGPL-3.0-later",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./local": {
|
|
14
|
+
"types": "./dist/local/index.d.ts",
|
|
15
|
+
"import": "./dist/local/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./local/azure": {
|
|
18
|
+
"types": "./dist/local/azure.d.ts",
|
|
19
|
+
"import": "./dist/local/azure.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"package.json"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/mburumaxwell/dependabot-azure-devops.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"dependabot",
|
|
32
|
+
"azure",
|
|
33
|
+
"devops",
|
|
34
|
+
"paklo"
|
|
35
|
+
],
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/mburumaxwell/dependabot-azure-devops/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/mburumaxwell/dependabot-azure-devops#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@hono/node-server": "1.19.5",
|
|
42
|
+
"dockerode": "4.0.9",
|
|
43
|
+
"node-forge": "1.3.1",
|
|
44
|
+
"tar-stream": "3.1.7",
|
|
45
|
+
"@paklo/core": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/dockerode": "3.3.44",
|
|
49
|
+
"@types/node": "24.8.1",
|
|
50
|
+
"@types/node-forge": "1.3.14",
|
|
51
|
+
"@types/tar-stream": "3.1.4",
|
|
52
|
+
"tsdown": "0.15.8"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"postinstall": "tsdown",
|
|
59
|
+
"dev": "tsdown --watch",
|
|
60
|
+
"prebuild": "tsc",
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"lint": "biome check",
|
|
63
|
+
"test": "vitest",
|
|
64
|
+
"clean": "rimraf .turbo dist"
|
|
65
|
+
}
|
|
66
|
+
}
|