Skip to content

fix(analysis): handle multi-document YAML (spec: block) in CI config parsing#216

Open
12122J wants to merge 1 commit into
getplumber:mainfrom
12122J:fix/multi-doc-yaml-spec
Open

fix(analysis): handle multi-document YAML (spec: block) in CI config parsing#216
12122J wants to merge 1 commit into
getplumber:mainfrom
12122J:fix/multi-doc-yaml-spec

Conversation

@12122J
Copy link
Copy Markdown

@12122J 12122J commented May 28, 2026

Summary

Fixes hardcoded job detection being silently skipped when a .gitlab-ci.yml contains a spec: block.

Root cause (#211)

GitLab CI component template files use a two-document YAML layout:

spec:
  inputs:
    gitlab_token:
      default: $GITLAB_TOKEN
---
plumber:
  stage: .pre
  script:
    - /plumber analyze

When a user copies this template directly into their .gitlab-ci.yml, the raw file is multi-document YAML. yaml.Unmarshal in GetFullGitlabCI only reads the first document, so gitlabConf.GitlabJobs was always empty for such files.

Downstream effect: the hardcoded-job detector iterates data.Conf.GitlabJobs to populate JobHardcodedMap. With an empty map, no jobs were ever marked "hardcoded", even jobs clearly defined in the user's file. The plumber job in the example above would silently get originKind = "" instead of "hardcoded", suppressing ISSUE-401.

Fix

Replace yaml.Unmarshal(confByte, &gitlabConf) with a new helper unmarshalMultiDocGitlabCI that uses yaml.NewDecoder to iterate all YAML documents and merge their GitlabJobs maps. 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: a spec: + --- + job file correctly yields both Spec populated and plumber in GitlabJobs
  • make test passes clean

AI 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

…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>
@thomasboni
Copy link
Copy Markdown
Contributor

Hello @12122J , thanks for this PR ! We will review soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] hardcoded jobs not detected when using spec

2 participants