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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With