Skip to content

feat(gitlab): infer issue context from native branch prefixes - #4911

Merged
IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
PeterDaveHello:feature/gitlab-branch-issue-context
Nov 16, 2026
Merged

IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
PeterDaveHello:feature/gitlab-branch-issue-context

Conversation

@PeterDaveHello

@PeterDaveHello PeterDaveHello commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

User description

Why

GitLab automatically links issues to merge requests when the source branch starts with an issue IID followed by a hyphen, such as 123-fix-export.

However, PR-Agent currently extracts GitLab issue references only from MR descriptions and titles. Users following GitLab's native branch naming convention must repeat the issue reference manually to make its context available to PR-Agent.

This enhancement allows PR-Agent to recognize those existing branch references without requiring additional user input.

GitLab documentation: https://docs.gitlab.com/user/project/repository/branches/

Changes

  • Infer GitLab issue references from source branches starting with <IID>-, where the IID contains 1–6 digits and is greater than zero.
  • Apply inference only to same-project MRs. Forks and nested branch names such as feature/123-fix are excluded.
  • Preserve the existing reference precedence (description → title → branch), deduplication, and ticket lookup limits.
  • Deduplicate numeric GitLab project IDs against canonical project paths when the latter can be derived from the MR URL.
  • Exclude confidential issues inferred only from branch names. Check the project's Issues and MR feature visibility before fetching an implicitly referenced issue; unknown or insufficient visibility is treated as ineligible.
  • Reuse the existing extract_issue_from_branch setting, including consistent interpretation of string-form boolean values such as "false" across GitHub and GitLab.
  • Update the ticket-context documentation and configuration reference. The custom branch_issue_regex setting remains GitHub-only.

Examples

MR context Source branch Result
No explicit issue reference 123-fix-export Include issue #123 when eligible
Description references #123 123-fix-export Fetch issue #123 only once
Description references #10, title references #11 123-fix-export Prioritize #10, #11, then #123
No explicit issue reference feature/123-fix Do not infer an issue
Fork MR 123-fix-export Do not infer an issue
Confidential or insufficiently visible issue 123-fix-export Exclude the implicit issue

Compatibility and cost

  • No new configuration options or dependencies.
  • Existing explicit issue references retain their behavior and precedence.
  • Branch inference can be disabled using the existing extract_issue_from_branch setting.
  • The shared setting now handles string-form boolean values consistently across GitHub and GitLab. Other provider workflows remain unchanged.
  • A new branch-only GitLab issue candidate requires one additional project-metadata API request to verify feature visibility, followed by the existing issue lookup.
  • No additional LLM requests are introduced.

Tests

Regression coverage uses the existing ticket extraction flow and mocked Git provider API responses, including:

  • Valid and invalid branch naming patterns.
  • Same-project and fork MR eligibility.
  • Description, title, and branch reference precedence.
  • Deduplication, numeric project IDs, and lookup limits.
  • Disabled inference with boolean and string-form settings.
  • Missing metadata, restricted project visibility, and confidential issues.
  • Existing GitHub branch inference behavior.

The changes are limited to the existing ticket extraction logic, relevant tests, and documentation.


PR Type

Enhancement, Tests, Documentation


Description

  • Infer GitLab issues from same-project branch prefixes.

  • Enforce visibility and confidentiality for implicit references.

  • Preserve reference precedence, deduplication, and lookup limits.

  • Document settings and add focused regression coverage.


Diagram Walkthrough

flowchart LR
  explicit["MR description and title references"]
  branch["Same-project numeric branch prefix"]
  merge["Ordered, deduplicated references within lookup limit"]
  checks["Branch-only visibility and confidentiality checks"]
  context["Issue context"]
  explicit --> merge
  branch -- "Inference enabled" --> merge
  merge -- "Explicit references" --> context
  merge -- "Branch-only references" --> checks
  checks -- "Allowed" --> context
Loading

File Walkthrough

Relevant files
Enhancement
ticket_pr_compliance_check.py
Infer GitLab branch issues with visibility safeguards       

pr_agent/commands/ticket_pr_compliance_check.py

  • Infer issues from same-project GitLab branches matching a positive,
    one-to-six-digit IID followed by a hyphen.
  • Append branch references after description and title references,
    respecting the existing setting and lookup limit.
  • Deduplicate numeric project IDs and canonical project-path aliases
    while preserving explicit-reference behavior.
  • Check project feature visibility before branch-only issue retrieval
    and exclude confidential implicit issues.
+76/-9   
Tests
test_ticket_extraction_async.py
Cover GitLab branch inference and security boundaries       

tests/unittest/test_ticket_extraction_async.py

  • Cover branch matching, same-project eligibility, missing metadata, and
    inference opt-out.
  • Verify source precedence, deduplication, lookup limits, and numeric
    project aliases.
  • Test visibility boundaries, confidential issues, and preservation of
    explicit references.
  • Update mock access levels and snapshot the branch-inference setting.
+225/-1 
Documentation
fetching_ticket_context.md
Document GitLab branch linking rules and safeguards           

docs/docs/core-abilities/fetching_ticket_context.md

  • Document GitLab native branch prefixes, same-project restrictions, and
    reference precedence.
  • Explain branch-only visibility checks, confidentiality filtering, and
    the metadata request.
  • Clarify shared opt-out behavior and GitHub-only custom branch regex
    support.
+17/-6   
configuration_reference.md
Update branch issue configuration reference descriptions 

