55 - cron : " 0 */6 * * *" # Runs every 6 hours
66 workflow_dispatch : # Allows manual triggering
77
8+ permissions :
9+ contents : read
10+
811jobs :
912 update-draft-hips :
1013 if : ${{ github.ref == 'refs/heads/main' }} # Only run on main branch
@@ -13,15 +16,20 @@ jobs:
1316 contents : write
1417 pull-requests : read
1518 steps :
19+ - name : Harden the runner (Audit all outbound calls)
20+ uses : step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
21+ with :
22+ egress-policy : audit
23+
1624 - name : Checkout Code
17- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1826 with :
1927 token : ${{ secrets.GH_ACCESS_TOKEN }}
2028 ref : ' main'
2129
2230 - name : Import GPG Key
2331 id : gpg_importer
24- uses : step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1 .0
32+ uses : step-security/ghaction-import-gpg@c86c374c0659a6c2d1284bccf8af889e73ce8fe0 # v6.3 .0
2533 with :
2634 git_commit_gpgsign : true
2735 git_tag_gpgsign : true
8088 edges {
8189 node {
8290 path
91+ changeType
8392 additions
8493 deletions
8594 }
@@ -99,6 +108,12 @@ jobs:
99108
100109 if (result.errors) {
101110 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);
102117 process.exit(1);
103118 }
104119
@@ -110,21 +125,31 @@ jobs:
110125 }
111126
112127 // Run the main function
113- getAllPRs().then(prs => {
114- // Ensure we're completely replacing the file by writing fresh data
115- // 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);
136+ return fileNode.changeType === 'ADDED' && isNewHIPFile;
137+ }).map(edge => edge.node);
138+
139+ return hipFiles.length > 0;
140+ });
141+
116142 const outputPath = '_data/draft_hips.json';
117143
118- // Remove the file if it exists (optional, as writeFileSync will overwrite it anyway)
119144 if (fs.existsSync(outputPath)) {
120145 console.log(`Removing existing file: ${outputPath}`);
121146 fs.unlinkSync(outputPath);
122147 }
123148
124- console.log(`Writing fresh data to: ${outputPath}`);
125- 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));
126151 }).catch(error => {
127- console.error('Failed to fetch PRs:', error);
152+ console.error('Failed to fetch and filter PRs:', error);
128153 process.exit(1);
129154 });
130155 EOF
0 commit comments