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>
相关推荐
QN1幻化引擎18 小时前
SFA 信号场注意力:用8KB参数换248x KV Cache压缩,边缘设备也能跑长序列
人工智能·算法·gitee·gitlab
阿里云云原生19 小时前
研发福音:云效 AI 智能评审正式支持 GitLab 集成,VPC 内网即可实现自动审阅
gitlab
这个需求做不了4 天前
Jenkins自动化构建与CI/CD流水线,并配置GitLab
java·ci/cd·自动化·gitlab·jenkins
qq_452396235 天前
第六篇:《GitLab CI 进阶:多环境部署与环境变量管理》
git·ci/cd·gitlab
考虑考虑6 天前
git中的tag
git·gitlab·github
Skilce8 天前
基于GitLab CI/CD + Kubernetes的自动化部署平台搭建
ci/cd·kubernetes·gitlab
行者-全栈开发8 天前
Jenkins 与 GitLab 深度集成实战:从 Webhook 到 Merge Request 全流程自动化
gitlab·jenkins·webhook·merge request·multibranch·source plugin·ci/cd 自动化
zoipuus10 天前
上传repo仓库到自己的gitlab
linux·gitlab·shell·全志·tina
刘马想放假11 天前
Git 从入门到进阶:一篇吃透版本管理的实战指南
git·gitlab
NexTunnel14 天前
公司老项目还在 SVN,远程维护怎么做更稳?
git·svn·gitlab·远程工作·nextunnel