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>
相关推荐
HIT_Weston7 小时前
63、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(七)
前端·ubuntu·gitlab
HIT_Weston11 小时前
65、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(九)
前端·ubuntu·gitlab
victory043113 小时前
GitLab部署报告
gitlab
HIT_Weston13 小时前
64、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(八)
前端·ubuntu·gitlab
HIT_Weston13 小时前
62、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(六)
前端·ubuntu·gitlab
不爱吃米饭_1 天前
Gitea 轻量级的Git方案 - Gitlab的替代品
git·gitlab·gitea
嘻哈baby1 天前
自建GitLab与CI/CD实战:团队协作完整方案
ci/cd·gitlab
秦时明月天明1 天前
GitLab SSH Key 过期:git pull failed : remote your ssh key has expired
git·ssh·gitlab
极限实验室2 天前
程序员爆哭!我们让 COCO AI 接管 GitLab 审查后,团队直接起飞:连 CTO 都说“这玩意儿比人靠谱多了
人工智能·gitlab
HIT_Weston3 天前
61、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(五)
前端·ubuntu·gitlab