From 61f43d0abd23e4427ca81b33e997b3f39935b08e Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 29 May 2024 22:20:57 -0300 Subject: [PATCH 1/2] improve from-issue --- .blueprint/from-issue/command.mts | 18 +- .blueprint/from-issue/generator.mjs | 156 ---------- .blueprint/from-issue/generator.mts | 125 ++++++++ cli/environment-builder.mjs | 6 + cli/program.mjs | 3 +- generators/base-core/generator.ts | 15 +- generators/base/internal/command.ts | 16 + generators/base/internal/index.ts | 1 + generators/info/support/extract-info.ts | 72 +++++ generators/info/support/index.ts | 1 + package-lock.json | 376 +----------------------- package.json | 1 - testing/github.ts | 34 +++ testing/index.ts | 2 + testing/sample-config.ts | 40 +++ 15 files changed, 329 insertions(+), 537 deletions(-) delete mode 100644 .blueprint/from-issue/generator.mjs create mode 100644 .blueprint/from-issue/generator.mts create mode 100644 generators/base/internal/command.ts create mode 100644 generators/info/support/extract-info.ts create mode 100644 testing/github.ts create mode 100644 testing/sample-config.ts diff --git a/.blueprint/from-issue/command.mts b/.blueprint/from-issue/command.mts index 1b2519f86ccb..0e2b0a50c53f 100644 --- a/.blueprint/from-issue/command.mts +++ b/.blueprint/from-issue/command.mts @@ -18,11 +18,25 @@ */ import { JHipsterCommandDefinition } from '../../generators/base/api.js'; import { GENERATOR_APP, GENERATOR_WORKSPACES } from '../../generators/generator-list.js'; +import { parseIssue } from '../../testing/github.js'; const command: JHipsterCommandDefinition = { - arguments: { + configs: { issue: { - type: String, + argument: { + type: String, + description: 'Github issue to generate', + }, + configure(gen: any) { + // Gets the owner, repo and issue_number from a string such as, "jhipster/generator-jhipster#12345" + const parsedIssue = parseIssue(gen.issue); + if (parsedIssue) { + gen.owner = parsedIssue.owner; + gen.repository = parsedIssue.repository; + gen.issue = parsedIssue.issue; + } + }, + scope: 'generator', }, }, options: { diff --git a/.blueprint/from-issue/generator.mjs b/.blueprint/from-issue/generator.mjs deleted file mode 100644 index b89ffcfd6a10..000000000000 --- a/.blueprint/from-issue/generator.mjs +++ /dev/null @@ -1,156 +0,0 @@ -import { Octokit } from 'octokit'; -import { setOutput } from '@actions/core'; -import BaseGenerator from '../../generators/base/index.js'; -import { promptSamplesFolder } from '../support.mjs'; -import { join } from 'path'; -import { GENERATOR_APP, GENERATOR_JDL } from '../../generators/generator-list.js'; -import { GENERATOR_JHIPSTER } from '../../generators/generator-constants.js'; -import { CLI_NAME } from '../../cli/utils.mjs'; -import EnvironmentBuilder from '../../cli/environment-builder.mjs'; - -const YO_RC_OUTPUT = 'yo-rc'; -const ENTITIES_JDL_OUTPUT = 'entities-jdl'; -const RESULT_OUTPUT = 'result'; -const VALID_OUTPUT = 'valid'; -const CONTAINS_SAMPLE = 'contains-sample'; - -const BLANK = 'blank'; -const VALID = 'valid'; -const ERROR = 'error'; -const SUCCESS = 'successfully generated'; - -export default class extends BaseGenerator { - issue; - projectFolder; - owner; - codeWorkspace; - repository; - yoRcContent; - jdlEntities; - - get [BaseGenerator.INITIALIZING]() { - return this.asInitializingTaskGroup({ - async parseCommand() { - await this.parseCurrentJHipsterCommand(); - }, - }); - } - - get [BaseGenerator.PROMPTING]() { - return this.asPromptingTaskGroup({ - async promptOptions() { - if (this.codeWorkspace) { - await promptSamplesFolder.call(this); - } - }, - }); - } - - get [BaseGenerator.DEFAULT]() { - return this.asDefaultTaskGroup({ - async generateSample() { - const octokit = new Octokit(); - // Gets the owner, repo and issue_number from a string such as, "jhipster/generator-jhipster#12345" - if (this.issue.includes('#')) { - let split = this.issue.split('/'); - this.owner = split[0]; - split = split[1].split('#'); - this.repo = split[0]; - this.issue = split[1]; - } - const issue = await octokit.request('GET /repos/{owner}/{repo}/issues/{issue_number}', { - owner: this.owner, - repo: this.repository, - issue_number: this.issue, - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - }, - }); - - const regexp = /(?(?:(?!<\/summary>).)+)<\/summary>\s+<pre>(?<body>(?:(?!<\/pre>).)+)/gs; - let match; - let containsSample = false; - let valid = false; - while ((match = regexp.exec(issue.data.body)) !== null) { - if (match.groups.title.includes('.yo-rc.json file')) { - containsSample = true; - try { - if (match.groups.body) { - const yoRcContent = JSON.parse(match.groups.body); - this.yoRcContent = yoRcContent[GENERATOR_JHIPSTER] ? yoRcContent : { [GENERATOR_JHIPSTER]: yoRcContent }; - setOutput(YO_RC_OUTPUT, VALID); - valid = true; - } else { - setOutput(YO_RC_OUTPUT, BLANK); - } - } catch { - setOutput(YO_RC_OUTPUT, ERROR); - } - } else if (match.groups.title.includes('JDL entity definitions')) { - containsSample = true; - this.jdlEntities = match.groups.body?.trim(); - setOutput(ENTITIES_JDL_OUTPUT, this.jdlEntities ? VALID : BLANK); - } - } - setOutput(CONTAINS_SAMPLE, containsSample); - setOutput(VALID_OUTPUT, valid); - - this.projectFolder = this.projectFolder ?? join(this._globalConfig.get('samplesFolder'), `issues/${this.issue}`); - if (this.yoRcContent) { - const yoRcFile = join(this.projectFolder, '.yo-rc.json'); - try { - const { jwtSecretKey } = this.readDestinationJSON(yoRcFile)?.[GENERATOR_JHIPSTER]; - this.yoRcContent[GENERATOR_JHIPSTER].jwtSecretKey = jwtSecretKey; - } catch {} - - this.writeDestinationJSON(yoRcFile, this.yoRcContent); - } - if (this.jdlEntities) { - this.writeDestination(this.destinationPath(this.projectFolder, 'entities.jdl'), this.jdlEntities); - } - }, - }); - } - - get [BaseGenerator.END]() { - return this.asEndTaskGroup({ - async generateSample() { - if (this.jdlEntities) { - try { - await this.runNonInteractive({ - cwd: this.projectFolder, - inline: this.jdlEntities, - generatorOptions: { - jsonOnly: true, - }, - }); - } catch (error) { - setOutput(ENTITIES_JDL_OUTPUT, ERROR); - throw error; - } - } - if (this.yoRcContent) { - await this.runNonInteractive({ cwd: this.projectFolder }); - } - setOutput(RESULT_OUTPUT, SUCCESS); - - if (this.codeWorkspace) { - await this.composeWithJHipster('@jhipster/jhipster-dev:code-workspace', { - generatorOptions: { - samplePath: this.projectFolder, - }, - }); - } - }, - }); - } - - async runNonInteractive({ cwd, inline, generatorOptions: customOptions }) { - const envOptions = { cwd, logCwd: this.destinationPath() }; - const generatorOptions = { ...this.options, skipPriorities: ['prompting'], skipInstall: true, inline, ...customOptions }; - delete generatorOptions.sharedData; - const envBuilder = await EnvironmentBuilder.createDefaultBuilder(envOptions); - const env = envBuilder.getEnvironment(); - await env.run([`${CLI_NAME}:${inline ? GENERATOR_JDL : GENERATOR_APP}`], generatorOptions); - } -} diff --git a/.blueprint/from-issue/generator.mts b/.blueprint/from-issue/generator.mts new file mode 100644 index 000000000000..fd3a1ed79f2d --- /dev/null +++ b/.blueprint/from-issue/generator.mts @@ -0,0 +1,125 @@ +import { join } from 'node:path'; + +import BaseGenerator from '../../generators/base/index.js'; +import { getGithubIssue, setGithubTaskOutput, prepareSample, parseIssue } from '../../testing/index.js'; +import { promptSamplesFolder } from '../support.mjs'; +import { GENERATOR_APP, GENERATOR_JDL, GENERATOR_WORKSPACES } from '../../generators/generator-list.js'; +import { GENERATOR_JHIPSTER } from '../../generators/generator-constants.js'; +import { extractDataFromInfo, type InfoData } from '../../generators/info/support/index.js'; +import EnvironmentBuilder from '../../cli/environment-builder.mjs'; +import { mutateData } from '../../generators/base/support/config.js'; + +const YO_RC_OUTPUT = 'yo-rc'; +const ENTITIES_JDL_OUTPUT = 'entities-jdl'; +const RESULT_OUTPUT = 'result'; +const VALID_OUTPUT = 'valid'; +const CONTAINS_SAMPLE = 'contains-sample'; + +const BLANK = 'blank'; +const VALID = 'valid'; +const ERROR = 'error'; +const SUCCESS = 'successfully generated'; + +export default class extends BaseGenerator { + issue!: string; + projectFolder!: string; + owner!: string; + codeWorkspace!: boolean; + repository!: string; + data!: InfoData; + + get [BaseGenerator.INITIALIZING]() { + return this.asInitializingTaskGroup({ + async parseCommand() { + await this.parseCurrentJHipsterCommand(); + }, + }); + } + + get [BaseGenerator.PROMPTING]() { + return this.asPromptingTaskGroup({ + async promptOptions() { + if (this.codeWorkspace) { + await promptSamplesFolder.call(this); + } + }, + }); + } + + get [BaseGenerator.CONFIGURING]() { + return this.asConfiguringTaskGroup({ + async configure() { + await this.configureCurrentJHipsterCommandConfig(); + }, + }); + } + + get [BaseGenerator.DEFAULT]() { + return this.asDefaultTaskGroup({ + async generateSample() { + const issue = await getGithubIssue({ owner: this.owner, repository: this.repository, issue: this.issue }); + + this.projectFolder = this.destinationPath( + this.projectFolder ?? join(this._globalConfig.get('samplesFolder'), `issues/${this.issue}`), + ); + + this.data = extractDataFromInfo(issue.body ?? ''); + if (this.data.yoRcBlank) { + setGithubTaskOutput(YO_RC_OUTPUT, BLANK); + } else { + setGithubTaskOutput(YO_RC_OUTPUT, this.data.yoRcValid ? VALID : ERROR); + } + + setGithubTaskOutput(ENTITIES_JDL_OUTPUT, this.data.jdlEntitiesDefinitions ? VALID : BLANK); + setGithubTaskOutput(CONTAINS_SAMPLE, Boolean(this.data.yoRcContent && this.data.jdlEntitiesDefinitions)); + setGithubTaskOutput(VALID_OUTPUT, this.data.yoRcValid); + + for (const file of await prepareSample(this.projectFolder, this.data.files)) { + this.writeDestination(file.filename, file.content); + } + }, + }); + } + + get [BaseGenerator.END]() { + return this.asEndTaskGroup({ + async generateSample() { + const envOptions = { cwd: this.projectFolder, logCwd: this.destinationPath() }; + const generatorOptions = { ...this.options, skipPriorities: ['prompting'], skipInstall: true, experimental: true }; + delete generatorOptions.sharedData; + + const { workspacesFolders, jdlEntitiesDefinitions, yoRcContent, jdlDefinitions } = this.data; + if (jdlEntitiesDefinitions) { + try { + await EnvironmentBuilder.run( + [`jhipster:${GENERATOR_JDL}`], + { ...generatorOptions, inline: jdlEntitiesDefinitions, jsonOnly: true }, + envOptions, + ); + } catch (error) { + setGithubTaskOutput(ENTITIES_JDL_OUTPUT, ERROR); + throw error; + } + } + if (yoRcContent) { + await EnvironmentBuilder.run( + [`jhipster:${workspacesFolders ? GENERATOR_WORKSPACES : GENERATOR_APP}`], + { ...generatorOptions, ...(workspacesFolders ? { workspacesFolders, generateApplications: true } : {}) }, + envOptions, + ); + } else if (jdlDefinitions) { + await EnvironmentBuilder.run([`jhipster:${GENERATOR_JDL}`], { ...generatorOptions, inline: jdlDefinitions }, envOptions); + } + setGithubTaskOutput(RESULT_OUTPUT, SUCCESS); + + if (this.codeWorkspace) { + await this.composeWithJHipster('@jhipster/jhipster-dev:code-workspace', { + generatorOptions: { + samplePath: this.projectFolder, + } as any, + }); + } + }, + }); + } +} diff --git a/cli/environment-builder.mjs b/cli/environment-builder.mjs index b52808a79a2e..b638cb4c4c04 100644 --- a/cli/environment-builder.mjs +++ b/cli/environment-builder.mjs @@ -96,6 +96,12 @@ export default class EnvironmentBuilder { return EnvironmentBuilder.create(...args).prepare(); } + static async run(args, generatorOptions = {}, envOptions = {}) { + const envBuilder = await EnvironmentBuilder.createDefaultBuilder(envOptions); + const env = envBuilder.getEnvironment(); + await env.run(args, generatorOptions); + } + /** * Class to manipulate yeoman environment for jhipster needs. * - Registers jhipster generators. diff --git a/cli/program.mjs b/cli/program.mjs index dd4c4acf50de..6e7d4ac749be 100644 --- a/cli/program.mjs +++ b/cli/program.mjs @@ -34,6 +34,7 @@ import { packageJson } from '../lib/index.js'; import { packageNameToNamespace } from '../generators/base/support/index.js'; import command from '../generators/base/command.js'; import { GENERATOR_APP, GENERATOR_BOOTSTRAP, GENERATOR_JDL } from '../generators/generator-list.js'; +import { extractArgumentsFromConfigs } from '../generators/base/internal/command.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -118,7 +119,7 @@ const addCommandGeneratorOptions = async (command, generatorMeta, { root, bluepr const addCommandRootGeneratorOptions = async (command, generatorMeta, { usage = true } = {}) => { const generatorModule = await generatorMeta.importModule(); if (generatorModule.command) { - command.addJHipsterArguments(generatorModule.command.arguments); + command.addJHipsterArguments(generatorModule.command.arguments ?? extractArgumentsFromConfigs(generatorModule.command.configs)); } else { const generator = await generatorMeta.instantiateHelp(); command.addGeneratorArguments(generator._arguments); diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index 6d918b519fdf..79e0a6b05ebb 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -67,6 +67,7 @@ import { convertConfigToOption } from '../../lib/internal/index.js'; import { getGradleLibsVersionsProperties } from '../gradle/support/dependabot-gradle.js'; import { dockerPlaceholderGenerator } from '../docker/utils.js'; import { getConfigWithDefaults } from '../../jdl/index.js'; +import { extractArgumentsFromConfigs } from '../base/internal/command.js'; const { INITIALIZING, @@ -423,19 +424,7 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`); if (commandDef.arguments) { this.parseJHipsterArguments(commandDef.arguments); } else if (commandDef.configs) { - this.parseJHipsterArguments( - Object.fromEntries( - Object.entries(commandDef.configs as Record<string, any>) - .filter(([_name, def]) => def.argument) - .map(([name, def]) => [ - name, - { - description: def.description, - ...def.argument, - }, - ]), - ) as any, - ); + this.parseJHipsterArguments(extractArgumentsFromConfigs(commandDef.configs)); } if (commandDef.options || commandDef.configs) { this.parseJHipsterOptions(commandDef.options, commandDef.configs); diff --git a/generators/base/internal/command.ts b/generators/base/internal/command.ts new file mode 100644 index 000000000000..3b90542ce4ce --- /dev/null +++ b/generators/base/internal/command.ts @@ -0,0 +1,16 @@ +import { JHipsterArguments, JHipsterConfigs } from '../api.js'; + +export const extractArgumentsFromConfigs = (configs: JHipsterConfigs | undefined): JHipsterArguments => { + if (!configs) return {}; + return Object.fromEntries( + Object.entries(configs) + .filter(([_name, def]) => def.argument) + .map(([name, def]) => [ + name, + { + description: def.description, + ...def.argument, + }, + ]), + ) as JHipsterArguments; +}; diff --git a/generators/base/internal/index.ts b/generators/base/internal/index.ts index 4b28488a64d4..511ad83a3062 100644 --- a/generators/base/internal/index.ts +++ b/generators/base/internal/index.ts @@ -17,3 +17,4 @@ * limitations under the License. */ export * from './blueprint.js'; +export * from './command.js'; diff --git a/generators/info/support/extract-info.ts b/generators/info/support/extract-info.ts new file mode 100644 index 000000000000..51b3c3515e01 --- /dev/null +++ b/generators/info/support/extract-info.ts @@ -0,0 +1,72 @@ +import { GENERATOR_JHIPSTER } from '../../generator-constants.js'; + +export type InfoFile = { filename: string; content: string }; + +export type InfoData = { + yoRcContent: string | undefined; + jdlDefinitions: string | undefined; + jdlEntitiesDefinitions: string | undefined; + yoRcBlank: boolean; + yoRcValid: boolean; + files: InfoFile[]; + workspacesFolders: string[] | undefined; +}; + +export const extractDataFromInfo = (info: string): InfoData => { + const regexp = /<summary>(?<title>(?:(?!<\/summary>).)+)<\/summary>\s+<pre>(?<body>(?:(?!<\/pre>).)+)/gs; + let yoRcContent: string | undefined; + let jdlEntitiesDefinitions: string | undefined; + let jdlDefinitions: string | undefined; + let workspacesFolders; + const files: { filename: string; content: string }[] = []; + + for (const match of info.matchAll(regexp)) { + const { title, body } = match.groups ?? {}; + if (title?.trim() && body?.trim()) { + if (title.includes('.yo-rc.json file')) { + if (title.includes(' for ')) { + const folder = title.split(' for ')[1].trim(); + files.push({ filename: `${folder}/.yo-rc.json`, content: body.trim() }); + } else { + yoRcContent = body.trim(); + } + } else if (title.includes('JDL entity definitions')) { + jdlEntitiesDefinitions = body.trim(); + } else if (title.includes('JDL definitions')) { + // JDL definitions can be be a placehoder + if (body.includes('application')) { + jdlDefinitions = body.trim(); + } + } + } + } + + let yoRcBlank = true; + let yoRcValid = false; + if (yoRcContent) { + yoRcBlank = false; + try { + let content = JSON.parse(yoRcContent); + content = GENERATOR_JHIPSTER in content ? content : { [GENERATOR_JHIPSTER]: content }; + workspacesFolders = content[GENERATOR_JHIPSTER].appsFolders; + yoRcContent = JSON.stringify(content); + yoRcValid = true; + } catch (error) { + // eslint-disable-next-line no-console + console.log('Invalid .yo-rc.json file', error); + } + } + + if (jdlDefinitions) { + files.push({ filename: 'app.jdl', content: jdlDefinitions }); + yoRcContent = undefined; + jdlEntitiesDefinitions = undefined; + } + if (jdlEntitiesDefinitions) { + files.push({ filename: 'entities.jdl', content: jdlEntitiesDefinitions }); + } + if (yoRcContent) { + files.push({ filename: '.yo-rc.json', content: yoRcContent }); + } + return { yoRcContent, jdlEntitiesDefinitions, jdlDefinitions, yoRcBlank, yoRcValid, files, workspacesFolders }; +}; diff --git a/generators/info/support/index.ts b/generators/info/support/index.ts index 6fb06477bf7a..b413a519b440 100644 --- a/generators/info/support/index.ts +++ b/generators/info/support/index.ts @@ -17,3 +17,4 @@ * limitations under the License. */ export * from './utils.js'; +export * from './extract-info.js'; diff --git a/package-lock.json b/package-lock.json index 1fb01728127d..a424745bae01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,7 +85,6 @@ "esmocha": "1.2.0", "jest-extended": "4.0.2", "jsdoc": "4.0.3", - "octokit": "4.0.2", "open-cli": "8.0.0", "prettier2": "npm:prettier@2.8.8", "quibble": "0.9.2", @@ -2586,124 +2585,12 @@ "node": "^16.13.0 || >=18.0.0" } }, - "node_modules/@octokit/app": { - "version": "15.0.1", - "resolved": "https://registry.npmjs.org/@octokit/app/-/app-15.0.1.tgz", - "integrity": "sha512-nwSjC349E6/wruMCo944y1dBC7uKzUYrBMoC4Qx/xfLLBmD+R66oMKB1jXS2HYRF9Hqh/Alq3UNRggVWZxjvUg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/auth-app": "^7.0.0", - "@octokit/auth-unauthenticated": "^6.0.0", - "@octokit/core": "^6.1.2", - "@octokit/oauth-app": "^7.0.0", - "@octokit/plugin-paginate-rest": "^11.0.0", - "@octokit/types": "^13.0.0", - "@octokit/webhooks": "^13.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/auth-app": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-7.1.0.tgz", - "integrity": "sha512-cazGaJPSgeZ8NkVYeM/C5l/6IQ5vZnsI8p1aMucadCkt/bndI+q+VqwrlnWbASRmenjOkf1t1RpCKrif53U8gw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/auth-oauth-app": "^8.1.0", - "@octokit/auth-oauth-user": "^5.1.0", - "@octokit/request": "^9.1.1", - "@octokit/request-error": "^6.1.1", - "@octokit/types": "^13.4.1", - "lru-cache": "^10.0.0", - "universal-github-app-jwt": "^2.2.0", - "universal-user-agent": "^7.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/auth-app/node_modules/lru-cache": { - "version": "10.2.2", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", - "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", - "dev": true, - "license": "ISC", - "engines": { - "node": "14 || >=16.14" - } - }, - "node_modules/@octokit/auth-oauth-app": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-8.1.1.tgz", - "integrity": "sha512-5UtmxXAvU2wfcHIPPDWzVSAWXVJzG3NWsxb7zCFplCWEmMCArSZV0UQu5jw5goLQXbFyOr5onzEH37UJB3zQQg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/auth-oauth-device": "^7.0.0", - "@octokit/auth-oauth-user": "^5.0.1", - "@octokit/request": "^9.0.0", - "@octokit/types": "^13.0.0", - "universal-user-agent": "^7.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/auth-oauth-device": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-device/-/auth-oauth-device-7.1.1.tgz", - "integrity": "sha512-HWl8lYueHonuyjrKKIup/1tiy0xcmQCdq5ikvMO1YwkNNkxb6DXfrPjrMYItNLyCP/o2H87WuijuE+SlBTT8eg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/oauth-methods": "^5.0.0", - "@octokit/request": "^9.0.0", - "@octokit/types": "^13.0.0", - "universal-user-agent": "^7.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/auth-oauth-user": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-user/-/auth-oauth-user-5.1.1.tgz", - "integrity": "sha512-rRkMz0ErOppdvEfnemHJXgZ9vTPhBuC6yASeFaB7I2yLMd7QpjfrL1mnvRPlyKo+M6eeLxrKanXJ9Qte29SRsw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/auth-oauth-device": "^7.0.1", - "@octokit/oauth-methods": "^5.0.0", - "@octokit/request": "^9.0.1", - "@octokit/types": "^13.0.0", - "universal-user-agent": "^7.0.0" - }, - "engines": { - "node": ">= 18" - } - }, "node_modules/@octokit/auth-token": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.1.tgz", "integrity": "sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==", "license": "MIT", - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/auth-unauthenticated": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-6.1.0.tgz", - "integrity": "sha512-zPSmfrUAcspZH/lOFQnVnvjQZsIvmfApQH6GzJrkIunDooU1Su2qt2FfMTSVPRp7WLTQyC20Kd55lF+mIYaohQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/request-error": "^6.0.1", - "@octokit/types": "^13.0.0" - }, + "peer": true, "engines": { "node": ">= 18" } @@ -2713,6 +2600,7 @@ "resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.2.tgz", "integrity": "sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/auth-token": "^5.0.0", "@octokit/graphql": "^8.0.0", @@ -2731,6 +2619,7 @@ "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.1.tgz", "integrity": "sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/types": "^13.0.0", "universal-user-agent": "^7.0.2" @@ -2744,6 +2633,7 @@ "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.1.1.tgz", "integrity": "sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/request": "^9.0.0", "@octokit/types": "^13.0.0", @@ -2753,93 +2643,12 @@ "node": ">= 18" } }, - "node_modules/@octokit/oauth-app": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-7.1.2.tgz", - "integrity": "sha512-4ntCOZIiTozKwuYQroX/ZD722tzMH8Eicv/cgDM/3F3lyrlwENHDv4flTCBpSJbfK546B2SrkKMWB+/HbS84zQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/auth-oauth-app": "^8.0.0", - "@octokit/auth-oauth-user": "^5.0.1", - "@octokit/auth-unauthenticated": "^6.0.0-beta.1", - "@octokit/core": "^6.0.0", - "@octokit/oauth-authorization-url": "^7.0.0", - "@octokit/oauth-methods": "^5.0.0", - "@types/aws-lambda": "^8.10.83", - "universal-user-agent": "^7.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/oauth-authorization-url": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-7.1.1.tgz", - "integrity": "sha512-ooXV8GBSabSWyhLUowlMIVd9l1s2nsOGQdlP2SQ4LnkEsGXzeCvbSbCPdZThXhEFzleGPwbapT0Sb+YhXRyjCA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/oauth-methods": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/@octokit/oauth-methods/-/oauth-methods-5.1.2.tgz", - "integrity": "sha512-C5lglRD+sBlbrhCUTxgJAFjWgJlmTx5bQ7Ch0+2uqRjYv7Cfb5xpX4WuSC9UgQna3sqRGBL9EImX9PvTpMaQ7g==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/oauth-authorization-url": "^7.0.0", - "@octokit/request": "^9.1.0", - "@octokit/request-error": "^6.1.0", - "@octokit/types": "^13.0.0" - }, - "engines": { - "node": ">= 18" - } - }, "node_modules/@octokit/openapi-types": { "version": "22.2.0", "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz", "integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==", - "license": "MIT" - }, - "node_modules/@octokit/openapi-webhooks-types": { - "version": "8.2.1", - "resolved": "https://registry.npmjs.org/@octokit/openapi-webhooks-types/-/openapi-webhooks-types-8.2.1.tgz", - "integrity": "sha512-msAU1oTSm0ZmvAE0xDemuF4tVs5i0xNnNGtNmr4EuATi+1Rn8cZDetj6NXioSf5LwnxEc209COa/WOSbjuhLUA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@octokit/plugin-paginate-graphql": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-graphql/-/plugin-paginate-graphql-5.2.2.tgz", - "integrity": "sha512-7znSVvlNAOJisCqAnjN1FtEziweOHSjPGAuc5W58NeGNAr/ZB57yCsjQbXDlWsVryA7hHQaEQPcBbJYFawlkyg==", - "dev": true, "license": "MIT", - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=6" - } - }, - "node_modules/@octokit/plugin-paginate-rest": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.3.0.tgz", - "integrity": "sha512-n4znWfRinnUQF6TPyxs7EctSAA3yVSP4qlJP2YgI3g9d4Ae2n5F3XDOjbUluKRxPU3rfsgpOboI4O4VtPc6Ilg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/types": "^13.5.0" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=6" - } + "peer": true }, "node_modules/@octokit/plugin-request-log": { "version": "1.0.4", @@ -2850,62 +2659,12 @@ "@octokit/core": ">=3" } }, - "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "13.2.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.2.1.tgz", - "integrity": "sha512-YMWBw6Exh1ZBs5cCE0AnzYxSQDIJS00VlBqISTgNYmu5MBdeM07K/MAJjy/VkNaH5jpJmD/5HFUvIZ+LDB5jSQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/types": "^13.5.0" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=6" - } - }, - "node_modules/@octokit/plugin-retry": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-7.1.1.tgz", - "integrity": "sha512-G9Ue+x2odcb8E1XIPhaFBnTTIrrUDfXN05iFXiqhR+SeeeDMMILcAnysOsxUpEWcQp2e5Ft397FCXTcPkiPkLw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/request-error": "^6.0.0", - "@octokit/types": "^13.0.0", - "bottleneck": "^2.15.3" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=6" - } - }, - "node_modules/@octokit/plugin-throttling": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-9.3.0.tgz", - "integrity": "sha512-B5YTToSRTzNSeEyssnrT7WwGhpIdbpV9NKIs3KyTWHX6PhpYn7gqF/+lL3BvsASBM3Sg5BAUYk7KZx5p/Ec77w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/types": "^13.0.0", - "bottleneck": "^2.15.3" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": "^6.0.0" - } - }, "node_modules/@octokit/request": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.1.1.tgz", "integrity": "sha512-pyAguc0p+f+GbQho0uNetNQMmLG1e80WjkIaqqgUkihqUp0boRU6nKItXO4VWnr+nbZiLGEyy4TeKRwqaLvYgw==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/endpoint": "^10.0.0", "@octokit/request-error": "^6.0.1", @@ -2921,6 +2680,7 @@ "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.1.tgz", "integrity": "sha512-1mw1gqT3fR/WFvnoVpY/zUM2o/XkMs/2AszUUG9I69xn0JFLv6PGkPhNk5lbfvROs79wiS0bqiJNxfCZcRJJdg==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/types": "^13.0.0" }, @@ -3068,36 +2828,11 @@ "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.5.0.tgz", "integrity": "sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==", "license": "MIT", + "peer": true, "dependencies": { "@octokit/openapi-types": "^22.2.0" } }, - "node_modules/@octokit/webhooks": { - "version": "13.2.7", - "resolved": "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-13.2.7.tgz", - "integrity": "sha512-sPHCyi9uZuCs1gg0yF53FFocM+GsiiBEhQQV/itGzzQ8gjyv2GMJ1YvgdDY4lC0ePZeiV3juEw4GbS6w1VHhRw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/openapi-webhooks-types": "8.2.1", - "@octokit/request-error": "^6.0.1", - "@octokit/webhooks-methods": "^5.0.0", - "aggregate-error": "^5.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/webhooks-methods": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@octokit/webhooks-methods/-/webhooks-methods-5.1.0.tgz", - "integrity": "sha512-yFZa3UH11VIxYnnoOYCVoJ3q4ChuSOk2IVBBQ0O3xtKX4x9bmKb/1t+Mxixv2iUhzMdOl1qeWJqEhouXXzB3rQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 18" - } - }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -3362,13 +3097,6 @@ "node": "^16.14.0 || >=18.0.0" } }, - "node_modules/@types/aws-lambda": { - "version": "8.10.138", - "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.138.tgz", - "integrity": "sha512-71EHMl70TPWIAsFuHd85NHq6S6T2OOjiisPTrH7RgcjzpJpPh4RQJv7PvVvIxc6PIp8CLV7F9B+TdjcAES5vcA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/chai": { "version": "4.3.11", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.11.tgz", @@ -3985,23 +3713,6 @@ "node": ">= 14" } }, - "node_modules/aggregate-error": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-5.0.0.tgz", - "integrity": "sha512-gOsf2YwSlleG6IjRYG2A7k0HmBMEo6qVNk9Bp/EaLgAJT5ngH6PXbqa4ItvnEwCm/velL5jAnQgsHsWnjhGmvw==", - "dev": true, - "license": "MIT", - "dependencies": { - "clean-stack": "^5.2.0", - "indent-string": "^5.0.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/ajv": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", @@ -4397,7 +4108,8 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz", "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", - "license": "Apache-2.0" + "license": "Apache-2.0", + "peer": true }, "node_modules/bin-links": { "version": "4.0.4", @@ -4483,13 +4195,6 @@ "dev": true, "license": "MIT" }, - "node_modules/bottleneck": { - "version": "2.19.5", - "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", - "integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==", - "dev": true, - "license": "MIT" - }, "node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -4935,35 +4640,6 @@ "node": ">=8" } }, - "node_modules/clean-stack": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-5.2.0.tgz", - "integrity": "sha512-TyUIUJgdFnCISzG5zu3291TAsE77ddchd0bepon1VVQrKLGKFED4iXFEDQ24mIPdPBbyE16PK3F8MYE1CmcBEQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "escape-string-regexp": "5.0.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/clean-stack/node_modules/escape-string-regexp": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", - "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -11335,28 +11011,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/octokit": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/octokit/-/octokit-4.0.2.tgz", - "integrity": "sha512-wbqF4uc1YbcldtiBFfkSnquHtECEIpYD78YUXI6ri1Im5OO2NLo6ZVpRdbJpdnpZ05zMrVPssNiEo6JQtea+Qg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@octokit/app": "^15.0.0", - "@octokit/core": "^6.0.0", - "@octokit/oauth-app": "^7.0.0", - "@octokit/plugin-paginate-graphql": "^5.0.0", - "@octokit/plugin-paginate-rest": "^11.0.0", - "@octokit/plugin-rest-endpoint-methods": "^13.0.0", - "@octokit/plugin-retry": "^7.0.0", - "@octokit/plugin-throttling": "^9.0.0", - "@octokit/request-error": "^6.0.0", - "@octokit/types": "^13.0.0" - }, - "engines": { - "node": ">= 18" - } - }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -14296,18 +13950,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/universal-github-app-jwt": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/universal-github-app-jwt/-/universal-github-app-jwt-2.2.0.tgz", - "integrity": "sha512-G5o6f95b5BggDGuUfKDApKaCgNYy2x7OdHY0zSMF081O0EJobw+1130VONhrA7ezGSV2FNOGyM+KQpQZAr9bIQ==", - "dev": true, - "license": "MIT" - }, "node_modules/universal-user-agent": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", - "license": "ISC" + "license": "ISC", + "peer": true }, "node_modules/untildify": { "version": "5.0.0", diff --git a/package.json b/package.json index ca65415a3de1..c81cb3b03e30 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,6 @@ "esmocha": "1.2.0", "jest-extended": "4.0.2", "jsdoc": "4.0.3", - "octokit": "4.0.2", "open-cli": "8.0.0", "prettier2": "npm:prettier@2.8.8", "quibble": "0.9.2", diff --git a/testing/github.ts b/testing/github.ts new file mode 100644 index 000000000000..2bbaca281b4a --- /dev/null +++ b/testing/github.ts @@ -0,0 +1,34 @@ +import axios from 'axios'; +import { randomUUID } from 'node:crypto'; +import { appendFileSync, existsSync } from 'node:fs'; +import { EOL } from 'node:os'; + +export const parseIssue = (issue: string): undefined | { owner: string; repository: string; issue: string } => { + if (issue.includes('#')) { + const split = issue.split('/'); + const split2 = split[1].split('#'); + return { owner: split[0], repository: split2[0], issue: split2[1] }; + } + return undefined; +}; + +export const setGithubTaskOutput = (name: string, value: string | boolean | number) => { + const delimiter = `delimiter_${randomUUID()}`; + const output = `${name}<<${delimiter}${EOL}${value}${EOL}${delimiter}${EOL}`; + const filePath = process.env.GITHUB_OUTPUT; + if (filePath && existsSync(filePath)) { + appendFileSync(filePath, output, { encoding: 'utf8' }); + } else { + // eslint-disable-next-line no-console + console.log(output); + } +}; + +export const getGithubIssue = async ({ owner, repository, issue }: { owner: string; repository: string; issue: string }) => { + const response = await axios.get(`https://api.github.com/repos/${owner}/${repository}/issues/${issue}`, { + headers: { + 'X-GitHub-Api-Version': '2022-11-28', + }, + }); + return response.data; +}; diff --git a/testing/index.ts b/testing/index.ts index 6d2808bc4302..153eecefd6f9 100644 --- a/testing/index.ts +++ b/testing/index.ts @@ -1,5 +1,7 @@ export { default as getGenerator } from './get-generator.js'; export * from './helpers.js'; +export * from './github.js'; +export * from './sample-config.js'; // test matrix export * from './support/application-samples.js'; diff --git a/testing/sample-config.ts b/testing/sample-config.ts new file mode 100644 index 000000000000..dcc5ebd2fd25 --- /dev/null +++ b/testing/sample-config.ts @@ -0,0 +1,40 @@ +import { lstat, readFile } from 'node:fs/promises'; +import { join } from 'node:path'; + +import { InfoFile } from '../generators/info/support/extract-info.js'; +import { GENERATOR_JHIPSTER } from '../generators/generator-constants.js'; +import { mutateData } from '../generators/base/support/config.js'; + +const isFile = async (filename: string): Promise<boolean> => { + try { + return (await lstat(filename)).isFile(); + } catch { + return false; + } +}; + +export const prepareSample = async ( + projectFolder: string, + files: InfoFile[], + { removeBlueprints }: { removeBlueprints?: boolean } = {}, +): Promise<InfoFile[]> => { + return Promise.all( + files.map(async ({ filename, content }) => { + filename = join(projectFolder, filename); + if (filename.endsWith('.yo-rc.json')) { + if (await isFile(filename)) { + const { jwtSecretKey, rememberMeKey } = JSON.parse(await readFile(filename, 'utf-8'))[GENERATOR_JHIPSTER]; + if (jwtSecretKey || rememberMeKey) { + const newContent = JSON.parse(content); + mutateData(newContent[GENERATOR_JHIPSTER], { jwtSecretKey, rememberMeKey }); + if (removeBlueprints) { + delete newContent[GENERATOR_JHIPSTER].blueprints; + } + content = JSON.stringify(newContent, null, 2); + } + } + } + return { filename, content }; + }), + ); +}; From 8d48f3e1606bbeff51616cab4add456c73d151e5 Mon Sep 17 00:00:00 2001 From: Marcelo Shima <marceloshima@gmail.com> Date: Fri, 31 May 2024 14:03:10 -0300 Subject: [PATCH 2/2] Update .blueprint/from-issue/command.mts Co-authored-by: Matt Raible <matt@raibledesigns.com> --- .blueprint/from-issue/command.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.blueprint/from-issue/command.mts b/.blueprint/from-issue/command.mts index 0e2b0a50c53f..2d16ff12c404 100644 --- a/.blueprint/from-issue/command.mts +++ b/.blueprint/from-issue/command.mts @@ -25,7 +25,7 @@ const command: JHipsterCommandDefinition = { issue: { argument: { type: String, - description: 'Github issue to generate', + description: 'GitHub issue to generate', }, configure(gen: any) { // Gets the owner, repo and issue_number from a string such as, "jhipster/generator-jhipster#12345"