Skip to content

Commit 51cbf49

Browse files
Jeroen-ClaasensJeroen-Claasens
authored andcommitted
feat: add github-base-url option to publish to GHES and GHEC
1 parent 522e3c5 commit 51cbf49

6 files changed

Lines changed: 42 additions & 15 deletions

File tree

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ variation of the [Angular preset][angular-preset] (seen
3939
1. If `--install` was provided (or `install: true` set in the config file) then
4040
run the `install` command of the package manager (`npm install`,
4141
`yarn install`, or `pnpm install`) you used to call this CLI.
42-
4342
- **Important:** when you install `@favware/cliff-jumper` globally this will
4443
always default to `npm` because of how NodeJS works. Therefore, if you wish
4544
for it to be `yarn` or `npm` make sure to add it as dev dependency to your
@@ -169,14 +168,12 @@ Options:
169168
as latest an this option will essentially be ignored.
170169
--github-release-name-template [string] Note that this is only supported if "--git-host-variant" is set to "github"
171170
A GitHub release name template to use. Defaults to an empty string, which means GitHub will use the tag name as the release name.
172-
You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be
173-
published.
174-
You can use "{{org}}" in your template, this will be replaced with the org provided through "-o", "--org" or the same value set in
175-
your config file.
176-
You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in
177-
your config file.
178-
You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}"
179-
(when "org" is provided).
171+
You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be published.
172+
You can use "{{org}}" in your template, this will be replaced with the org provided through "-o", "--org" or the same value set in your config file.
173+
You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in your config file.
174+
You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is provided).
175+
--github-base-url [string] Note that this is only supported if "--git-host-variant" is set to "github"
176+
The base URL for the GitHub API. Defaults to "https://api.github.com".
180177
-v, --verbose Whether to print verbose information (default: false)
181178
-h, --help display help for command
182179
```
@@ -212,6 +209,7 @@ package). It should be named `.cliff-jumperrc`, optionally suffixed with
212209
- `--github-release-pre-release` maps to `githubReleasePrerelease`
213210
- `--github-release-latest` maps to `githubReleaseLatest`
214211
- `--github-release-name-template` maps to `githubReleaseNameTemplate`
212+
- `--github-base-url` maps to `githubBaseUrl`
215213
- `--verbose` maps to `verbose`
216214
217215
When using `.cliff-jumperrc` or `.cliff-jumperrc.json` as your config file you
@@ -301,6 +299,7 @@ This library has opinionated defaults for its options. These are as follows:
301299
- `--github-release-pre-release` will default to `false`.
302300
- `--github-release-latest` will default to `true`.
303301
- `--github-release-name-template` will default to an empty string.
302+
- `--github-base-url` will default to `https://api.github.com`.
304303
- `--verbose` will default to `false`.
305304
306305
### Merging of config file, defaults and CLI provided flags

assets/cliff-jumper.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
"description": "Note that this is only supported if \"--git-host-variant\" is set to \"github\"\nA custom release name template to use.\n\nYou can use \"{{new-version}}\" in your template which will be dynamically replaced with whatever the new version is that will be published.\n\nYou can use \"{{name}}\" in your template, this will be replaced with the name provided through \"-n\", \"--name\" or the same value set in your config file.\n\nYou can use \"{{full-name}}\" in your template, this will be replaced \"{{name}}\" (when \"org\" is not provided), or \"@{{org}}/{{name}}\" (when \"org\" is provided).",
117117
"type": "string"
118118
},
119+
"githubBaseUrl": {
120+
"description": "Note that this is only supported if \"--git-host-variant\" is set to \"github\"\nA custom GitHub base URL to use. This can be used for GHEC or GHES instances. This should be the full API URL, for example \"https://api.github.com\" for github.com, or \"https://octokit.ghe.com/api/v3\" for a GHEC instance.",
121+
"type": "string",
122+
"default": "https://api.github.com"
123+
},
119124
"verbose": {
120125
"description": "Whether to print verbose information",
121126
"type": "boolean",

src/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ const command = new Command()
174174
'You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is provided).'
175175
].join('\n')
176176
)
177+
.option(
178+
'--github-base-url [string]',
179+
[
180+
'Note that this is only supported if "--git-host-variant" is set to "github"',
181+
'The base URL for the GitHub API. Defaults to "https://api.github.com".'
182+
].join('\n')
183+
)
177184
.option('-v, --verbose', 'Whether to print verbose information', false);
178185

