Skip to content

🐛 Use authenticated GitLab GraphQL API to fetch public monthly MRs - #106

Merged
jeanphi-baconnais merged 1 commit into
zenika-open-source:mainfrom
jeanphi-baconnais:fix/gitlab-graphql-monthly-mrs
Nov 3, 2026
Merged

jeanphi-baconnais merged 1 commit into
zenika-open-source:mainfrom
jeanphi-baconnais:fix/gitlab-graphql-monthly-mrs

Conversation

@jeanphi-baconnais

Copy link
Copy Markdown
Member

📝 Description

Calling the GitLab REST API (GET /api/v4/merge_requests) without an Authorization: Bearer header falls under GitLab's throttle_unauthenticated_api rate limit (500 requests / minute per IP), triggering 429 Too Many Requests during organization-wide contribution synchronization. However, calling the REST endpoint with the Bearer token returns merge requests from private/internal projects without exposing project visibility in the REST payload.

This PR switches the monthly GitLab Merge Requests lookup in GitLabServices to GitLab's GraphQL API (/api/graphql) authenticated with the Bearer token (2,000 requests / minute quota), querying project { name fullPath webUrl visibility } and strictly filtering on visibility == "public".

🚀 Main Changes

  • GraphQL Query (GitLabGraphQLQueries.java):
    • Added qGetMergedMergeRequestsForAPeriod querying user(username: $username) { authoredMergeRequests(state: merged, updatedAfter: $updatedAfter, updatedBefore: $updatedBefore, first: 100) } along with project { name fullPath webUrl visibility }.
  • GraphQL Beans (src/main/java/fr/zenika/opensource/stats/beans/gitlab/graphql/):
    • Added GitLabMergeRequestProject (with isPublic()) and GitLabMergeRequestNode.
    • Updated GitLabMergeRequestsCount to expose List<GitLabMergeRequestNode> nodes.
  • Service (GitLabServices.java):
    • Configured an authenticated DynamicGraphQLClient using quarkus.smallrye-graphql-client.gitlab-api.url and gitlab.token.
    • Updated getContributionsByUserId and getContributionsForTheCurrentYear to query GitLab GraphQL per month by username (removing the extra /users?username=... REST call) and filter merge requests to keep only public projects (GitLabMergeRequestProject::isPublic).
  • Unit Tests (GitLabServicesTest.java):
    • Updated unit tests to verify GraphQL invocation and public/private MR filtering, and added a GraphQL JSON deserialization test.

🧪 Verification & Testing

  • Executed ./mvnw -Dtest=GitLabServicesTest test (3/3 tests passing).

@jeanphi-baconnais
jeanphi-baconnais merged commit fd4865c into zenika-open-source:main Nov 3, 2026
2 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 3, 2026
# [v1.12.2](v1.12.1...v1.12.2) (2026-11-03)

## 🐛 Bug Fixes
- [`fd4865c`](fd4865c)  Use authenticated GitLab GraphQL API to fetch public monthly MRs (#106) (Issues: [`#106`](#106))
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.12.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant