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>
相关推荐
you来有去14 小时前
记录一下在k3s快速创建gitlab
java·kubernetes·gitlab
木二21 小时前
001.GItLab介绍及云原生部署
gitlab·cicd
User_undefined2 天前
批量将gitlab仓库转移到gitea中
gitlab·gitea
秋の水2 天前
使用Docker Desktop部署GitLab
docker·gitlab
深情不及里子5 天前
纯手工搭建整套CI/CD流水线指南
ci/cd·gitlab·jenkins·harbor
AliCloudROS6 天前
阿里云ACK+GitLab企业级部署实战教程
k8s·gitlab·helm·ack·计算巢
{⌐■_■}6 天前
【gitlab】认识 持续集成与部署
ci/cd·log4j·gitlab
JAVA坚守者12 天前
Jenkins+maven+gitlab+shell 实现项目自动化部署
gitlab·jenkins·maven
大熊程序猿12 天前
jenkins 配置ssh拉取gitlab
ssh·gitlab·jenkins
到不了p8不改名13 天前
gitlab无法登录问题
运维·服务器·容器·centos·gitlab·jenkins