Skip to content

feat(api): add listing user contributed projects #3179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

darkhaniop
Copy link
Contributor

Changes

This PR implements an endpoint for listing a user's contributed projects (related issue #3119):

GET /users/:user_id/contributed_projects

GitLab docs: https://docs.gitlab.com/api/projects/#list-projects-a-user-has-contributed-to

API usage

projects = user.contributed_projects.list()

CLI usage

gitlab -g something user-contributed-project list --user-id username

Modified files:

  • "docs/gl_objects/users.rst" - explain the added method.
  • "gitlab/v4/objects/users.py" - the API implementation.
  • "tests/unit/objects/test_users.py" - add a unit test

Documentation and testing

Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated:

Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.32%. Comparing base (306c4b1) to head (f486bc7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3179      +/-   ##
==========================================
+ Coverage   94.07%   97.32%   +3.24%     
==========================================
  Files          98       98              
  Lines        6038     6046       +8     
==========================================
+ Hits         5680     5884     +204     
+ Misses        358      162     -196     
Flag Coverage Δ
api_func_v4 83.64% <100.00%> (?)
cli_func_v4 84.66% <100.00%> (+0.02%) ⬆️
unit 90.17% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/v4/objects/users.py 99.20% <100.00%> (+4.98%) ⬆️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JohnVillalovos
Copy link
Member

Question: If I am user 'bob' can I list the contributed projects of user 'alice'?

@darkhaniop
Copy link
Contributor Author

darkhaniop commented Apr 23, 2025

@JohnVillalovos

Question: If I am user 'bob' can I list the contributed projects of user 'alice'?

Yes, it looks to be the case.

I just ran a couple of tests with two users on my local GitLab.

Test 1

The first user gituser0 has several private projects, the second user, testuser101 has two public projects:

  • testuser101/testprojectby101
  • testuser101/testprojectby101-2 <-- the first user forks this one

Initially, the second user's API-key sees no "contributed projects" of gituser0 when running:

gitlab -g testuser101 user-contributed-project list --user-id gituser0

After the first user created MR (has not merged yet), the first user's contributed projects list the one with the MR:

$ gitlab -g testuser101 user-contributed-project list --user-id gituser0
id: 90
path_with_namespace: testuser101/testprojectby101-2

After the merge, the contribution stays visible.

Test 2

After gituser0 created two public projects:

  • testpublicgroup0/testprojectby-g0-01 - in a public group
  • gituser0/testprojectby-g0-02.git - in their own namespace
    Checking the endpoint again with the same API-key (visible to testuser101), we get:
$ gitlab -g testuser101 user-contributed-project list --user-id gituser0
id: 92
path_with_namespace: testpublicgroup0/testprojectby-g0-01

id: 90
path_with_namespace: testuser101/testprojectby101-2

Conclusion

Based on these tests, it seems this endpoint shows user "bob" public contributions of user "alice" in namespaces other than "alice/*".


Edit: clarity + add the second test case

@JohnVillalovos JohnVillalovos force-pushed the issue-3119-list-user-contributed-projects branch from eb382e6 to f486bc7 Compare June 7, 2025 14:05
@JohnVillalovos JohnVillalovos requested a review from Copilot June 7, 2025 14:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Implements a new endpoint to list projects a user has contributed to via the GitLab API.

  • Adds UserContributedProject and its manager to the Python client
  • Updates User object to expose contributed_projects
  • Provides fixture and unit test in test_users.py and updates documentation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gitlab/v4/objects/users.py Define UserContributedProject and UserContributedProjectManager, add to User
tests/unit/objects/test_users.py Add HTTP fixture and test_list_contributed_projects
docs/gl_objects/users.rst Document user.contributed_projects.list() usage

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @darkhaniop

@JohnVillalovos JohnVillalovos enabled auto-merge (rebase) June 7, 2025 14:07
@JohnVillalovos JohnVillalovos merged commit 98c1307 into python-gitlab:main Jun 7, 2025
17 checks passed
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.

2 participants