Skip to content

Commit b58260a

Browse files
committed
Fix parsing errors in migration scripts
- Fix missing closing brace in mongo-migrate.js conditional block - Fix missing closing parenthesis in verifyMigration function call - Resolve syntax errors that prevented linting from completing - Scripts now parse correctly for further linting improvements
1 parent e1d9318 commit b58260a

6 files changed

Lines changed: 685 additions & 55 deletions

File tree

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Process Pull Request Comments
2+
3+
## Purpose
4+
This workflow processes analyzed pull request comments from `./tmp/PR_CONVERSATIONS.md` and executes actions based on the Decision field for each relevant comment.
5+
6+
## Prerequisites
7+
- Analysis file exists at: `./tmp/PR_CONVERSATIONS.md`
8+
- Scripts available: `scripts/resolve-pr-conversation.js`
9+
- GitHub CLI configured for issue creation
10+
11+
## Process Flow
12+
13+
### 1. Read Analysis File
14+
- Load `./tmp/PR_CONVERSATIONS.md`
15+
- Parse all comments into structured data
16+
- Extract fields: Id, Status, Decision, Comment Body, PR Number, etc.
17+
18+
### 2. Process Each Conversation
19+
20+
#### Step 2.1: Check Id Field
21+
- **If Id = "Local"**: Skip to next conversation (no resolution needed - created by local tool)
22+
- **Otherwise**: Continue to Step 2.2
23+
24+
#### Step 2.2: Check Status Field
25+
- **If Status = "OUTDATED"**:
26+
- Execute: `node scripts/resolve-pr-conversation.js CONVERSATION_ID "Marked as outdated"`
27+
- Skip to next conversation
28+
- **Otherwise**: Continue to Step 2.3
29+
30+
#### Step 2.3: Process Based on Decision Field
31+
32+
| Decision Value | Action | Resolution Comment |
33+
|----------------|--------|-------------------|
34+
| IGNORE or Empty | Skip to next conversation | N/A |
35+
| RESOLVE | Mark as resolved only | "Acknowledged and resolved" |
36+
| PROCESS or FIX | 1. Apply fix using common rules<br>2. Mark as resolved | "Fixed: [7-15 word description of what was done]" |
37+
| Create Issue or Fix later | 1. Create GitHub issue<br>2. Add links (PR ↔ Issue)<br>3. Mark as resolved | "Created issue #[number] for future fix" |
38+
39+
### 3. Resolution Command Format
40+
```bash
41+
node scripts/resolve-pr-conversation.js CONVERSATION_ID "Your comment here"
42+
```
43+
44+
## Visual Process Diagrams
45+
46+
### Main Process Flow Diagram
47+
```mermaid
48+
flowchart TD
49+
Start([Start: Process PR Comments]) --> ReadFile[Read ./tmp/PR_CONVERSATIONS.md]
50+
ReadFile --> ParseComments[Parse Comments into Structured Data]
51+
ParseComments --> StartLoop{For Each Conversation}
52+
53+
StartLoop --> CheckId{Is Id = Local?}
54+
CheckId -->|Yes| NextConv[Skip to Next Conversation]
55+
CheckId -->|No| CheckStatus{Is Status = OUTDATED?}
56+
57+
CheckStatus -->|Yes| ResolveOutdated[Execute: resolve-pr-conversation.js<br/>with 'Marked as outdated']
58+
ResolveOutdated --> NextConv
59+
60+
CheckStatus -->|No| CheckDecision{Check Decision Field}
61+
62+
CheckDecision -->|IGNORE or Empty| NextConv
63+
CheckDecision -->|RESOLVE| ResolveOnly[Mark as Resolved<br/>Comment: 'Acknowledged and resolved']
64+
CheckDecision -->|PROCESS or FIX| ProcessFix[1. Apply Fix Using Common Rules<br/>2. Mark as Resolved<br/>Comment: 'Fixed: 7-15 word description']
65+
CheckDecision -->|Create Issue or<br/>Fix later| CreateIssue[1. Create GitHub Issue<br/>2. Add PR-Issue Links<br/>3. Mark as Resolved<br/>Comment: 'Created issue #number for future fix']
66+
67+
ResolveOnly --> NextConv
68+
ProcessFix --> NextConv
69+
CreateIssue --> NextConv
70+
71+
NextConv --> MoreConv{More Conversations?}
72+
MoreConv -->|Yes| StartLoop
73+
MoreConv -->|No| End([End])
74+
75+
%% Styling
76+
classDef decision fill:#f9f,stroke:#333,stroke-width:2px
77+
classDef action fill:#bbf,stroke:#333,stroke-width:2px
78+
classDef terminal fill:#9f9,stroke:#333,stroke-width:2px
79+
80+
class CheckId,CheckStatus,CheckDecision,StartLoop,MoreConv decision
81+
class ReadFile,ParseComments,ResolveOutdated,ResolveOnly,ProcessFix,CreateIssue,NextConv action
82+
class Start,End terminal
83+
```
84+
85+
### Common Rules Application Diagram (For PROCESS/FIX Decision)
86+
```mermaid
87+
flowchart LR
88+
subgraph ProcessFix[Process/Fix Workflow]
89+
direction TB
90+
Start2([Decision = PROCESS/FIX]) --> ApplyRules[Apply Common Rules]
91+
92+
ApplyRules --> Rule1[no-apologies-rule:<br/>Remove any apologies]
93+
ApplyRules --> Rule2[no-summaries-rule:<br/>Don't summarize changes]
94+
ApplyRules --> Rule3[no-unnecessary-confirmations-rule:<br/>Don't ask for confirmation]
95+
ApplyRules --> Rule4[no-unnecessary-updates-rule:<br/>Only make needed changes]
96+
ApplyRules --> Rule5[preserve-existing-code-rule:<br/>Keep unrelated code intact]
97+
98+
Rule1 --> ImplementFix[Implement the Fix]
99+
Rule2 --> ImplementFix
100+
Rule3 --> ImplementFix
101+
Rule4 --> ImplementFix
102+
Rule5 --> ImplementFix
103+
104+
ImplementFix --> CreateComment[Create 7-15 Word Summary<br/>of What Was Fixed]
105+
CreateComment --> ResolveConv[Execute: resolve-pr-conversation.js<br/>CONVERSATION_ID 'Fixed: summary']
106+
end
107+
108+
%% Styling
109+
classDef rules fill:#ffd,stroke:#333,stroke-width:2px
110+
classDef process fill:#ddf,stroke:#333,stroke-width:2px
111+
112+
class Rule1,Rule2,Rule3,Rule4,Rule5 rules
113+
class ApplyRules,ImplementFix,CreateComment,ResolveConv process
114+
```
115+
116+
## Comment Guidelines
117+
- Rephrase comments to fix English grammar
118+
- Keep original wording/intent
119+
- For processed/fixed items: Create concise 7-15 word summary of action taken
120+
- Be specific about what was changed or fixed
121+
122+
## Error Handling
123+
- If conversation ID not found: Log and continue
124+
- If GitHub issue creation fails: Log error, mark conversation with error note
125+
- If resolution script fails: Retry once, then log failure
126+
127+
## Common Rules Reference
128+
When Decision = PROCESS or FIX, apply these rules:
129+
- no-apologies-rule
130+
- no-summaries-rule
131+
- no-unnecessary-confirmations-rule
132+
- no-unnecessary-updates-rule
133+
- preserve-existing-code-rule
134+
135+
## Quick Reference Flowchart
136+
137+
### Main Process Flow
138+
1. Read `./tmp/PR_CONVERSATIONS.md`
139+
2. For each conversation:
140+
- Local? → Skip
141+
- OUTDATED? → Resolve with "Marked as outdated"
142+
- Decision:
143+
- IGNORE/Empty → Skip
144+
- RESOLVE → Resolve with "Acknowledged and resolved"
145+
- PROCESS/FIX → Apply fix, resolve with action summary
146+
- Create Issue/Fix later → Create issue, add links, resolve
147+
148+
### Resolution Command
149+
```bash
150+
node scripts/resolve-pr-conversation.js CONVERSATION_ID "Your comment"
151+
```
152+
153+
### Decision Matrix
154+
| Decision | Action Required | Resolution Comment Template |
155+
|----------|----------------|---------------------------|
156+
| Local ID | None (Skip) | N/A |
157+
| OUTDATED | Resolve only | "Marked as outdated" |
158+
| IGNORE | None (Skip) | N/A |
159+
| Empty | None (Skip) | N/A |
160+
| RESOLVE | Resolve only | "Acknowledged and resolved" |
161+
| PROCESS | Fix + Resolve | "Fixed: [specific action taken]" |
162+
| FIX | Fix + Resolve | "Fixed: [specific action taken]" |
163+
| Create Issue | Issue + Resolve | "Created issue #[num] for future fix" |
164+
| Fix later | Issue + Resolve | "Created issue #[num] for future fix" |
165+
166+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Handle Pull Request Comments
7+
8+
## Purpose
9+
This workflow analyzes pull request comments against the current codebase to identify which comments are still relevant and need to be addressed.
10+
11+
## Process
12+
13+
1. Get PR Number: `npx tsx scripts/get-pr-number.ts`
14+
2. Fetch PR Comments: `npx tsx scripts/list-pr-conversations.ts <PR_NUMBER>`
15+
3. Analyze Comments
16+
For each comment retrieved:
17+
- Review the comment content
18+
- Check if the mentioned code/issue still relevant in the current codebase
19+
- Categorize as:
20+
- **RELEVANT**: The issue or suggestion mentioned still applies (even if code moved to different location)
21+
- **OUTDATED**: The issue has been addressed or code has changed
22+
23+
**Relevance is determined by the intent of the comment, not exact code location:**
24+
- If problematic pattern still exists anywhere → RELEVANT
25+
- If suggestion hasn't been implemented → RELEVANT
26+
- If issue was fixed/refactored → OUTDATED
27+
- If code was removed entirely → OUTDATED
28+
29+
### 4. Generate Report
30+
Create a detailed report that includes:
31+
- Summary of all comments analyzed
32+
- List of comments that are still relevant
33+
- if issue is still relevant, provide recommendation for addressing the comment
34+
- Any comments that need further investigation
35+
36+
#### Edge Cases:
37+
- **Bot comments**: Treat bot comments (e.g., from copilot-pull-request-reviewer) the same as human comments
38+
- **Deleted files**: If a comment references a file that no longer exists, mark as OUTDATED
39+
- **Vague comments**: Comments without specific details (e.g., "this looks wrong") should be marked as RELEVANT
40+
- **Decision field**: Always leave the Decision field empty for the user to fill in later
41+
42+
### 5. Save the analysis report to `./tmp/PR_CONVERSATIONS.md`, Use the following structure:
43+
44+
```markdown
45+
# All Conversations for PR #4:
46+
47+
## ❌ OUTDATED (Fixed by previous changes):
48+
49+
### **<relative path to file>:<line>**
50+
Id: <conversation id>
51+
Author: <the author of a comment>
52+
Description: <once sentence up to 40 words what actually this comment about>
53+
----
54+
<Full text of original comment>
55+
----
56+
Status: <RELEVANT>:<Explanation why this is relevant>
57+
58+
## ✅ STILL RELEVANT (Need to be fixed):
59+
60+
### **<relative path to file>:<line>**
61+
Id: <conversation id>
62+
Author: <the author of a comment>
63+
Description: <once sentence up to 40 words what actually this comment about>
64+
----
65+
<Full text of original comment>
66+
----
67+
Status: <RELEVANT>:<Explanation why this is relevant>
68+
Recommendation: <Recommendation whether this issue needs to be processed or ignored>
69+
Decision:
70+
71+
```
72+
73+
## Important Notes
74+
- The `list-pr-comments.ts` script outputs JSON to console for programmatic processing
75+
- Each comment includes: file, line, author, body, createdAt, outdated, resolved, diffHunk, and url
76+
- Comments are automatically sorted by creation date

