Skip to content

fix(backend): match GitLab project topics case-insensitively - #1443

Closed
outrunn wants to merge 2 commits into
sourcebot-dev:mainfrom
outrunn:fix/gitlab-topic-case
Closed

fix(backend): match GitLab project topics case-insensitively#1443
outrunn wants to merge 2 commits into
sourcebot-dev:mainfrom
outrunn:fix/gitlab-topic-case

Conversation

@outrunn

@outrunn outrunn commented Jul 14, 2026

Copy link
Copy Markdown

Fixes #1388

Problem

GitLab connection topic filters are case-insensitive on the config side but case-sensitive on the project side. In shouldExcludeProject (packages/backend/src/gitlab.ts), the configured topics / exclude.topics are lowercased before matching, but the project's own topics (from the GitLab API) are compared in their original case. So a project whose topic is Backend does not match a config topic or glob like backend, and repositories get unexpectedly included or excluded whenever a GitLab project uses mixed-case topics.

Fix

Lowercase the project topics as well, in both the include.topics and exclude.topics branches, so matching is case-insensitive and symmetric between the configured topics and the project topics.

Before / after

Config: include.topics: ["backend"], project topic: ["Backend"]

  • Before: no match -> the repository is excluded from sync.
  • After: case-insensitive match -> the repository is included, as expected.

Testing

  • Updated the existing test that documented the old case-sensitive behavior so it now asserts the mixed-case project topic Backend matches config backend, and added a symmetric exclude.topics test.
  • yarn workspace @sourcebot/backend test --run src/gitlab.test.ts -> 13/13 passing.
  • yarn workspace @sourcebot/backend exec tsc --noEmit -> clean.

Changelog

Added an entry under ## [Unreleased] -> ### Fixed.

Note on #1393

I saw #1393 takes the same approach but has unresolved conflicts and looks stale. Opening this as a clean, rebased alternative with tests in case it helps land the fix faster. Happy to close this one if the original author picks theirs back up.


Note

Low Risk
Small, localized change to GitLab sync filtering logic with matching unit tests; no auth or data-path changes.

Overview
Fixes GitLab connection topic filtering so include.topics and exclude.topics treat project topics from the API the same way as configured patterns: both sides are lowercased before micromatch runs in shouldExcludeProject.

Mixed-case project topics (e.g. Backend) now match config like backend, so sync include/exclude rules behave as users expect instead of silently skipping or dropping repos.

Tests were updated for the include case and an exclude.topics case-insensitive test was added; the unreleased changelog notes the fix (#1388).

Reviewed by Cursor Bugbot for commit 9dc0eb2. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • GitLab topic filters now match project topics regardless of capitalization.
    • Included and excluded topic rules correctly handle mixed-case topics.
  • Documentation

    • Updated the changelog to document the improved GitLab topic filtering behavior.

GitLab connection topic filters lowercased the configured topics but
compared them against project topics in their original case, so a
project topic like 'Backend' would not match a config topic such as
'backend'. Lowercase the project topics as well so include/exclude
topic matching is case-insensitive and symmetric.

Fixes sourcebot-dev#1388
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

GitLab project topics are lowercased before matching against configured include and exclude topic filters. Tests cover mixed-case topics for both paths, and the changelog documents the fix.

Changes

GitLab topic filtering

Layer / File(s) Summary
Normalize project topics for filtering
packages/backend/src/gitlab.ts, packages/backend/src/gitlab.test.ts, CHANGELOG.md
Lowercases GitLab project topics before include and exclude matching, adds mixed-case coverage for both filters, and documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation normalizes project topics for both include and exclude matching, with tests covering mixed-case topics as required by issue #1388.
Out of Scope Changes check ✅ Passed The changes are limited to GitLab topic matching, related tests, and the corresponding changelog entry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: case-insensitive matching for GitLab project topics in the backend.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/backend/src/gitlab.ts (1)

251-254: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify case-insensitive matching with micromatch options.

Both include.topics and exclude.topics paths manually create new arrays to map topics to lowercase. micromatch supports case-insensitive matching natively via the { nocase: true } option, which would allow you to skip creating intermediate lowercased arrays.

Consider refactoring both sections to use the native option:

  • packages/backend/src/gitlab.ts#L251-L254: Remove .map(topic => topic.toLowerCase()) from both configTopics and projectTopics, and pass { nocase: true } to micromatch.isMatch(topic, include.topics, { nocase: true }).
  • packages/backend/src/gitlab.ts#L262-L265: Remove .map(topic => topic.toLowerCase()) from both configTopics and projectTopics, and pass { nocase: true } to micromatch.isMatch(topic, exclude.topics, { nocase: true }).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/gitlab.ts` around lines 251 - 254, The topic matching
logic in both include and exclude paths unnecessarily lowercases intermediate
arrays. In packages/backend/src/gitlab.ts lines 251-254, remove the lowercase
mappings and use the original topic arrays with micromatch.isMatch configured
with nocase: true; apply the same change to lines 262-265 for exclude.topics,
preserving the existing matching behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/backend/src/gitlab.ts`:
- Around line 251-254: The topic matching logic in both include and exclude
paths unnecessarily lowercases intermediate arrays. In
packages/backend/src/gitlab.ts lines 251-254, remove the lowercase mappings and
use the original topic arrays with micromatch.isMatch configured with nocase:
true; apply the same change to lines 262-265 for exclude.topics, preserving the
existing matching behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9067891-a1c0-498d-9d1f-315d76e39e56

📥 Commits

Reviewing files that changed from the base of the PR and between a50ca10 and 20a803d.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/backend/src/gitlab.test.ts
  • packages/backend/src/gitlab.ts

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.

GitLab topic filters are case-sensitive on project topics

2 participants