Skip to content

feat(package): add stage-override-to-pr-base script#55

Closed
dario-fazio wants to merge 8 commits into
mainfrom
#181-stage-override-to-pr-base
Closed

feat(package): add stage-override-to-pr-base script#55
dario-fazio wants to merge 8 commits into
mainfrom
#181-stage-override-to-pr-base

Conversation

@dario-fazio
Copy link
Copy Markdown
Contributor

@dario-fazio dario-fazio commented Aug 4, 2025

dario-fazio and others added 8 commits August 4, 2025 10:56
 - @shiftcode/branch-utilities@4.1.0-pr181.0
 - @shiftcode/publish-helper@4.0.1-pr181.0
 - @shiftcode/branch-utilities@4.1.0-pr181.1
 - @shiftcode/publish-helper@4.0.1-pr181.1
 - @shiftcode/branch-utilities@4.1.0-pr181.2
 - @shiftcode/publish-helper@4.1.0-pr181.0
 - @shiftcode/branch-utilities@4.1.0-pr181.3
 - @shiftcode/publish-helper@4.1.0-pr181.1
@dario-fazio dario-fazio marked this pull request as ready for review August 5, 2025 13:45
@michaelwittwer michaelwittwer requested a review from Copilot August 7, 2025 09:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new command-line script stage-override-to-pr-base to the branch-utilities package that determines branch override settings and PR status for CI/CD workflows. The script outputs environment variables to configure branch name overrides and PR detection.

Key changes:

  • Adds new CLI script with yargs command-line interface
  • Implements core function to detect PR status using GitHub CLI
  • Updates package versions to prerelease format for testing

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/branch-utilities/src/stage-override-to-pr-base.ts New CLI entry point script with yargs argument parsing
packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts Core function implementing PR detection logic using GitHub CLI
packages/branch-utilities/src/scripts/index.ts Export barrel for the new function
packages/branch-utilities/package.json Adds binary entry point and yargs dependency
packages/publish-helper/package.json Updates dependency versions to prerelease format

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.
Comment on lines +7 to +16
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)
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.
Comment on lines +18 to +21
return `
export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride}
export SC_OVERRIDE_IS_PR=${isPrOverride}
`
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.
): 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.
Comment thread packages/branch-utilities/src/stage-override-to-pr-base.ts
@michaelwittwer
Copy link
Copy Markdown
Member

@dario-fazio closing as this is now part of https://github.com/shiftcode/sc-commons/pull/215

@michaelwittwer michaelwittwer deleted the #181-stage-override-to-pr-base branch August 13, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants