Skip to content

The agent engineering platform.

fix(infra): resolve module crash blocking external PR enforcement (#36059)

Mason Daughertycf1f510d7742
diff --git a/.github/scripts/pr-labeler.js b/.github/scripts/pr-labeler.js
index bc0639bffb..ac2ff31ba7 100644
--- a/.github/scripts/pr-labeler.js
+++ b/.github/scripts/pr-labeler.js
@@ -1,7 +1,7 @@
// Shared helpers for pr_labeler.yml and tag-external-issues.yml.
//
// Usage from actions/github-script (requires actions/checkout first):
-// const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+// const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const fs = require('fs');
const path = require('path');
@@ -32,7 +32,10 @@ function loadConfig() {
return config;
}
-function init(github, owner, repo, config) {
+function init(github, owner, repo, config, core) {
+ if (!core) {
+ throw new Error('init() requires a `core` parameter (e.g., from actions/github-script)');
+ }
const {
trustedThreshold,
labelColor,
@@ -60,7 +63,6 @@ function init(github, owner, repo, config) {
} catch (createErr) {
// 422 = label created by a concurrent run between our get and create
if (createErr.status !== 422) throw createErr;
- const core = require('@actions/core');
core.info(`Label "${name}" creation returned 422 (likely already exists)`);
}
}
@@ -196,7 +198,6 @@ function init(github, owner, repo, config) {
mergedCount = result?.data?.total_count ?? null;
} catch (e) {
if (e?.status !== 422) throw e;
- const core = require('@actions/core');
core.warning(`Search failed for ${author}; skipping tier.`);
}
}
@@ -209,7 +210,6 @@ function init(github, owner, repo, config) {
// ── Tier label resolution ───────────────────────────────────────────
async function applyTierLabel(issueNumber, author, { skipNewContributor = false } = {}) {
- const core = require('@actions/core');
let mergedCount;
try {
const result = await github.rest.search.issuesAndPullRequests({
@@ -263,9 +263,9 @@ function init(github, owner, repo, config) {
};
}
-function loadAndInit(github, owner, repo) {
+function loadAndInit(github, owner, repo, core) {
const config = loadConfig();
- return { config, h: init(github, owner, repo, config) };
+ return { config, h: init(github, owner, repo, config, core) };
}
module.exports = { loadConfig, init, loadAndInit };
diff --git a/.github/workflows/pr_labeler.yml b/.github/workflows/pr_labeler.yml
index 26127e1627..50edec08cc 100644
--- a/.github/workflows/pr_labeler.yml
+++ b/.github/workflows/pr_labeler.yml
@@ -76,7 +76,7 @@ jobs:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const author = context.payload.sender.login;
const { isExternal } = await h.checkMembership(
@@ -92,7 +92,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const pr = context.payload.pull_request;
if (!pr) return;
@@ -184,7 +184,7 @@ jobs:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const pr = context.payload.pull_request;
await h.applyTierLabel(pr.number, pr.user.login);
@@ -201,7 +201,7 @@ jobs:
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
await h.ensureLabel('external');
await github.rest.issues.addLabels({
diff --git a/.github/workflows/pr_labeler_backfill.yml b/.github/workflows/pr_labeler_backfill.yml
index 4cebfde862..ba75f58257 100644
--- a/.github/workflows/pr_labeler_backfill.yml
+++ b/.github/workflows/pr_labeler_backfill.yml
@@ -48,7 +48,7 @@ jobs:
return;
}
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
for (const name of [...h.sizeLabels, ...h.tierLabels]) {
await h.ensureLabel(name);
diff --git a/.github/workflows/tag-external-issues.yml b/.github/workflows/tag-external-issues.yml
index 7c3e615d3a..fe32849d53 100644
--- a/.github/workflows/tag-external-issues.yml
+++ b/.github/workflows/tag-external-issues.yml
@@ -68,7 +68,7 @@ jobs:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const author = context.payload.sender.login;
const { isExternal } = await h.checkMembership(
@@ -86,7 +86,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const issue = context.payload.issue;
// new-contributor is only meaningful on PRs, not issues
@@ -101,7 +101,7 @@ jobs:
const { owner, repo } = context.repo;
const issue_number = context.payload.issue.number;
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const label = '${{ steps.check-membership.outputs.is-external }}' === 'true'
? 'external' : 'internal';
@@ -141,7 +141,7 @@ jobs:
return;
}
- const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo);
+ const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core);
const tierLabels = ['trusted-contributor'];
for (const name of tierLabels) {