Skip to content

Commit

Permalink
general style changes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar committed Feb 27, 2024
1 parent e0ddb5f commit 7f63f6a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
5 changes: 2 additions & 3 deletions lib/cwd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ export async function setCwd() {
let RWFW_PATH = process.env.RWFW_PATH;

if (!RWFW_PATH) {
throw new CustomError("`RWFW_PATH` isn't set. Set it to the path of the Redwood monorepo.");
throw new CustomError("The `RWFW_PATH` environment variable isn't set. Set it to the path of the Redwood monorepo.");
}

try {
RWFW_PATH = await fs.realpath(RWFW_PATH)
} catch (error) {
throw new CustomError(`\`RWFW_PATH\` is set to "${RWFW_PATH}" but it doesn't exist at that path.`)
throw new CustomError(`\`RWFW_PATH\` environment variable is set to "${RWFW_PATH}" but it doesn't exist at that path.`)
}

const originalCwd = process.cwd()
Expand Down
1 change: 1 addition & 0 deletions lib/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class CustomError extends Error {
name
title

constructor(message: string, title: string = '👷 Heads up') {
Expand Down
5 changes: 1 addition & 4 deletions lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { unwrap } from './zx_helpers.js'
/** Gets release branches (e.g. `release/major/v7.0.0`, etc.) */
export async function getReleaseBranches() {
const releaseBranchesStdout = unwrap(await $`git branch --list release/*`)

if (releaseBranchesStdout === '') {
return []
}
Expand All @@ -18,7 +17,6 @@ export async function getReleaseBranches() {
.sort((releaseBranchA, releaseBranchB) => {
const [, , versionA] = releaseBranchA.split('/')
const [, , versionB] = releaseBranchB.split('/')

return semver.compare(versionA, versionB)
})

Expand All @@ -27,7 +25,6 @@ export async function getReleaseBranches() {

export async function assertWorkTreeIsClean() {
const workTreeIsClean = unwrap(await $`git status -s`) === ''

if (!workTreeIsClean) {
throw new CustomError(
"Your working tree isn't clean. Commit or stash your changes."
Expand All @@ -41,6 +38,6 @@ export async function branchExists(branch: string) {

export async function assertBranchExists(branch: string) {
if (!(await branchExists(branch))) {
throw new CustomError(`The branch ${branch} does not exist. Check it out from the Redwood remote.`)
throw new CustomError(`The branch ${branch} doesn't exist. Check it out from the Redwood remote.`)
}
}
23 changes: 14 additions & 9 deletions lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import { CustomError } from './error.js'

export const REMOTE = 'https://github.com/redwoodjs/redwood.git'

// See https://stackoverflow.com/questions/18268986/git-how-to-push-messages-added-by-git-notes-to-the-central-git-server.
export async function fetchNotes() {
await $`git fetch ${REMOTE} 'refs/notes/*:refs/notes/*'`
}
export async function pushNotes() {
await $`git push ${REMOTE} 'refs/notes/*'`
}

/** Get the GitHub token from REDWOOD_GITHUB_TOKEN */
export function getGitHubToken() {
const gitHubToken = process.env.REDWOOD_GITHUB_TOKEN

if (!gitHubToken) {
throw new CustomError("REDWOOD_GITHUB_TOKEN isn't set")
throw new CustomError("The `REDWOOD_GITHUB_TOKEN` environment variable isn't set")
}

return gitHubToken
Expand Down Expand Up @@ -56,3 +48,16 @@ export async function pullBranch(branch: string) {
export async function pushBranch(branch: string) {
await $`git push ${REMOTE} ${branch}`
}

/**
* Fetches notes from the remote.
*
* See https://stackoverflow.com/questions/18268986/git-how-to-push-messages-added-by-git-notes-to-the-central-git-server.
*/
export async function fetchNotes() {
await $`git fetch ${REMOTE} 'refs/notes/*:refs/notes/*'`
}

export async function pushNotes() {
await $`git push ${REMOTE} 'refs/notes/*'`
}
1 change: 0 additions & 1 deletion lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function prompts(

export function resolveRes(res: string) {
const isYes = resIsYes(res)

if (isYes) {
return 'yes'
}
Expand Down
2 changes: 1 addition & 1 deletion lib/zx_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ProcessOutput } from 'zx'
* Helper for getting the trimmed stdout from `zx`'s `ProcessOutput`:
*
* ```ts
* unwrap(await $`git branch --list release/*`)
* unwrap(await $`...`)
* ```
*/
export function unwrap(processOutput: ProcessOutput) {
Expand Down
4 changes: 2 additions & 2 deletions release/lib/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getLatestReleaseOrThrow() {
`The latest release is ${chalk.magenta(latestRelease)}? [Y/n] > `
))
if (!ok) {
throw new CustomError('The latest release is not correct')
throw new CustomError("The latest release isn't correct")
}
return latestRelease
}
Expand All @@ -28,7 +28,7 @@ export async function getNextReleaseOrThrow({ latestRelease, desiredSemver }: Pi
)
)
if (!ok) {
throw new CustomError('The next release is not correct')
throw new CustomError("The next release isn't correct")
}
return nextRelease
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/reset_next.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Don't use this unless you know what you're doing!
//
// This script resets the next branch to the ${REMOTE}/next branch.
// It's useful for testing the triage script, but it's destructive.
// Don't use it unless you know what you're doing!

import { question, $ } from 'zx'

Expand Down
2 changes: 1 addition & 1 deletion triage/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ try {
process.exitCode = 1;

if (error instanceof CustomError) {
consoleBoxen("👷 Heads up", error.message);
consoleBoxen(error.title, error.message);
} else {
throw error;
}
Expand Down

0 comments on commit 7f63f6a

Please sign in to comment.