Skip to content

[dead-code] chore: remove dead functions — 7 functions removed#23693

Merged
pelikhan merged 1 commit intomainfrom
dead-code/remove-unreachable-functions-20260331-3c2560ccf6189c7c
Mar 31, 2026
Merged

[dead-code] chore: remove dead functions — 7 functions removed#23693
pelikhan merged 1 commit intomainfrom
dead-code/remove-unreachable-functions-20260331-3c2560ccf6189c7c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Dead Code Removal

This PR removes unreachable Go functions identified by the deadcode static analyzer.

Functions Removed

Function File
ResolveRefToSHA pkg/parser/remote_fetch.go
ExtractPermissionsFromContent pkg/parser/content_extractor.go
SemanticVersion.IsPrecise pkg/semverutil/semverutil.go
SemanticVersion.IsNewer pkg/semverutil/semverutil.go
writeArgsToYAMLInline pkg/workflow/args.go
higherIntegrityLevels pkg/workflow/cache_integrity.go
GenerateHeredocDelimiter pkg/workflow/strings.go

Tests Removed

  • TestSemanticVersionIsPrecise (pkg/semverutil/semverutil_test.go) — exclusively tested IsPrecise
  • TestSemanticVersionIsNewer (pkg/semverutil/semverutil_test.go) — exclusively tested IsNewer
  • TestWriteArgsToYAMLInline (pkg/workflow/mcp_config_utils_test.go) — exclusively tested writeArgsToYAMLInline (entire file deleted)
  • TestHigherIntegrityLevels (pkg/workflow/cache_integrity_test.go) — exclusively tested higherIntegrityLevels
  • TestGenerateHeredocDelimiter (pkg/workflow/strings_test.go) — exclusively tested GenerateHeredocDelimiter
  • TestGenerateHeredocDelimiter_Usage (pkg/workflow/strings_test.go) — exclusively tested GenerateHeredocDelimiter
  • TestGenerateHeredocDelimiter_Uniqueness (pkg/workflow/strings_test.go) — exclusively tested GenerateHeredocDelimiter
  • TestExtractPermissionsFromContent (pkg/workflow/permissions_import_test.go) — exclusively tested ExtractPermissionsFromContent

Verification

  • go build ./... — passes
  • go vet ./... — passes
  • go vet -tags=integration ./... — passes
  • make fmt — no changes needed
  • go test ./pkg/parser/... ./pkg/semverutil/... ./pkg/workflow/... — all pass

Dead Function Count

  • Before this batch: ~24 functions
  • Removed in this PR: 7 functions
  • Remaining: ~17 functions

Skipped (safe WASM functions)

WithSkipValidation, WithNoEmit, WithWorkflowIdentifier, CompileToYAML, ParseWorkflowString — all referenced in cmd/gh-aw-wasm/main.go (build-constrained js && wasm).


Automated by Dead Code Removal workflow — https://github.com/github/gh-aw/actions/runs/23796136562

Generated by Dead Code Removal Agent ·

  • expires on Apr 3, 2026, 12:17 PM UTC

Removes unreachable Go functions identified by the deadcode static analyzer.

Functions removed:
- ResolveRefToSHA (pkg/parser/remote_fetch.go)
- ExtractPermissionsFromContent (pkg/parser/content_extractor.go)
- SemanticVersion.IsPrecise (pkg/semverutil/semverutil.go)
- SemanticVersion.IsNewer (pkg/semverutil/semverutil.go)
- writeArgsToYAMLInline (pkg/workflow/args.go)
- higherIntegrityLevels (pkg/workflow/cache_integrity.go)
- GenerateHeredocDelimiter (pkg/workflow/strings.go)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 31, 2026 12:21
Copilot AI review requested due to automatic review settings March 31, 2026 12:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes Go dead code (and the now-obsolete unit tests) based on deadcode analyzer output.

Changes:

  • Deleted 7 unreachable helper functions across pkg/parser, pkg/semverutil, and pkg/workflow.
  • Removed unit tests that exclusively exercised the deleted functions (including deleting an entire test file).
  • Cleaned up related imports in the affected test files.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/workflow/strings.go Removes GenerateHeredocDelimiter; keeps seeded delimiter helper.
pkg/workflow/strings_test.go Removes tests that only covered GenerateHeredocDelimiter.
pkg/workflow/permissions_import_test.go Removes test/import that only covered ExtractPermissionsFromContent.
pkg/workflow/mcp_config_utils_test.go Deletes test file that only covered writeArgsToYAMLInline.
pkg/workflow/cache_integrity.go Removes unused higherIntegrityLevels helper.
pkg/workflow/cache_integrity_test.go Removes test that only covered higherIntegrityLevels.
pkg/workflow/args.go Removes unused writeArgsToYAMLInline helper.
pkg/semverutil/semverutil.go Removes unused exported methods IsPrecise / IsNewer.
pkg/semverutil/semverutil_test.go Removes tests that only covered IsPrecise / IsNewer.
pkg/parser/remote_fetch.go Removes exported wrapper ResolveRefToSHA.
pkg/parser/content_extractor.go Removes exported wrapper ExtractPermissionsFromContent.
Comments suppressed due to low confidence (2)

