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>
相关推荐
大脸男孩17 小时前
gitlab迁移
运维·gitlab
hillstream31 天前
配置git从公网能访问-基于frp
git·gitlab
spjhandsomeman2 天前
各个历史版本mysql/tomcat/Redis/Jdk/Apache/gitlab下载地址
java·redis·mysql·jdk·tomcat·gitlab
freejackman2 天前
Git从入门到精通
git·gitee·gitlab·github
Cchaofan3 天前
Git/GitLab日常使用的命令指南来了!
git·gitlab
可乐加.糖4 天前
项目版本管理和Git分支管理方案
java·git·目标跟踪·gitlab·敏捷流程·源代码管理
GoodStudyAndDayDayUp4 天前
gitlab+portainer 实现Ruoyi Vue后端CI/CD
vue.js·ci/cd·gitlab
伊成5 天前
gitlab提交测试分支的命令和流程
gitlab
山师第一深情5 天前
ssh connect to remote gitlab without authority
服务器·ssh·gitlab
GoodStudyAndDayDayUp5 天前
gitlab+portainer 实现Ruoyi Vue前端CI/CD
前端·vue.js·gitlab