@@ -10,43 +10,8 @@ import type { OctokitResponse } from '@octokit/types'
1010
1111type PullsCreateResponseData = components [ 'schemas' ] [ 'pull-request' ]
1212
13- const {
14- GITHUB_ACTIONS ,
15- GITHUB_REF_NAME ,
16- GITHUB_REPOSITORY ,
17- SOCKET_SECURITY_GITHUB_PAT
18- } = constants
19-
20- async function branchExists (
21- branch : string ,
22- cwd : string | undefined = process . cwd ( )
23- ) : Promise < boolean > {
24- try {
25- await spawn (
26- 'git' ,
27- [ 'show-ref' , '--verify' , '--quiet' , `refs/heads/${ branch } ` ] ,
28- {
29- cwd,
30- stdio : 'ignore'
31- }
32- )
33- return true
34- } catch { }
35- return false
36- }
37-
38- async function checkoutBaseBranchIfAvailable (
39- baseBranch : string ,
40- cwd : string | undefined = process . cwd ( )
41- ) {
42- try {
43- await spawn ( 'git' , [ 'checkout' , baseBranch ] , { cwd } )
44- await spawn ( 'git' , [ 'reset' , '--hard' , `origin/${ baseBranch } ` ] , { cwd } )
45- logger . info ( `Checked out and reset to ${ baseBranch } ` )
46- } catch {
47- logger . warn ( `Could not switch to ${ baseBranch } . Proceeding with HEAD.` )
48- }
49- }
13+ const { GITHUB_ACTIONS , GITHUB_REPOSITORY , SOCKET_SECURITY_GITHUB_PAT } =
14+ constants
5015
5116type GitHubRepoInfo = {
5217 owner : string
@@ -125,13 +90,10 @@ export function getGitHubRepoInfo(): GitHubRepoInfo {
12590 }
12691}
12792
128- export function getSocketBranchName ( name : string , version : string ) : string {
129- return `socket-fix-${ name } -${ version . replace ( / \. / g, '-' ) } `
130- }
131-
13293export async function openGitHubPullRequest (
13394 owner : string ,
13495 repo : string ,
96+ baseBranch : string ,
13597 branch : string ,
13698 name : string ,
13799 version : string ,
@@ -144,30 +106,12 @@ export async function openGitHubPullRequest(
144106 if ( ! pat ) {
145107 throw new Error ( 'Missing SOCKET_SECURITY_GITHUB_PAT environment variable' )
146108 }
147- const baseBranch =
148- // Lazily access constants.ENV[GITHUB_REF_NAME].
149- constants . ENV [ GITHUB_REF_NAME ] ??
150- // GitHub defaults to branch name "main"
151- // https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch
152- 'main'
153-
154109 const commitMsg = `chore: upgrade ${ name } to ${ version } `
155110 const url = `https://x-access-token:${ pat } @github.com/${ owner } /${ repo } `
156111
157112 await spawn ( 'git' , [ 'remote' , 'set-url' , 'origin' , url ] , {
158113 cwd
159114 } )
160-
161- if ( await branchExists ( branch , cwd ) ) {
162- logger . warn ( `Branch "${ branch } " already exists. Skipping creation.` )
163- } else {
164- await checkoutBaseBranchIfAvailable ( baseBranch , cwd )
165- await spawn ( 'git' , [ 'checkout' , '-b' , branch ] , { cwd } )
166- await spawn ( 'git' , [ 'add' , 'package.json' , 'pnpm-lock.yaml' ] , { cwd } )
167- await spawn ( 'git' , [ 'commit' , '-m' , commitMsg ] , { cwd } )
168- await spawn ( 'git' , [ 'push' , '--set-upstream' , 'origin' , branch ] , { cwd } )
169- }
170-
171115 const octokit = getOctokit ( )
172116 return await octokit . pulls . create ( {
173117 owner,
0 commit comments