Optimize group label validation by searching for requested labels instead of paging through the full group tree

Open
#746 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Start with validateSubscriptionLabels in server/command.go, then read GetGroupLabels in server/gitlab/api.go, where the paging loop over resp.NextPage lives. Check whether ListGroupLabelsOptions in the GitLab client accepts a Search field. Done when each requested label is checked with a search query, an exact match on Name is still required, and unknown labels are still rejected.

Written by the indexing model from the issue text.

Description

Summary

When adding a group subscription with label filters (e.g., /gitlab subscriptions add group issues,label:"bug"), validateSubscriptionLabels currently calls GetGroupLabels, which pages through every label across the entire group hierarchy (including descendant groups and projects). In large GitLab organizations with hundreds or thousands of labels, this generates unnecessary API requests and causes high latency during command execution.

Thanks to @nang2049 for the suggestion in https://github.com/mattermost/mattermost-plugin-gitlab/pull/726#discussion_r4548460348.

Current Behavior

In server/gitlab/api.go:

opts := &internGitlab.ListGroupLabelsOptions{
    ListOptions: internGitlab.ListOptions{
        Page:    1,
        PerPage: 100,
    },
    OnlyGroupLabels:          &onlyGroupLabels,
    IncludeDescendantGrouops: &includeDescendants,
}

GetGroupLabels paginates through all labels in the group hierarchy (resp.NextPage != 0). If a group has many projects and sub-groups, validating a single label can issue numerous paginated HTTP requests to GitLab.

Proposed Solution

GitLab's Group Labels API (ListGroupLabelsOptions) supports a Search parameter. Rather than fetching and paging through the entire group label catalog:

  1. Query GitLab's group labels endpoint with Search: &label for each label requested in the subscription features string.
  2. Validate that at least one returned result matches the exact label name (exact match against l.Name).
  3. This restricts the API interaction to 1–2 requests per subscription command regardless of the total number of labels in the group tree.
Code References & Context
Dominant language
JavaScript
Stars
158
Forks
97
Avg merge
2d 17h
Merged PRs (30d)
21

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mattermost/mattermost-plugin-gitlab

All issues in mattermost/mattermost-plugin-gitlab

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.