Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contributions.json on Gitlab

How can I get contributions.json of myself in a Gitlab CI pipeline with private contributions if "show private contributions" is off in the settings?

https://gitlab.com/users/GITLAB_USERNAME/calendar.json shows both public and private contributions if the logged in user is GITLAB_USERNAME.

https://gitlab.com/users/GITLAB_USERNAME/calendar.json shows only public contributions if the logged in user is not GITLAB_USERNAME and "show private contributions" is off for GITLAB_USERNAME.

I can do this with curl --cookie "_gitlab_session=..." https://gitlab.com/users/GITLAB_USERNAME/calendar.json where I have obtained the cookie by logging in through the web interface. The session cookie expires after 1 week by default.

I want an automated way to do this through a CI pipeline without simulating a log in and storing my password as a variable (insecure, and if I change my password, I need to update all of them).

I have tried using CI_JOB_TOKEN for authentication (like I do with API: curl --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects"), but only the public contributions are showing up.

like image 363
gtpzkldqc Avatar asked Sep 17 '25 20:09

gtpzkldqc


1 Answers

You can't do it using calendar.json endpoint. You need to use events api.

You can collect all your events using personal token and events api curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.com/api/v4/users/:id/events

User id can be found using: https://gitlab.com/api/v4/users?username=YOUR_USERNAME

Instead of job token use personal access token to get access to gitlab api.

To filter out your results use parameters according to your needs. There is a lot more data than when gathering from https://gitlab.com/users/GITLAB_USERNAME/calendar.json url so you would need to process it.

NOTE:

https://gitlab.com/users/GITLAB_USERNAME/calendar.json is not api url but gitlab endpoint so gitlab token won't work for it.

like image 167
makozaki Avatar answered Sep 22 '25 09:09

makozaki