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>
相关推荐
惜年_night1 天前
Docker部署05-GitLab的CI-CD发布
ci/cd·docker·gitlab
无人生还别怕2 天前
搭建gitlab服务并接入openldap认证
git·gitlab·github·openldap·ldap·统一认证
*_潇_*2 天前
0095__日常--记一次gitlab Runner配置与CI/CD环境搭建流程
ci/cd·gitlab
开发者联盟league3 天前
在ubuntu上使用apt方式安装gitlab
linux·ubuntu·gitlab
张小凡vip3 天前
gitlab的ci配置文件yaml参数说明
git·ci/cd·gitlab
田里的水稻3 天前
OE_gitlab服务操作和维护方法
分布式·gitlab
puamac4 天前
GitLab CI/CD 指南
gitlab
Rain5094 天前
GitLab-Runner + AI 代码审查服务 + 远程大模型 全套部署运维实战
linux·运维·人工智能·python·ci/cd·gitlab·ai编程
puamac5 天前
gitLab CI/CD 执行流程说明
ci/cd·gitlab
维度跃迁笔记5 天前
2核4G轻量服务器部署GitLab实战:配置调优与CI/CD拆分方案
服务器·ci/cd·gitlab