Skip to content

Decouple frontmatter hash computation from file system I/O#13104

Merged
pelikhan merged 6 commits intomainfrom
copilot/refactor-frontmatter-hash-algorithm
Feb 1, 2026
Merged

Decouple frontmatter hash computation from file system I/O#13104
pelikhan merged 6 commits intomainfrom
copilot/refactor-frontmatter-hash-algorithm

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Frontmatter hash computation was hardcoded to read from disk using fs.readFileSync (JavaScript) and os.ReadFile (Go). This prevented computing hashes via GitHub API or in-memory file systems.

Changes

JavaScript (actions/setup/js/frontmatter_hash_pure.cjs)

  • Accept optional fileReader function in computeFrontmatterHash(options)
  • Add createGitHubFileReader(github, owner, repo, ref) helper
  • Default to fs.readFileSync when no custom reader provided

Go (pkg/parser/frontmatter_hash.go)

  • Define FileReader type: func(filePath string) ([]byte, error)
  • Add ComputeFrontmatterHashFromFileWithReader(filePath, cache, fileReader)
  • Default to os.ReadFile via DefaultFileReader variable

Both implementations

  • Thread custom reader through processImportsTextBased() for recursive import handling
  • Fully backward compatible - existing code unchanged

Usage

// GitHub API
const reader = createGitHubFileReader(github, 'owner', 'repo', 'main');
const hash = await computeFrontmatterHash('workflow.md', { fileReader: reader });

// In-memory
const mockFS = { 'workflow.md': '---\nengine: copilot\n---\n' };
const hash = await computeFrontmatterHash('workflow.md', { 
  fileReader: async (path) => mockFS[path] 
});
// Custom reader (GitHub API, cache, etc.)
customReader := func(path string) ([]byte, error) {
    return githubClient.GetFileContent(path)
}
hash, err := parser.ComputeFrontmatterHashFromFileWithReader("workflow.md", cache, customReader)
Original prompt

Refactor frontmatter hash algorithm to use either fs module or github.getFileContent api so that it can compute the hash without files on disk.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

Smoke Test Results

  • ✅ Draft issue creation
  • ✅ Field creation with new fields
  • ✅ Field update
  • ✅ Existing issue addition
  • ✅ Existing PR addition
  • ✅ Project status update
  • ✅ Scoping validation (4 tests)

Status: PASS

AI generated by Smoke Project

Copilot AI and others added 5 commits February 1, 2026 13:22
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor frontmatter hash algorithm to use fs module or api Decouple frontmatter hash computation from file system I/O Feb 1, 2026
Copilot AI requested a review from pelikhan February 1, 2026 13:37
@pelikhan pelikhan marked this pull request as ready for review February 1, 2026 15:37
@pelikhan pelikhan merged commit 1656e15 into main Feb 1, 2026
135 checks passed
@pelikhan pelikhan deleted the copilot/refactor-frontmatter-hash-algorithm branch February 1, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants