Uploaded image for project: 'OpenShift Pipelines'
  1. OpenShift Pipelines
  2. SRVKP-10915

[KONFLUX-12312] GitOps comment parser treats branch names containing "tag" as tag, breaking /retest … branch:<branch> on commit comments

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • None
    • None
    • 1

      Description of problem:

      When a user posts a commit comment with /retest <pipeline> branch:<branch-name> and the branch name contains the substring tag (e.g. akurlov/ROX-32966-test-tagged-rebuild), Pipelines-as-Code mis-parses the comment as a tag instead of a branch. The branch name is never set, so the controller falls back to the repository default branch (e.g. master) and then fails with:

      failed to parse event: provided SHA <commit-sha> is not the HEAD commit of the branch master
      provider: github
      

      So retest does not run for that commit even though the user correctly specified branch:....

      Root cause: In pkg/provider/provider.go, the logic that chooses between parsing tag: vs branch: uses strings.Contains(splitText[1], "tag"). Any branch name that contains the letters "tag" (e.g. test-tagged-rebuild) triggers tag parsing. The code then looks for a literal tag: in the comment, finds none, leaves tagName empty and never sets branchName, so the event is later treated as "default branch" and fails the HEAD check.

      Prerequisites (if any, like setup, operators/versions):

      • Pipelines-as-Code (GitHub provider)
      • User comments on a commit (not a pull request)
      • Branch name in the comment contains the substring "tag" (e.g. test-tagged-rebuild, feature/tag-v2)

      Steps to Reproduce

      1. Open a repo with PaC and a pipeline (e.g. central-db-on-push) that can be triggered by comment.
      2. Create or use a branch whose name contains "tag", e.g. akurlov/ROX-32966-test-tagged-rebuild.
      3. Push a commit to that branch (so the commit is HEAD of that branch but not of master).
      4. On GitHub, open the commit page (not the PR) and add a comment: {
        Unknown macro: {/retest central-db-on-push branch}

        }

      5. Observe PaC logs and/or GitHub check result.

      Actual results:

      • PaC fails to run the pipeline for that comment.
      • Logs show: failed to parse event: provided SHA <sha> is not the HEAD commit of the branch master (provider: github).
      • No new PipelineRun is created for that comment.

      Expected results:

      • PaC parses branch:akurlov/ROX-32966-test-tagged-rebuild as a branch ref.
      • The controller verifies that the comment's commit is the HEAD of that branch and then runs the requested pipeline for that commit.
      • Pipeline runs successfully when the commit is the HEAD of the specified branch.

      Reproducibility (Always/Intermittent/Only Once):

      Always, for any commit comment where the branch name in branch:... contains the substring "tag".

      Acceptance criteria:

      • Comment /retest <pipeline> branch:<branch-name> is parsed as branch when the comment contains the literal prefix branch:, even if <branch-name> contains the substring "tag".
      • Comment /retest <pipeline> tag:<tag-name> continues to be parsed as tag when the comment contains the literal prefix tag:.
      • Existing tests for branch/tag parsing still pass; at least one test added for a branch name containing "tag" (e.g. branch:akurlov/ROX-32966-test-tagged-rebuild).

      Definition of Done:

      • Fix: use strings.Contains(..., "tag:") instead of strings.Contains(..., "tag") when deciding between tag and branch parsing.
      • New or updated unit test covers branch names containing "tag".
      • No regression for tag:... or branch:... parsing.

      Workaround

      Until the fix is deployed, use one of:

      • Post the retest comment on the pull request instead of the commit (PR context uses the PR branch, so the bug does not apply).
      • Use /retest <pipeline> tag:<tagname> if the commit is pointed to by a tag.
      • Use a branch name that does not contain the substring "tag".

      Additional info

      • Related support ticket: KFLUXSPRT-7140 KONFLUX-12312
      • Fix location: pkg/provider/provider.go, function getPipelineRunAndBranchOrTagNameFromComment (decision between tag vs branch).
      • Correct behavior: only treat as tag when the comment contains the literal tag: prefix; otherwise treat as branch: when that prefix is present.

              rh-ee-shumathu Shubham Mathur
              rh-ee-shumathu Shubham Mathur
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:

                  Estimated:
                  Original Estimate - 1 minute
                  1m
                  Remaining:
                  Remaining Estimate - 1 minute
                  1m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified