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>
相关推荐
MinterFusion1 天前
如果openKylin 2.0 SP2主机的IPv4地址改变,如何让GitLab正常运行
运维·gitlab·系统配置·系统维护·明德融创
Elivs.Xiang1 天前
ubuntu20中安装gitlab
linux·ubuntu·gitlab
csdn_aspnet1 天前
Gemini实战:用AI写CI/CD脚本,分享Gemini辅助编写GitLab CI、GitHub Actions等运维脚本的硬核技巧
人工智能·ci/cd·ai·gitlab·gemini·辅助编程
Cyber4K2 天前
【DevOps专项】GitLab 与 Jenkins 介绍及部署持续集成环境
运维·ci/cd·gitlab·jenkins·devops
IT布道3 天前
[GitLab] 项目源码迁移踩坑记
运维·gitlab
极小狐4 天前
PingCode × 极狐GitLab 用AI打通需求到交付全链路,研发管理与工程交付真正一体化
人工智能·gitlab·pingcode
qq_452396235 天前
【工程实战】第九篇:持续集成 —— Jenkins 与 GitLab CI:构建无人值守的自动化流水线
ci/cd·gitlab·jenkins
angushine8 天前
gitlab跨服务器备份
服务器·gitlab·github
蜡台9 天前
Git 常用配置:修改地址 ,提交模板配置
git·gitlab·template·git commit·gitbash
染夕陌木9 天前
极简教程:GitLab 上配置 SSH Key(附常见问题解决)
运维·ssh·gitlab