From 90407aa9f2ffe7480452c28de28ee6324ee0740e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 02:35:36 +0000 Subject: [PATCH] Fix: Fetch file content from PR head using GitHub API The workflow was checking out the base branch but trying to read files from the filesystem, which meant it couldn't see changes in the PR. Now using github.rest.repos.getContent with the PR head SHA to fetch the actual file content from the PR branch. Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com> --- .github/workflows/auto-label-pr.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-label-pr.yml b/.github/workflows/auto-label-pr.yml index 87c031bf2b..a247b40234 100644 --- a/.github/workflows/auto-label-pr.yml +++ b/.github/workflows/auto-label-pr.yml @@ -408,11 +408,23 @@ jobs: } } + // Get PR head SHA to fetch files from the PR branch + const prHeadSha = context.payload.pull_request.head.sha; + // Check each component's __init__.py for DEPRECATED_COMPONENT constant for (const component of components) { const initFile = `esphome/components/${component}/__init__.py`; try { - const content = fs.readFileSync(initFile, 'utf8'); + // Fetch file content from PR head using GitHub API + const { data: fileData } = await github.rest.repos.getContent({ + owner, + repo, + path: initFile, + ref: prHeadSha + }); + + // Decode base64 content + const content = Buffer.from(fileData.content, 'base64').toString('utf8'); // Look for DEPRECATED_COMPONENT = "message" or DEPRECATED_COMPONENT = 'message' // Support single quotes, double quotes, and triple quotes (for multiline) @@ -431,8 +443,8 @@ jobs: console.log(`Found deprecated component: ${component}`); } } catch (error) { - // Only log if it's not a simple "file not found" error - if (error.code !== 'ENOENT') { + // Only log if it's not a simple "file not found" error (404) + if (error.status !== 404) { console.log(`Error reading ${initFile}:`, error.message); } }