Skip to content

Commit

Permalink
fix: url readme url
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Oct 30, 2022
1 parent 88879fe commit 6615d96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/presets/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Preset {
}

const presets: Preset[] = [semverWorkflowPreset, renovatePreset]
const presetNames = presets.map((p) => p.name)
const presetNames = presets.map((p) => p?.name)

export function presetHelpList(padStart: number) {
return presets
Expand Down
16 changes: 14 additions & 2 deletions src/presets/semver-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import chalk from 'chalk'
import path from 'path'
import {readFile, writeFile} from '../util/files'
import {errorToUndefined} from '../util/errorToUndefined'
import {PackageJson} from '../actions/verify/types'

export const semverWorkflowPreset: Preset = {
name: 'semver-workflow',
Expand Down Expand Up @@ -79,12 +80,14 @@ async function updateReadme(options: InjectOptions) {
async function readmeSnippets(options: InjectOptions) {
const pkg = await getPackage(options)

const bestEffortUrl = readmeBaseurl(pkg)

const v3Banner = outdent`
> **NOTE**
>
> This is the **Sanity Studio v3 version** of ${pkg.name}.
>
> For the v2 version, please refer to the [v2-branch](${pkg.repository?.url ?? 'TODO'}).
> For the v2 version, please refer to the [v2-branch](${bestEffortUrl}).
`

const installUsage = outdent`
Expand Down Expand Up @@ -120,7 +123,7 @@ async function readmeSnippets(options: InjectOptions) {
### Release new version
Run ["CI & Release" workflow](${pkg.repository?.url ?? 'TODO'}/actions/workflows/main.yml).
Run ["CI & Release" workflow](${bestEffortUrl}/actions/workflows/main.yml).
Make sure to select the main branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.
Expand Down Expand Up @@ -156,3 +159,12 @@ async function semverWorkflowDependencies(): Promise<Record<string, string>> {
'lint-staged',
])
}

export function readmeBaseurl(pkg: PackageJson) {
return ((pkg.repository?.url ?? pkg.homepage ?? 'TODO') as string)
.replaceAll(/.+:\/\//g, 'https://')
.replaceAll(/\.git/g, '')
.replaceAll(/[email protected]\//g, 'github.com/')
.replaceAll(/[email protected]:/g, 'https://github.com/')
.replaceAll(/#.+/g, '')
}
30 changes: 30 additions & 0 deletions test/semver-workflow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import tap from 'tap'
import {readmeBaseurl} from '../src/presets/semver-workflow'
import {PackageJson} from '../src/actions/verify/types'

tap.test('readmeBaseUrl', async (t) => {
const testCases: {pkg: PackageJson; expectedUrl: string}[] = [
{
pkg: {repository: {url: 'git+https://github.com/sanity-io/sanity.git'}},
expectedUrl: 'https://github.com/sanity-io/sanity',
},
{
pkg: {repository: {url: 'git+ssh://[email protected]/sanity-io/plugin-kit.git'}},
expectedUrl: 'https://github.com/sanity-io/plugin-kit',
},
{
pkg: {repository: {url: '[email protected]:sanity-io/sanity-plugin-cloudinary.git'}},
expectedUrl: 'https://github.com/sanity-io/sanity-plugin-cloudinary',
},
{
pkg: {repository: {url: 'git+https://github.com/sanity-io/sanity-plugin.git'}},
expectedUrl: 'https://github.com/sanity-io/sanity-plugin',
},
{
pkg: {homepage: 'https://github.com/sanity-io/plugin-with-readme#readme'},
expectedUrl: 'https://github.com/sanity-io/plugin-with-readme',
},
]

testCases.forEach(({pkg, expectedUrl}) => t.equal(readmeBaseurl(pkg), expectedUrl))
})

0 comments on commit 6615d96

Please sign in to comment.