docs/docs/usage-guide/configuration_reference.md

  • Update extract_issue_from_branch documentation to include same-project
    GitLab inference.
  • Keep branch_issue_regex explicitly GitHub-only and link to detailed
    documentation.
+2/-2     
Configuration changes
configuration.toml
Clarify branch inference settings without changing defaults

pr_agent/settings/configuration.toml

  • Describe GitLab support in the existing branch-inference setting
    comment.
  • Shorten the GitHub-only regex comment and link both settings to
    detailed documentation.
  • Preserve existing setting values and defaults.
+2/-7     


⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 11,240 in / 683 out / 11,923 total
  • Time cost: 12.1s
  • AI calls: 1

Copilot AI balanced review requested due to automatic review settings November 13, 2026 15:53
@github-actions github-actions Bot added the feature 💡 label Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The GitLab branch issue-inference change has no active review issues blocking approval.

No open issues 🎉

What changed in this PR

Adds GitLab-native branch issue inference to PR-Agent’s ticket-context extraction, allowing same-project merge requests to use issue context without repeating references in their title or description.

Changes:

  • Recognizes <IID>-... GitLab branches while preserving description → title → branch precedence, deduplication, and existing ticket limits.
  • Excludes fork MRs and nested branch patterns; applies visibility and confidentiality checks to branch-only references.
  • Adds focused tests and updates documentation, clarifying that custom branch_issue_regex remains GitHub-only.
File Description
tests/​unittest/​test_ticket_extraction_async.py Adds coverage for branch eligibility, precedence, deduplication, opt-out, and visibility boundaries.
pr_agent/​settings/​configuration.toml Updates setting comments to describe GitLab support and GitHub-only regex customization.
pr_agent/​commands/​ticket_pr_compliance_check.py Implements GitLab branch inference, project-alias deduplication, and visibility safeguards.
docs/​docs/​usage-guide/​configuration_reference.md Synchronizes configuration descriptions with the updated setting comments.
docs/​docs/​core-abilities/​fetching_ticket_context.md Documents supported branch patterns, source precedence, and privacy restrictions.

Review effort: Balanced

@the-pr-agent-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 23,695 in / 275 out / 23,970 total
  • Time cost: 10.3s
  • AI calls: 1

@the-pr-agent-bot

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible bug
Normalize branch inference configuration

Normalize extract_issue_from_branch before testing it, since configuration values
can arrive as strings as well as booleans. Otherwise, a string such as "false" is
truthy and enables branch-derived issue fetching despite the disabling setting.

pr_agent/commands/ticket_pr_compliance_check.py [1368-1369]

             settings = get_settings()
-            if settings.get("extract_issue_from_branch", settings.get("config.extract_issue_from_branch", True)):
+            branch_enabled = settings.get(
+                "extract_issue_from_branch", settings.get("config.extract_issue_from_branch", True)
+            )
+            if isinstance(branch_enabled, str):
+                branch_enabled = branch_enabled.strip().casefold() in {"true", "1", "yes", "on"}
+            if branch_enabled:
Suggestion importance[1-10]: 4

__

Why: The change correctly prevents string values such as "false" from enabling branch inference through Python truthiness. This is a defensive improvement rather than a demonstrated bug, since the provided configuration and tests use actual booleans.

Low

⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 21,445 in / 802 out / 22,247 total
  • Time cost: 20.2s
  • AI calls: 2

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the thorough work and tests; I ran them and the branch-only handling held: confidential and members-only issues are skipped, forks and nested branch names are not inferred. Holding this one for now. One ask: once #4919 lands with the #4908 rule (skip confidential issues in the own project, explicit references included), rebase onto it and drop the explicit-reference carve-out and its test, since this PR currently keeps own-project confidential issues for explicit references. The hold is about order, not the code.

@PeterDaveHello

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for confirming the branch-only safeguards!

Agreed on the sequencing. Once #4919 is merged, I'll rebase this PR onto the updated main, remove the explicit-reference carve-out and its dedicated test, and rely on the shared confidentiality handling from #4919 for explicit references.

The stricter safeguards for branch-inferred issues will remain in place, with any affected tests and documentation updated as needed before rerunning the relevant checks.

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. #4932, #4959 and #4919 are now in main, so this needs the rebase you described. Two asks: drop the explicit-reference carve-out so confidential own-project issues are skipped via #4919, and give the branch-prefix path the same date exception as #4959 (2026-11-15 is not an issue number; 2024-upgrade-deps, feature/42-2026-11-15 and 2026-11/123-fix keep their documented behaviour). Keeping the label until then.

Use native same-project GitLab branch prefixes to resolve issue context
without requiring duplicate references in MR descriptions. Preserve
explicit issue precedence, visibility checks, and existing ticket limits.

Document GitLab's ASCII issue-ID, no-leading-zero, and date-prefix
rules alongside the shared branch-extraction setting.
@PeterDaveHello
PeterDaveHello force-pushed the feature/gitlab-branch-issue-context branch from e1555ee to 3799eff Compare November 16, 2026 16:38

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the rebase and for dropping the carve-out. I ran it: a confidential own-project issue is skipped for branch-only and explicit references, 2026-11-15, 2026-11/123-fix and feature/42-2026-11-15 are not inferred, and 2024-upgrade-deps still is. The full unit suite passes and CI is green.

@IsmaelMartinez
IsmaelMartinez merged commit 95cddc7 into The-PR-Agent:main Nov 16, 2026
14 checks passed
@PeterDaveHello
PeterDaveHello deleted the feature/gitlab-branch-issue-context branch November 16, 2026 18:50
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.

4 participants