|
1 | 1 | import type { CLI, ReleaseOptions } from '@stacksjs/types' |
| 2 | +import { execFileSync } from 'node:child_process' |
2 | 3 | import process from 'node:process' |
3 | 4 | import { runAction } from '@stacksjs/actions' |
4 | | -import { intro, italic, log, onUnknownSubcommand, outro } from "@stacksjs/cli" |
| 5 | +import { intro, italic, log, onUnknownSubcommand, outro } from '@stacksjs/cli' |
5 | 6 | import { Action } from '@stacksjs/enums' |
6 | 7 | import { ExitCode } from '@stacksjs/types' |
7 | 8 |
|
@@ -39,8 +40,26 @@ export function release(buddy: CLI): void { |
39 | 40 | useSeconds: true, |
40 | 41 | }) |
41 | 42 |
|
42 | | - log.info(`Follow along: ${italic('https://github.com/stacksjs/stacks/actions')}`) |
| 43 | + log.info(`Follow along: ${italic(resolveGitHubActionsUrl(readOriginRemote()))}`) |
43 | 44 | }) |
44 | 45 |
|
45 | | - onUnknownSubcommand(buddy, "release") |
| 46 | + onUnknownSubcommand(buddy, 'release') |
| 47 | +} |
| 48 | + |
| 49 | +export function resolveGitHubActionsUrl( |
| 50 | + remoteUrl?: string, |
| 51 | + repository = process.env.GITHUB_REPOSITORY, |
| 52 | + serverUrl = process.env.GITHUB_SERVER_URL ?? 'https://github.com', |
| 53 | +): string { |
| 54 | + const repo = repository?.trim() || remoteUrl?.trim().match(/github\.com[/:]([^/\s]+\/[^/\s]+?)(?:\.git)?$/)?.[1] |
| 55 | + return repo ? `${serverUrl.replace(/\/$/, '')}/${repo}/actions` : 'https://github.com/stacksjs/stacks/actions' |
| 56 | +} |
| 57 | + |
| 58 | +function readOriginRemote(): string | undefined { |
| 59 | + try { |
| 60 | + return execFileSync('git', ['config', '--get', 'remote.origin.url'], { encoding: 'utf8' }).trim() |
| 61 | + } |
| 62 | + catch { |
| 63 | + return undefined |
| 64 | + } |
46 | 65 | } |
0 commit comments