179186
const program = command.parse(process.argv);
@@ -207,6 +214,7 @@ logVerboseInfo(
207214
`${indent}github release pre-release: ${JSON.stringify(options.githubReleasePrerelease)}`,
208215
`${indent}github release latest: ${JSON.stringify(options.githubReleaseLatest)}`,
209216
`${indent}github release name template: ${JSON.stringify(options.githubReleaseNameTemplate)}`,
217+
`${indent}github base URL: ${JSON.stringify(options.githubBaseUrl)}`,
210218
''
211219
],
212220
options.verbose

src/commands/create-github-release.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import type { Options } from 'commander';
1010

1111
export function createGitHubRelease(options: Options, newVersion: string, changelogSection: string | undefined) {
1212
const HydratedOctokit = Octokit.plugin(retry).defaults({
13-
userAgent: 'Cliff Jumper CLI/ (@favware/cliff-jumper) (https://github.com/favware/cliff-jumper/tree/main)'
13+
userAgent: 'Cliff Jumper CLI/ (@favware/cliff-jumper) (https://github.com/favware/cliff-jumper/tree/main)',
14+
baseUrl: options.githubBaseUrl || 'https://api.github.com'
1415
});
1516

1617
return doActionAndLog('Creating release', async () => {

src/lib/interfaces.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ declare module 'commander' {
2929
githubReleasePrerelease: boolean;
3030
githubReleaseLatest: boolean;
3131
githubReleaseNameTemplate: string;
32+
githubBaseUrl: string;
3233
}
3334
}

src/lib/preflight-checks.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,25 @@ async function checkGitConfig(options: Options) {
8181

8282
const gitRepo = getGitRepo(options);
8383
const gitToken = getGitToken(options);
84-
const { gitHostVariant, githubRelease, githubReleaseDraft, githubReleasePrerelease, githubReleaseLatest, githubReleaseNameTemplate, pushTag } =
85-
options;
84+
const {
85+
gitHostVariant,
86+
githubRelease,
87+
githubReleaseDraft,
88+
githubReleasePrerelease,
89+
githubReleaseLatest,
90+
githubReleaseNameTemplate,
91+
githubBaseUrl,
92+
pushTag
93+
} = options;
8694

8795
if (
8896
!isNullishOrEmpty(gitRepo) ||
8997
githubRelease ||
9098
githubReleaseDraft ||
9199
githubReleasePrerelease ||
92100
githubReleaseLatest ||
93-
!isNullishOrEmpty(githubReleaseNameTemplate)
101+
!isNullishOrEmpty(githubReleaseNameTemplate) ||
102+
!isNullishOrEmpty(githubBaseUrl)
94103
) {
95104
if (isNullishOrEmpty(gitToken)) {
96105
logVerboseError({
@@ -111,10 +120,14 @@ async function checkGitConfig(options: Options) {
111120
() => {
112121
if (
113122
(!githubRelease || !pushTag) &&
114-
(githubReleaseDraft || githubReleasePrerelease || githubReleaseLatest || !isNullishOrEmpty(githubReleaseNameTemplate))
123+
(githubReleaseDraft ||
124+
githubReleasePrerelease ||
125+
githubReleaseLatest ||
126+
!isNullishOrEmpty(githubReleaseNameTemplate) ||
127+
!isNullishOrEmpty(githubBaseUrl))
115128
) {
116129
throw new Error(
117-
'You can only use --github-release-draft, --github-release-latest, --github-release-name-template, and --github-release-pre-release when both --github-release and --push-tag are provided'
130+
'You can only use --github-release-draft, --github-release-latest, --github-release-name-template, --github-base-url, and --github-release-pre-release when both --github-release and --push-tag are provided'
118131
);
119132
}
120133
}

0 commit comments

Comments
 (0)