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>
相关推荐
jasnet_u3 天前
如何重置Gitlab的root用户密码
gitlab
全栈工程师修炼指南3 天前
告别手动构建!Jenkins 与 Gitlab 完美协作,根据参数自动化触发CI/CD流水线实践
运维·ci/cd·自动化·gitlab·jenkins
xiaok5 天前
分支管理提交代码
git·gitlab·github
*老工具人了*6 天前
Terraform整合到GitLab+Jenkins工具链
gitlab·jenkins·terraform
走上未曾设想的道路6 天前
中标麒麟7.4为gitlab添加Registry
gitlab
韩zj7 天前
docker部署Gitlab社区版,步骤以及外网访问出现502的解决方式
docker·容器·gitlab
走上未曾设想的道路7 天前
gitlab流水线与k8s集群的联通
kubernetes·gitlab
走上未曾设想的道路7 天前
中标麒麟7.4部署gitlab-runner
gitlab
xiaok8 天前
把代码上传到gitee的时候,怎么忽略node_modules文件夹
git·gitlab·github
deeper_wind8 天前
OpenEuler部署gitlab(小白的“升级打怪”成长之路)
gitlab