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>
相关推荐
字节逆旅10 小时前
Git提交后追加修改操作指南
gitlab
爱宇阳16 小时前
GitLab Docker Compose 迁移教程
docker·容器·gitlab
Blue啊18 小时前
code Merge(qcc)
git·gitlab
友莘居士19 小时前
极速迁移:GitLab项目无缝转移实战手册
gitlab·代码迁移·git命令
谢栋_19 小时前
基于 GitLab CI/CD 与 Google Gemini 的 AI Code Review 自动化方案
人工智能·ci/cd·gitlab
lijunjun3 天前
当ubuntu 系统的IP地址修改之后,gitlab服务应该如何修改?
tcp/ip·ubuntu·gitlab
Qperable6 天前
gitlab-runner提示401 Unauthorized
后端·gitlab
西瓜er6 天前
Docker 一键部署指南:GitLab、Nacos、Redis、MySQL 与 MinIO 全解析
redis·docker·gitlab
yunson_Liu7 天前
jenkins更新了gitlab后出现报错
运维·gitlab·jenkins
stark张宇7 天前
Git 与 GitHub 协同工作流:从0到1搭建版本控制体系
git·gitlab·github