From 0070bdfe73e7daa4747b8b2de8d51238ee281015 Mon Sep 17 00:00:00 2001 From: thilllon Date: Sat, 30 Dec 2023 18:14:16 +0900 Subject: [PATCH 1/2] feat: add open and default placeholder --- package.json | 1 + pnpm-lock.yaml | 48 +++++++++++++++++++++++++++++++--- src/cli.ts | 4 +-- src/gitarist.spec.ts | 18 ++++++++++--- src/gitarist.ts | 62 +++++++++++++++++++++++++++++++------------- 5 files changed, 107 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 5ba4dd2..33fa5cc 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "fast-glob": "^3.3.2", "lodash": "^4.17.21", "octokit": "^3.1.2", + "open": "^10.0.2", "parse-git-config": "^3.0.0", "zod": "^3.22.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf315d2..d3e1ee6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ dependencies: octokit: specifier: ^3.1.2 version: 3.1.2 + open: + specifier: ^10.0.2 + version: 10.0.2 parse-git-config: specifier: ^3.0.0 version: 3.0.0 @@ -2591,6 +2594,13 @@ packages: run-applescript: 5.0.0 dev: true + /bundle-name@4.1.0: + resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} + engines: {node: '>=18'} + dependencies: + run-applescript: 7.0.0 + dev: false + /bundle-require@4.0.2(esbuild@0.19.10): resolution: {integrity: sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -3123,6 +3133,11 @@ packages: untildify: 4.0.0 dev: true + /default-browser-id@5.0.0: + resolution: {integrity: sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==} + engines: {node: '>=18'} + dev: false + /default-browser@4.0.0: resolution: {integrity: sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==} engines: {node: '>=14.16'} @@ -3133,6 +3148,14 @@ packages: titleize: 3.0.0 dev: true + /default-browser@5.2.1: + resolution: {integrity: sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==} + engines: {node: '>=18'} + dependencies: + bundle-name: 4.1.0 + default-browser-id: 5.0.0 + dev: false + /defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} dependencies: @@ -3155,7 +3178,6 @@ packages: /define-lazy-prop@3.0.0: resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==} engines: {node: '>=12'} - dev: true /define-properties@1.2.1: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} @@ -4432,7 +4454,6 @@ packages: resolution: {integrity: sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} hasBin: true - dev: true /is-extglob@2.1.1: resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} @@ -4485,7 +4506,6 @@ packages: hasBin: true dependencies: is-docker: 3.0.0 - dev: true /is-installed-globally@0.4.0: resolution: {integrity: sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==} @@ -4655,6 +4675,13 @@ packages: is-docker: 2.2.1 dev: true + /is-wsl@3.1.0: + resolution: {integrity: sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==} + engines: {node: '>=16'} + dependencies: + is-inside-container: 1.0.0 + dev: false + /isarray@2.0.5: resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==} dev: true @@ -5845,6 +5872,16 @@ packages: mimic-fn: 4.0.0 dev: true + /open@10.0.2: + resolution: {integrity: sha512-GnYLdE+E3K8NeSE23N0g67/9q9AXRph5oTUbz6IbIgElPigEnQ2aHuqRge3y0JUr67qoc84xME5kF03fDc3fcA==} + engines: {node: '>=18'} + dependencies: + default-browser: 5.2.1 + define-lazy-prop: 3.0.0 + is-inside-container: 1.0.0 + is-wsl: 3.1.0 + dev: false + /open@9.1.0: resolution: {integrity: sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==} engines: {node: '>=14.16'} @@ -6484,6 +6521,11 @@ packages: execa: 5.1.1 dev: true + /run-applescript@7.0.0: + resolution: {integrity: sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==} + engines: {node: '>=18'} + dev: false + /run-async@2.4.1: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} engines: {node: '>=0.12.0'} diff --git a/src/cli.ts b/src/cli.ts index 49a552b..7d940f0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -25,8 +25,8 @@ program DEFAULT.remote, ), ) - .action((options: SetupCommandOptions) => { - Gitarist.setup({ remote: options.remote }); + .action(async (options: SetupCommandOptions) => { + await Gitarist.setup({ remote: options.remote }); }); program diff --git a/src/gitarist.spec.ts b/src/gitarist.spec.ts index bb2ff58..ee8267b 100644 --- a/src/gitarist.spec.ts +++ b/src/gitarist.spec.ts @@ -1,8 +1,10 @@ import { execSync } from 'child_process'; import dotenv from 'dotenv'; +import { mkdirSync, rmdirSync } from 'fs'; import { mkdir, writeFile } from 'fs/promises'; import { Octokit } from 'octokit'; -import { dirname } from 'path'; +import { dirname, join } from 'path'; +import { chdir } from 'process'; import { Gitarist, IssueItem } from './gitarist'; jest.setTimeout(999999999); @@ -24,9 +26,19 @@ describe('gitarist', () => { }); it.skip('setup', async () => { - Gitarist.setup({}); - + // FIXME: `open` is not working on commonjs + const targetDir = join( + process.cwd(), + '.gitarist', + `directory_${Date.now()}`, + ); + mkdirSync(targetDir, { recursive: true }); + chdir(targetDir); + execSync('git init'); + execSync('cd'); + await Gitarist.setup({}); expect(true).toBeTruthy(); + rmdirSync(targetDir); }); it.skip('simulate active user', async () => { diff --git a/src/gitarist.ts b/src/gitarist.ts index f73498d..bad0443 100644 --- a/src/gitarist.ts +++ b/src/gitarist.ts @@ -47,6 +47,8 @@ export const DEFAULT = { cron: '0 */6 * * 0-6', stale: 2, // days language: 'GO', + ownerPlaceholder: '', + repoPlaceholder: '', } as const; enum MODE { @@ -254,7 +256,9 @@ GITARIST_TOKEN="${token}" /** * Setup a repository for gitarist which is creating a workflow file. */ - static setup({ remote = DEFAULT.remote }: Partial) { + static async setup({ + remote = DEFAULT.remote, + }: Partial) { const gitConfigPath = path.join(process.cwd(), '.git', 'config'); if (!existsSync(gitConfigPath)) { throw new Error( @@ -262,12 +266,15 @@ GITARIST_TOKEN="${token}" ); } - const envPath = path.join(process.cwd(), '.env'); - console.log(`Searching .env file at ${envPath}`); + const dotenvFile = '.env'; + const envPath = path.join(process.cwd(), dotenvFile); + console.log(`Searching ${dotenvFile} file from ${envPath} ...`); if (existsSync(envPath)) { console.log( - 'There is a .env file already so template will be appended to the file.', + `\tThere is a ${dotenvFile} file already so template will be appended to the file.`, ); + } else { + console.log(`\tCould not find a ${dotenvFile} file`); } const ymlPath = path.join( @@ -276,21 +283,23 @@ GITARIST_TOKEN="${token}" 'workflows', 'gitarist.yml', ); - console.log(`Searching gitarist workflow file at ${envPath}.`); + console.log(`Searching gitarist workflow file from ${envPath} ...`); if (existsSync(ymlPath)) { - console.log(`There is a gitarist workflow file already at ${ymlPath}.`); + console.log(`\tThere is a gitarist workflow file already at ${ymlPath}.`); + } else { + console.log(`\tCould not find a workflow file`); } const git = parseGitConfig.sync( readFileSync(path.join(process.cwd(), '.git', 'config'), 'utf8'), ); - const owner = git?.user?.name ?? ''; + const owner = git?.user?.name ?? DEFAULT.ownerPlaceholder; const repo = git[`remote "${remote}"`]?.url ?.split('/') ?.pop() ?.replace('.git', '') - .replace('/', '') ?? ''; + .replace('/', '') ?? DEFAULT.repoPlaceholder; const githubWorkflowDirectory = path.join( process.cwd(), '.github', @@ -300,10 +309,7 @@ GITARIST_TOKEN="${token}" writeFileSync( path.join(githubWorkflowDirectory, 'gitarist.yml'), Gitarist.getActionTemplate({ owner, repo }), - { - encoding: 'utf8', - flag: 'a+', - }, + { encoding: 'utf8', flag: 'a+' }, ); writeFileSync( path.join(process.cwd(), '.env'), @@ -312,13 +318,33 @@ GITARIST_TOKEN="${token}" ); console.log( - [ - 'Generate a secret key settings:', - Gitarist.tokenIssueUrl, - 'Register the secret key to action settings:', - Gitarist.tokenSettingUrl({ owner, repo }), - ].join('\n'), + ['Generate a secret key settings:', Gitarist.tokenIssueUrl].join('\n'), + ); + const open = await import('open'); + await open.default(Gitarist.tokenIssueUrl, { wait: false }); + + console.log( + `Register the secret key to action settings: ${Gitarist.tokenSettingUrl({ + owner, + repo, + })}`, ); + + console.log( + 'Go to repository > settings > Secrets and variables > Actions > New repository secret', + ); + + if ( + owner !== DEFAULT.ownerPlaceholder && + repo !== DEFAULT.repoPlaceholder + ) { + console.log( + [ + 'Register the secret key to action settings:', + Gitarist.tokenSettingUrl({ owner, repo }), + ].join('\n'), + ); + } } /** From 62b63e9716f2ff57406f70b1acc08852c47d353f Mon Sep 17 00:00:00 2001 From: thilllon Date: Sat, 30 Dec 2023 18:34:13 +0900 Subject: [PATCH 2/2] chore: release 1.2.10-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33fa5cc..d680896 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitarist", - "version": "1.2.9", + "version": "1.2.10-0", "description": "A CLI tool to utilize Octokit", "license": "MIT", "publishConfig": {