fix(analysis): handle multi-document YAML (spec: block) in CI config parsing#216
Open
12122J wants to merge 1 commit into
Open
fix(analysis): handle multi-document YAML (spec: block) in CI config parsing#21612122J wants to merge 1 commit into
12122J wants to merge 1 commit into
Conversation
…parsing When a .gitlab-ci.yml file starts with a `spec:` block (first YAML document) followed by `---` and job definitions (second document) -- the standard layout of a GitLab CI component template copied directly into a project file -- yaml.Unmarshal would only read the first document. This left GitlabJobs empty for the raw conf, so the hardcoded-job detector never added those jobs to JobHardcodedMap and they were silently given no originKind instead of "hardcoded". Fix: replace yaml.Unmarshal with unmarshalMultiDocGitlabCI which uses yaml.NewDecoder to iterate all YAML documents and merges their GitlabJobs maps. Top-level scalar fields (spec, include, stages, variables, workflow) are taken from the first document that sets them. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Hello @12122J , thanks for this PR ! We will review soon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes hardcoded job detection being silently skipped when a
.gitlab-ci.ymlcontains aspec:block.Root cause (#211)
GitLab CI component template files use a two-document YAML layout:
When a user copies this template directly into their
.gitlab-ci.yml, the raw file is multi-document YAML.yaml.UnmarshalinGetFullGitlabCIonly reads the first document, sogitlabConf.GitlabJobswas always empty for such files.Downstream effect: the hardcoded-job detector iterates
data.Conf.GitlabJobsto populateJobHardcodedMap. With an empty map, no jobs were ever marked"hardcoded", even jobs clearly defined in the user's file. Theplumberjob in the example above would silently getoriginKind = ""instead of"hardcoded", suppressing ISSUE-401.Fix
Replace
yaml.Unmarshal(confByte, &gitlabConf)with a new helperunmarshalMultiDocGitlabCIthat usesyaml.NewDecoderto iterate all YAML documents and merge theirGitlabJobsmaps. Top-level scalar fields (spec,include,stages,variables,workflow) are taken from the first document that sets them.Test plan
TestUnmarshalMultiDocGitlabCI_SpecSeparated— new regression test: aspec:+---+ job file correctly yields bothSpecpopulated andplumberinGitlabJobsmake testpasses cleanAI disclosure
This PR was written with Claude Code (claude-sonnet-4-6). All code was reviewed by the submitter; tests were run and confirmed passing before submission.
Closes #211