pkg/workflow/strings.go:268

  • In the GenerateHeredocDelimiterFromSeed docstring, the later comment text still references GenerateHeredocDelimiter, which is removed in this PR. Please update the docstring to avoid referencing a non-existent function and describe the empty-seed fallback directly.
// GenerateHeredocDelimiterFromSeed creates a stable heredoc delimiter derived from a seed
// (typically the workflow frontmatter hash hex string) so that repeated compilations of the
// same workflow produce identical lock files.

pkg/parser/remote_fetch.go:707

  • This PR removes the exported parser.ResolveRefToSHA symbol, leaving only ResolveRefToSHAForHost. Removing an exported function is a breaking API change for external importers; if you want to preserve backward compatibility, consider keeping ResolveRefToSHA as a deprecated wrapper that calls ResolveRefToSHAForHost(owner, repo, ref, "").
	return downloadFileFromGitHubWithDepth(owner, repo, path, ref, 0, host)
}

// ResolveRefToSHAForHost resolves a git ref to its full commit SHA on a specific GitHub host.
// Use this when the target repository is on a different host than the one configured via GH_HOST.
// host is the hostname without scheme (e.g., "github.com", "myorg.ghe.com").
// An empty host uses the default configured host (GH_HOST or github.com).
func ResolveRefToSHAForHost(owner, repo, ref, host string) (string, error) {
	return resolveRefToSHA(owner, repo, ref, host)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -263,45 +263,6 @@ func ShortenCommand(command string) string {
return shortened
}

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the exported GenerateHeredocDelimiter API from pkg/workflow. Even if it’s currently unused within this repo, it is a breaking change for any external consumers of the module; consider keeping a deprecated wrapper that delegates to GenerateHeredocDelimiterFromSeed(name, "") (or equivalent) if backward compatibility matters.

This issue also appears on line 266 of the same file.

Suggested change
// GenerateHeredocDelimiter is retained for backward compatibility.
//
// Deprecated: Use GenerateHeredocDelimiterFromSeed with an explicit seed instead.
func GenerateHeredocDelimiter(name string) (string, error) {
return GenerateHeredocDelimiterFromSeed(name, "")
}

Copilot uses AI. Check for mistakes.
Comment on lines 54 to 58
return strings.TrimSpace(string(extractedJSON)), nil
}

// ExtractPermissionsFromContent extracts permissions section from frontmatter as JSON string
func ExtractPermissionsFromContent(content string) (string, error) {
return extractFrontmatterField(content, "permissions", "{}")
}

// extractFrontmatterField extracts a specific field from frontmatter as JSON string
func extractFrontmatterField(content, fieldName, emptyValue string) (string, error) {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the exported parser.ExtractPermissionsFromContent function is a breaking API change for any external consumers of this module. If the parser package is treated as public, consider leaving a deprecated wrapper (or documenting an alternative) rather than deleting the symbol outright.

Copilot uses AI. Check for mistakes.
Comment on lines 98 to 103
return ver
}

// IsPrecise returns true if the version has explicit minor and patch components.
// For example, "v6.0.0" is precise, but "v6" is not.
func (v *SemanticVersion) IsPrecise() bool {
versionPart := strings.TrimPrefix(v.Raw, "v")
dotCount := strings.Count(versionPart, ".")
return dotCount >= 2 // Require at least major.minor.patch
}

// IsNewer returns true if v is strictly newer than other.
// Uses golang.org/x/mod/semver.Compare for proper semantic version comparison.
func (v *SemanticVersion) IsNewer(other *SemanticVersion) bool {
v1 := EnsureVPrefix(v.Raw)
v2 := EnsureVPrefix(other.Raw)
isNewer := semver.Compare(v1, v2) > 0
log.Printf("Version comparison: %s vs %s, isNewer=%v", v.Raw, other.Raw, isNewer)
return isNewer
}

// Compare compares two semantic versions and returns 1 if v1 > v2, -1 if v1 < v2,
// or 0 if they are equal. A bare version without a leading "v" is accepted.
func Compare(v1, v2 string) int {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR removes exported methods (*SemanticVersion).IsPrecise and (*SemanticVersion).IsNewer. Even if they’re unused internally, deleting exported APIs is a breaking change for external consumers; consider keeping deprecated methods that delegate to existing helpers (e.g., Compare/EnsureVPrefix) if API stability is a goal.

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 251a924 into main Mar 31, 2026
67 checks passed
@pelikhan pelikhan deleted the dead-code/remove-unreachable-functions-20260331-3c2560ccf6189c7c branch March 31, 2026 12:28
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