4545 - name : Create Script
4646 run : |
4747 mkdir -p _data
48- cat << 'EOF' > fetch-draft-hips.js
48+ cat << \ 'EOF\ ' > fetch-draft-hips.js
4949 const https = require('https');
5050 const fs = require('fs');
5151
8888 edges {
8989 node {
9090 path
91+ changeType
9192 additions
9293 deletions
9394 }
@@ -107,6 +108,12 @@ jobs:
107108
108109 if (result.errors) {
109110 console.error('GraphQL errors:', result.errors);
111+ process.exit(1);
112+ }
113+
114+ // Check if data and the expected path to nodes exist
115+ if (!result.data || !result.data.repository || !result.data.repository.pullRequests || !result.data.repository.pullRequests.nodes) {
116+ console.error('Unexpected GraphQL response structure:', result);
110117 process.exit(1);
111118 }
112119
@@ -118,21 +125,31 @@ jobs:
118125 }
119126
120127 // Run the main function
121- getAllPRs().then(prs => {
122- // Ensure we're completely replacing the file by writing fresh data
123- // If the file exists, it will be overwritten entirely
128+ getAllPRs().then(allPRs => {
129+ const draftHIPPRs = allPRs.filter(pr => {
130+ if (!pr.files || !pr.files.edges) {
131+ return false;
132+ }
133+ const hipFiles = pr.files.edges.filter(edge => {
134+ const fileNode = edge.node;
135+ const isNewHIPFile = /^HIP\\/hip-[a-zA-Z0-9-]+\\.md$/.test(fileNode.path); // New regex
136+ return fileNode.changeType === 'ADDED' && isNewHIPFile;
137+ }).map(edge => edge.node);
138+
139+ return hipFiles.length > 0;
140+ });
141+
124142 const outputPath = '_data/draft_hips.json';
125143
126- // Remove the file if it exists (optional, as writeFileSync will overwrite it anyway)
127144 if (fs.existsSync(outputPath)) {
128145 console.log(`Removing existing file: ${outputPath}`);
129146 fs.unlinkSync(outputPath);
130147 }
131148
132- console.log(`Writing fresh data to: ${outputPath}`);
133- fs.writeFileSync(outputPath, JSON.stringify(prs , null, 2));
149+ console.log(`Writing ${draftHIPPRs.length} filtered PRs to: ${outputPath}`);
150+ fs.writeFileSync(outputPath, JSON.stringify(draftHIPPRs , null, 2));
134151 }).catch(error => {
135- console.error('Failed to fetch PRs:', error);
152+ console.error('Failed to fetch and filter PRs:', error);
136153 process.exit(1);
137154 });
138155 EOF
0 commit comments