-
Notifications
You must be signed in to change notification settings - Fork 1
feat(package): add stage-override-to-pr-base script #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b39c517
7af26f3
925837b
01ba996
e3f08f7
664678b
3717a5c
87d4e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
AI
Aug 7, 2025
There was a problem hiding this comment.
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.
| 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} | |
| ` |
| 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 | ||||||
|
dario-fazio marked this conversation as resolved.
|
||||||
|
|
||||||
| try { | ||||||
| const responseMsg = await stageOverrideToPrBase(args) | ||||||
| console.info(responseMsg) | ||||||
| }catch (err){ | ||||||
|
||||||
| }catch (err){ | |
| } catch (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
execSynccall should include error handling for cases where theghcommand fails (e.g., not authenticated, repository not found, or GitHub CLI not installed).