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>
相关推荐
hl040616 小时前
GitLab CI + Docker 自动构建前端项目并部署 — 完整流程文档
ci/cd·docker·gitlab
先天打工圣体的男人16 小时前
Linux环境gitlab多种部署方式及具体使用
运维·git·gitlab
委婉待续1 天前
基于linux环境在centos7上部署gitlab
gitlab
疯狂吧小飞牛5 天前
基于ubuntu搭建gitlab
linux·ubuntu·gitlab
__Smile°7 天前
Gitlab+Jenkins+K8S+Registry 建立 CI/CD 流水线
linux·ci/cd·docker·kubernetes·gitlab·jenkins
某某7 天前
gitlab启动失败,如何解决
gitlab
yangrenrui7 天前
GitLab:一站式 DevOps 平台的全方位解析
运维·gitlab·devops
流泪兔兔头8 天前
GitLab 同时拣选多个分支
gitlab
hi_link9 天前
idea添加gitlab访问令牌
gitlab