Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/branch-utilities/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shiftcode/branch-utilities",
"version": "4.0.0",
"version": "4.1.0-pr181.3",
"description": "Utilities for local and ci to get branch name and stage",
"repository": "https://github.com/shiftcode/sc-commons-public",
"license": "MIT",
Expand All @@ -13,6 +13,9 @@
"default": "./dist/index.js"
}
},
"bin": {
"stage-override-to-pr-base": "./dist/stage-override-to-pr-base.js"
},
"scripts": {
"prebuild": "rm -rf ./dist",
"build": "tsc",
Expand All @@ -28,6 +31,9 @@
"test:ci": "npm run test",
"test:watch": "npm run test -- --watch"
},
"dependencies": {
"yargs": "^17.7.2"
},
"peerDependencies": {
"tslib": "^2.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/branch-utilities/src/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './stage-override-to-pr-base.function.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { execSync } from 'node:child_process'

export interface StageOverrideToPrBaseOptions {
branchNameOverride?: string
}

export async function stageOverrideToPrBase(
options: StageOverrideToPrBaseOptions | Promise<StageOverrideToPrBaseOptions>,
): Promise<string> {
const opts = await options

const gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim()
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The execSync call should include error handling for cases where the gh command fails (e.g., not authenticated, repository not found, or GitHub CLI not installed).

Suggested change
const gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim()
let gitHubPrJson: string
try {
gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim()
} catch (error: any) {
console.error(
'Failed to execute "gh pr list". Please ensure that the GitHub CLI (gh) is installed, you are authenticated, and you are in a valid repository.',
)
if (error.stderr) {
console.error('Error details:', error.stderr.toString())
}
throw error
}

Copilot uses AI. Check for mistakes.
const gitHubPrs = JSON.parse(gitHubPrJson)

const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF']
const isPrOverride = !!gitHubPrs.find((pr: any) => pr.headRefName === branchNameOverride)
Comment on lines +7 to +16
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type defeats TypeScript's type safety. Consider defining a proper interface for the PR object with properties like headRefName, title, isDraft, and closed.

Suggested change
export async function stageOverrideToPrBase(
options: StageOverrideToPrBaseOptions | Promise<StageOverrideToPrBaseOptions>,
): Promise<string> {
const opts = await options
const gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim()
const gitHubPrs = JSON.parse(gitHubPrJson)
const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF']
const isPrOverride = !!gitHubPrs.find((pr: any) => pr.headRefName === branchNameOverride)
interface GitHubPr {
headRefName: string
title: string
isDraft: boolean
closed: boolean
}
export async function stageOverrideToPrBase(
options: StageOverrideToPrBaseOptions | Promise<StageOverrideToPrBaseOptions>,
): Promise<string> {
const opts = await options
const gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim()
const gitHubPrs: GitHubPr[] = JSON.parse(gitHubPrJson)
const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF']
const isPrOverride = !!gitHubPrs.find((pr: GitHubPr) => pr.headRefName === branchNameOverride)

Copilot uses AI. Check for mistakes.

return `
export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride}
export SC_OVERRIDE_IS_PR=${isPrOverride}
`
Comment on lines +18 to +21
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned string contains leading whitespace that may cause issues when sourced as shell commands. Consider using a trimmed template literal or removing the indentation.

Suggested change
return `
export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride}
export SC_OVERRIDE_IS_PR=${isPrOverride}
`
return `export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride}
export SC_OVERRIDE_IS_PR=${isPrOverride}
`

Copilot uses AI. Check for mistakes.
}
19 changes: 19 additions & 0 deletions packages/branch-utilities/src/stage-override-to-pr-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node
/* eslint-disable no-console */
import yargs from 'yargs'
import { stageOverrideToPrBase } from './scripts/index.js'

const args = yargs(process.argv)
.option('branchNameOverride', {
alias: 'b',
type: 'string',
description: 'branch name override to be used as PR base',
}).argv
Comment thread
dario-fazio marked this conversation as resolved.

try {
const responseMsg = await stageOverrideToPrBase(args)
console.info(responseMsg)
}catch (err){
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after closing brace. Should be } catch (err) { to follow standard JavaScript formatting conventions.

Suggested change
}catch (err){
} catch (err) {

Copilot uses AI. Check for mistakes.
console.error(err)
process.exit(1)
}
6 changes: 3 additions & 3 deletions packages/publish-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shiftcode/publish-helper",
"version": "4.0.0",
"version": "4.1.0-pr181.1",
"description": "scripts for conventional (pre)releases",
"repository": "https://github.com/shiftcode/sc-commons-public",
"license": "MIT",
Expand Down Expand Up @@ -30,11 +30,11 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@shiftcode/branch-utilities": "^4.0.0",
"@shiftcode/branch-utilities": "^4.1.0-pr181.3",
"@types/yargs": "^17.0.32"
},
"peerDependencies": {
"@shiftcode/branch-utilities": "^4.0.0 || ^4.0.0-pr45",
"@shiftcode/branch-utilities": "^4.1.0 || ^4.1.0-pr181",
"lerna": "^8.1.6",
"tslib": "^2.3.0"
},
Expand Down