4

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.

gtpzkldqc
  • 73
  • 7

1 Answers1

0

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.

makozaki
  • 3,772
  • 4
  • 23
  • 47
  • 2
    I've tried `curl https://gitlab.com/users/GITLAB_USERNAME/calendar.json?private_token=` and `curl --header "Private-Token: " https://gitlab.com/users/GITLAB_USERNAME/calendar.json`. Both of them only return the public data. – gtpzkldqc Nov 05 '19 at 03:58
  • As I wrote calendar.json won't do. you need to use `https://gitlab.com/api/v4/users/:id/events` to get more info. – makozaki Sep 13 '21 at 06:51