website/scripts/get-pr-number.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* eslint-disable no-console */
2+
3+
/**
4+
* Get PR Number Script
5+
*
6+
* This script reveals the Pull Request number associated with
7+
* the current git branch. It uses the GitHub CLI (gh) to search
8+
* for open PRs linked to the current branch.
9+
*
10+
* Usage:
11+
* Direct execution: ./scripts/get-pr-number.js
12+
* Via npm: npm run pr
13+
*
14+
* Requirements:
15+
* - GitHub CLI (gh) must be installed: https://cli.github.com/
16+
* - Must be run from within a git repository
17+
* - Repository must be hosted on GitHub
18+
*
19+
* Output:
20+
* - Shows PR number, title, state, and URL
21+
* - If no open PR is found, shows closed/merged PRs
22+
* - Displays just the PR number at the end for easy scripting
23+
*/
24+
25+
const { execSync } = require('child_process');
26+
27+
function getCurrentBranch() {
28+
try {
29+
const branch = execSync('git rev-parse --abbrev-ref HEAD', {
30+
encoding: 'utf8',
31+
}).trim();
32+
return branch;
33+
} catch (error) {
34+
console.error('Error getting current branch:', error);
35+
process.exit(1);
36+
}
37+
}
38+
39+
/**
40+
* Handles various error conditions when fetching PR information
41+
* @param {unknown} error - The error object to handle
42+
*/
43+
function handleError(error) {
44+
if (error instanceof Error) {
45+
if (error.message.includes('gh: command not found')) {
46+
console.error(
47+
'GitHub CLI (gh) is not installed. Please install it first:',
48+
);
49+
console.error('https://cli.github.com/manual/installation');
50+
} else if (error.message.includes('Could not resolve to a Repository')) {
51+
console.error(
52+
'This directory does not appear to be a GitHub repository.',
53+
);
54+
} else {
55+
console.error('Error fetching PR information:', error.message);
56+
}
57+
} else {
58+
console.error('Unknown error:', error);
59+
}
60+
process.exit(1);
61+
}
62+
63+
/**
64+
* Displays pull request information
65+
* @param {Object} pr - The pull request object
66+
* @param {number} pr.number - PR number
67+
* @param {string} pr.title - PR title
68+
* @param {string} pr.state - PR state
69+
* @param {string} pr.url - PR URL
70+
* @param {string} branch - The branch name
71+
*/
72+
function displayPR(pr, branch) {
73+
console.log(`\nCurrent branch: ${branch}`);
74+
console.log(`PR #${pr.number}: ${pr.title}`);
75+
console.log(`State: ${pr.state}`);
76+
console.log(`URL: ${pr.url}`);
77+
78+
// Output just the PR number for easy scripting
79+
console.log(`\nPR Number: ${pr.number}`);
80+
}
81+
82+
/**
83+
* Checks for closed or merged PRs for the given branch
84+
* @param {string} branch - The branch name to check
85+
*/
86+
function checkForClosedPRs(branch) {
87+
const allPRsResult = execSync(
88+
`gh pr list --head "${branch}" --state all ` +
89+
`--json number,title,state,url --limit 5`,
90+
{ encoding: 'utf8' },
91+
);
92+
93+
const allPRs = JSON.parse(allPRsResult);
94+
if (allPRs.length > 0) {
95+
console.log('\nFound closed/merged PRs:');
96+
allPRs.forEach((pr) => {
97+
console.log(` PR #${pr.number}: ${pr.title} (${pr.state})`);
98+
console.log(` URL: ${pr.url}`);
99+
});
100+
}
101+
}
102+
103+
/**
104+
* Gets PR information for the given branch
105+
* @param {string} branch - The branch name to get PR information for
106+
*/
107+
function getPRForBranch(branch) {
108+
if (branch === 'main' || branch === 'master') {
109+
console.log('Current branch is the default branch. No PR associated.');
110+
return;
111+
}
112+
113+
try {
114+
// First, try to get PR using GitHub CLI search
115+
const result = execSync(
116+
`gh pr list --head "${branch}" --json number,title,state,url --limit 1`,
117+
{ encoding: 'utf8' },
118+
);
119+
120+
const prs = JSON.parse(result);
121+
122+
if (prs.length === 0) {
123+
console.log(`No PR found for branch: ${branch}`);
124+
125+
// Try to find PRs that might have been merged or closed
126+
checkForClosedPRs(branch);
127+
return;
128+
}
129+
130+
displayPR(prs[0], branch);
131+
} catch (error) {
132+
handleError(error);
133+
}
134+
}
135+
136+
// Main execution
137+
const currentBranch = getCurrentBranch();
138+
console.log(`Checking for PR associated with branch: ${currentBranch}`);
139+
getPRForBranch(currentBranch);

0 commit comments

Comments
 (0)