forked from santanu-atta03/Intervyo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-prs.ps1
More file actions
215 lines (179 loc) · 7.79 KB
/
create-prs.ps1
File metadata and controls
215 lines (179 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<#
.SYNOPSIS
Creates multiple PR branches from current changes for Intervyo project
.DESCRIPTION
This script splits your current changes into 9 separate branches,
each containing related changes for individual PRs
#>
Write-Host "Intervyo Multi-PR Branch Creator" -ForegroundColor Cyan
Write-Host ("=" * 60) -ForegroundColor Cyan
# Check if we're in a git repository
if (-not (Test-Path ".git")) {
Write-Host "Error: Not in a git repository!" -ForegroundColor Red
exit 1
}
# Check for uncommitted changes
$status = git status --porcelain
if (-not $status) {
Write-Host "Error: No changes to commit!" -ForegroundColor Red
exit 1
}
Write-Host "`nCurrent changes detected:" -ForegroundColor Yellow
git status --short
Write-Host "`nThis script will:" -ForegroundColor Yellow
Write-Host " 1. Create a backup branch with all changes" -ForegroundColor Gray
Write-Host " 2. Create 9 separate feature branches from main" -ForegroundColor Gray
Write-Host " 3. Push all branches to origin" -ForegroundColor Gray
Write-Host "`nMake sure you've pulled the latest changes from main!" -ForegroundColor Yellow
$confirm = Read-Host "`nDo you want to continue? (yes/no)"
if ($confirm -ne "yes") {
Write-Host "Aborted by user" -ForegroundColor Red
exit 0
}
# Get current branch
$currentBranch = git branch --show-current
Write-Host "`nCurrent branch: $currentBranch" -ForegroundColor Cyan
# Stage all changes
Write-Host "`nStaging all changes..." -ForegroundColor Cyan
git add .
# Create backup branch
$backupBranch = "backup-all-improvements-$(Get-Date -Format 'yyyy-MM-dd-HHmmss')"
Write-Host "`nCreating backup branch: $backupBranch" -ForegroundColor Green
git stash push -m "All improvements for multi-PR split"
git branch $backupBranch
git stash pop
Write-Host "Backup branch created" -ForegroundColor Green
# Function to create a PR branch
function New-PRBranch {
param(
[string]$BranchName,
[string]$CommitMessage,
[string[]]$Files,
[int]$PRNumber
)
Write-Host "`n" + ("=" * 60) -ForegroundColor Cyan
Write-Host "PR #$PRNumber - Creating branch: $BranchName" -ForegroundColor Cyan
Write-Host ("=" * 60) -ForegroundColor Cyan
# Go back to main
Write-Host " Switching to main..." -ForegroundColor Gray
git checkout main 2>$null
# Create new branch
Write-Host " Creating branch: $BranchName" -ForegroundColor Gray
git checkout -b $BranchName 2>$null
# Copy files from backup branch
Write-Host " Adding files:" -ForegroundColor Gray
foreach ($file in $Files) {
Write-Host " - $file" -ForegroundColor DarkGray
# Check if file exists in backup branch
$fileExists = git ls-tree -r $backupBranch --name-only | Select-String -Pattern "^$file$" -Quiet
if ($fileExists) {
# File exists, checkout from backup
git checkout $backupBranch -- $file 2>$null
} else {
# New file, checkout from current stash/staging
if (Test-Path $file) {
git add $file 2>$null
} else {
Write-Host " Warning: File not found: $file" -ForegroundColor Yellow
}
}
}
# Check if there are changes to commit
$hasChanges = git diff --cached --quiet; $LASTEXITCODE -ne 0
if ($hasChanges) {
# Commit
Write-Host " Committing..." -ForegroundColor Gray
git commit -m $CommitMessage 2>$null
# Push
Write-Host " Pushing to origin..." -ForegroundColor Gray
git push -u origin $BranchName 2>$null
Write-Host " Branch created and pushed successfully!" -ForegroundColor Green
return $true
} else {
Write-Host " No changes to commit, skipping..." -ForegroundColor Yellow
git checkout main 2>$null
git branch -D $BranchName 2>$null
return $false
}
}
# Create all PR branches
$successCount = 0
# PR #1 - Fix duplicate socket initialization
# Note: This requires manual editing of index.js, so we'll skip auto-creation
Write-Host "`nPR #1, #2, #3 require manual editing of Backend/index.js" -ForegroundColor Yellow
Write-Host " These will need to be created manually to isolate changes" -ForegroundColor Gray
# PR #4 - Environment validation
if (New-PRBranch -BranchName "feat/env-validation" `
-CommitMessage "feat: Add environment variable validation system" `
-Files @("Backend/config/env.validation.js") `
-PRNumber 4) {
$successCount++
}
# PR #5 - Security middleware
if (New-PRBranch -BranchName "feat/security-middleware" `
-CommitMessage "feat: Add comprehensive security middleware suite" `
-Files @("Backend/middlewares/security.middleware.js") `
-PRNumber 5) {
$successCount++
}
# PR #6 - Admin authorization
if (New-PRBranch -BranchName "feat/admin-authorization" `
-CommitMessage "feat: Implement admin authorization middleware and role check" `
-Files @(
"Backend/middlewares/admin.middleware.js",
"Backend/routes/questionDatabase.routes.js",
"Backend/controllers/QuestionDatabase.controller.js"
) `
-PRNumber 6) {
$successCount++
}
# PR #7 - Performance monitoring
if (New-PRBranch -BranchName "feat/performance-monitoring" `
-CommitMessage "feat: Add real-time performance monitoring system" `
-Files @("Backend/utils/performance.monitor.js") `
-PRNumber 7) {
$successCount++
}
# PR #8 - Enhanced .env.example
if (New-PRBranch -BranchName "docs/enhance-env-example" `
-CommitMessage "docs: Enhance .env.example with comprehensive documentation" `
-Files @("Backend/.env.example") `
-PRNumber 8) {
$successCount++
}
# PR #9 - Comprehensive documentation
if (New-PRBranch -BranchName "docs/comprehensive-guides" `
-CommitMessage "docs: Add comprehensive API, deployment, and development documentation" `
-Files @(
"Backend/docs/API.md",
"Backend/docs/DEPLOYMENT.md",
"Backend/docs/FEATURE_DEVELOPMENT.md",
"CHANGELOG.md",
"README.md"
) `
-PRNumber 9) {
$successCount++
}
# Return to main branch
Write-Host "`nReturning to main branch..." -ForegroundColor Cyan
git checkout main 2>$null
# Summary
Write-Host "`n" + ("=" * 60) -ForegroundColor Green
Write-Host "Branch Creation Complete!" -ForegroundColor Green
Write-Host ("=" * 60) -ForegroundColor Green
Write-Host "`nSummary:" -ForegroundColor Cyan
Write-Host " Successfully created: $successCount branches" -ForegroundColor Green
Write-Host " Manual creation needed: 3 branches (index.js changes)" -ForegroundColor Yellow
Write-Host " Backup branch: $backupBranch" -ForegroundColor Gray
Write-Host "`nCreated Branches:" -ForegroundColor Cyan
git branch -r | Select-String "feat/|docs/" | ForEach-Object {
Write-Host " - $($_.ToString().Trim())" -ForegroundColor Gray
}
Write-Host "`nNext Steps:" -ForegroundColor Cyan
Write-Host " 1. Go to GitHub and create PRs from each pushed branch" -ForegroundColor Gray
Write-Host " 2. Manually create PR #1, #2, #3 for Backend/index.js changes:" -ForegroundColor Gray
Write-Host " - fix/duplicate-socket-init" -ForegroundColor DarkGray
Write-Host " - feat/graceful-shutdown" -ForegroundColor DarkGray
Write-Host " - feat/enhanced-health-check" -ForegroundColor DarkGray
Write-Host "`nTip: Use the backup branch ($backupBranch) if you need to reference all changes" -ForegroundColor Yellow
Write-Host "`nHappy contributing!" -ForegroundColor Green