โฌ ๏ธ Back to Table of Contents
๐ backport¶
๐ Analysis Summary¶
| Metric | Count |
|---|---|
| ๐ง Functions | 9 |
| ๐ฆ Imports | 5 |
| ๐ Variables & Constants | 6 |
| โก Async/Await Patterns | 1 |
| ๐ Interfaces | 1 |
๐ Table of Contents¶
๐ ๏ธ File Location:¶
๐ scripts/backport.ts
๐ฆ Imports¶
| Name | Source |
|---|---|
execFileSync |
node:child_process |
process |
node:process |
parseArgs |
node:util |
consola |
consola |
colors |
consola/utils |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
SEP |
"\u001F" |
const | '\x1F' |
โ |
EOL |
"\u001E" |
const | '\x1E' |
โ |
limit |
number |
const | args.limit ? Number.parseInt(args.limit, 10) : 0 |
โ |
selected |
Commit[] |
const | await selectCommits(listed) |
โ |
done |
number |
let/var | 0 |
โ |
skipped |
number |
let/var | 0 |
โ |
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| async-function | selectCommits |
consola.prompt('Select the commits to backport', { type: 'multiselect', requi... | none |
Functions¶
git(cmd: string[]): string¶
Parameters:
cmdstring[]
Returns: string
Calls:
execFileSync('git', cmd, { encoding: 'utf-8' }).trim
Code
tryGit(cmd: string[]): string | undefined¶
Parameters:
cmdstring[]
Returns: string | undefined
Calls:
git
Code
fatal(message: string, hint: string): never¶
Parameters:
messagestringhintstring
Returns: never
Calls:
consola.errorconsola.infoprocess.exit
Code
isBreaking(subject: string, body: string): boolean¶
Parameters:
subjectstringbodystring
Returns: boolean
Calls:
/^\w+(?:\([^)]*\))?!:/.test/^BREAKING[ -]CHANGE:/m.test
Internal Comments:
Code
parseCommits(raw: string): Commit[]¶
Parameters:
rawstring
Returns: Commit[]
Calls:
raw .split(EOL) .map(i => i.trim()) .filter(Boolean) .mapentry.splithash.sliceisBreaking
Code
function parseCommits(raw: string): Commit[] {
return raw
.split(EOL)
.map(i => i.trim())
.filter(Boolean)
.map((entry) => {
const [hash, subject, author, date, body = ''] = entry.split(SEP)
return {
hash,
short: hash.slice(0, 7),
subject,
author,
date,
body,
breaking: isBreaking(subject, body),
}
})
}
resolveSource(ref: string): string¶
Parameters:
refstring
Returns: string
Calls:
tryGitref.includesfatalcolors.yellow
Internal Comments:
// fall back to the remote tracking branch, so `--from main` works on a
// checkout that never created a local `main`
Code
function resolveSource(ref: string): string {
if (tryGit('rev-parse', '--verify', '--quiet', `${ref}^{commit}`))
return ref
// fall back to the remote tracking branch, so `--from main` works on a
// checkout that never created a local `main`
if (!ref.includes('/') && tryGit('rev-parse', '--verify', '--quiet', `origin/${ref}^{commit}`))
return `origin/${ref}`
return fatal(`Cannot resolve source ref ${colors.yellow(ref)}`)
}
getPickedHashes(source: string): Set<string>¶
Commits already backported with git cherry-pick -x. Patch-id matching
(git log --cherry-pick) misses those that needed conflict resolution,
the recorded source hash does not.
Raw JSDoc
Calls:
tryGitlog.matchAllhashes.addhash.toLowerCase
Code
function getPickedHashes(source: string): Set<string> {
const base = tryGit('merge-base', 'HEAD', source)
const range = base ? `${base}..HEAD` : 'HEAD'
const log = tryGit('log', range, '--format=%B') ?? ''
const hashes = new Set<string>()
for (const [, hash] of log.matchAll(/cherry picked from commit ([0-9a-f]{7,40})/gi))
hashes.add(hash.toLowerCase())
return hashes
}
label(commit: Commit): string¶
Parameters:
commitCommit
Returns: string
Calls:
colors.redcolors.yellow
Code
selectCommits(commits: Commit[]): Promise<Commit[]>¶
Parameters:
commitsCommit[]
Returns: Promise<Commit[]>
Calls:
commits.filterfatalcolors.cyanconsola.promptcommits.maplabelcommits.filter(i => !i.breaking).mapset.has
Code
async function selectCommits(commits: Commit[]): Promise<Commit[]> {
if (args.yes)
return commits.filter(i => !i.breaking)
if (!process.stdin.isTTY)
fatal(`Not a TTY, pass ${colors.cyan('--yes')} to run non-interactively`)
const answer = await consola.prompt('Select the commits to backport', {
type: 'multiselect',
required: false,
cancel: 'symbol',
options: commits.map(commit => ({
value: commit.hash,
label: label(commit),
hint: `${commit.date} ยท ${commit.author}${commit.breaking ? ' ยท breaking' : ''}`,
})),
initial: commits.filter(i => !i.breaking).map(i => i.hash),
}) as unknown as string[] | symbol
if (typeof answer === 'symbol')
fatal('Aborted')
const set = new Set(answer)
return commits.filter(i => set.has(i.hash))
}
Interfaces¶
Commit¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
hash |
string |
โ | not shown |
short |
string |
โ | not shown |
subject |
string |
โ | not shown |
body |
string |
โ | not shown |
author |
string |
โ | not shown |
date |
string |
โ | not shown |
breaking |
boolean |
โ | not shown |
Generated by Syntax Scribe