gitlab 获取指定分支下指定路径文件夹的解决方案

第一步:

获取accessToken 及你的 项目 id

  • 获取 accessToken ,点击用户头像进入setting 按图示操作,第 3 步 填写你发起请求的域名。
  • 获取项目 id , 简单粗暴方案 进入 你项目仓库页面后 直接 源码搜索 project_id, value 就是 id 值。

第二步

更gitlab提供api 调用即可,大功告成 🤣🤣🤣

javascript 复制代码
<script>
  async function getGitlabFolderData(gitlabUrl, projectId, branch, folderPath, privateToken) {
    const url = `${gitlabUrl}/api/v4/projects/${projectId}/repository/tree?ref=${branch}&path=${folderPath}`;
    const options = {
      method: 'GET',
      headers: {
        'PRIVATE-TOKEN': privateToken
      }
    };

    try {
      const response = await fetch(url, options);
      if (!response.ok) {
        throw new Error(`Failed to retrieve folder data: ${response.status} ${response.statusText}`);
      }
      const data = await response.json();
      return data;
    } catch (error) {
      console.error(error);
      return null;
    }
  }

  // 配置参数
  const gitlabUrl = "http://10.11.13.111";
  const projectId = 215; // 项目 ID
  const branch = "test"; // 查询的分支
  const folderPath = "public/test"; // 查询的文件夹路径
  const privateToken = "xxxxxxxxxx"; // 私有令牌

  // 获取gitlab 仓库指定路径文件夹数据
  window.onload = function() {
    getGitlabFolderData(gitlabUrl, projectId, branch, folderPath, privateToken)
      .then(folderData => {
        console.log(folderData)
      });
  }
</script>
相关推荐
github.com/starRTC5 小时前
Claude Code中英文系列教程17:将Claude Code集成在GitLab工作流里面
git·gitlab·github
阿凡达蘑菇灯1 天前
git安装--gitlab操作
git·gitlab
凉云生烟2 天前
cpolar助力Grafana告别局域网束缚!让数据监控触手可及
服务器·网络·信息可视化·gitlab·内网穿透
shimly1234562 天前
为公司服务器配置 gitlab CI/CD
gitlab
小舞O_o2 天前
gitlab文件上传
linux·服务器·git·python·目标检测·机器学习·gitlab
墨笔之风3 天前
Linux (Docker环境)GitLab本地部署指南
linux·docker·gitlab
筑梦之路4 天前
gitlab相关记录——筑梦之路
gitlab
悟能不能悟4 天前
.gitlab-ci.yml这个文件有什么作用
ci/cd·gitlab
极小狐5 天前
极狐GitLab 18.7 版本发布,带来了改进的 GitLab Duo 分析仪表盘与密钥有效性校验、支持为聊天和智能体选择 AI 模型,以及更多新功能!
人工智能·gitlab
一叶飘零_sweeeet6 天前
解决 GitLab 响应超时:清理日志 + 重启服务一步到位
gitlab