【问题标题】:Get contributions.json on Gitlab获取 Gitlab 上的贡献.json
【发布时间】:2020-02-29 08:04:57
【问题描述】:

如果“显示私人贡献”在设置中关闭,我如何在 Gitlab CI 管道中获得自己的 contributions.json 私人贡献?

如果登录用户是 GITLAB_USERNAME,https://gitlab.com/users/GITLAB_USERNAME/calendar.json 会显示公共和私人贡献。

https://gitlab.com/users/GITLAB_USERNAME/calendar.json 仅在登录用户不是 GITLAB_USERNAME 并且 GITLAB_USERNAME 的“显示私人贡献”关闭时显示公共贡献。

我可以使用curl --cookie "_gitlab_session=..." https://gitlab.com/users/GITLAB_USERNAME/calendar.json 执行此操作,我通过Web 界面登录获得了cookie。会话 cookie 默认在 1 周后过期。

我想要一种通过 CI 管道自动执行此操作的方法,而无需模拟登录并将我的密码存储为变量(不安全,如果我更改密码,我需要更新所有密码)。

我曾尝试使用 CI_JOB_TOKEN 进行身份验证(就像我使用 API:curl --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects" 一样),但只显示公共贡献。

【问题讨论】:

    标签: gitlab gitlab-ci gitlab-api gitlab-ce


    【解决方案1】:

    您需要使用 events 端点。

    您可以使用个人令牌和events api curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.com/api/v4/users/:id/events 收集您的所有事件

    可以使用以下方式找到用户 ID:https://gitlab.com/api/v4/users?username=YOUR_USERNAME

    使用personal access token 代替工作令牌来访问 gitlab api。

    filter out你的结果根据你的需要使用参数。比从https://gitlab.com/users/GITLAB_USERNAME/calendar.json url 收集的数据要多得多,因此您需要对其进行处理。

    注意:

    https://gitlab.com/users/GITLAB_USERNAME/calendar.json不是 api 网址,而是 gitlab 端点,因此 gitlab 令牌 不会为它工作

    【讨论】:

    • 我试过curl https://gitlab.com/users/GITLAB_USERNAME/calendar.json?private_token=<your_access_token>curl --header "Private-Token: <your_access_token>" https://gitlab.com/users/GITLAB_USERNAME/calendar.json。两者都只返回公共数据。
    • 正如我写的那样,calendar.json 不行。您需要使用https://gitlab.com/api/v4/users/:id/events 获取更多信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2021-12-10
    • 2017-03-03
    • 2011-09-13
    相关资源
    最近更新 更多