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>
相关推荐
月上柳青8 分钟前
docker gitlab arm64 版本安装部署
docker·容器·gitlab
画船听雨眠aa1 天前
gitlab云服务器配置
服务器·git·elasticsearch·gitlab
玉米的玉*」*4 天前
新项目上传gitlab
gitlab
鲁子狄4 天前
[笔记] 极狐GitLab实例 : 手动备份步骤总结
linux·运维·笔记·ubuntu·centos·gitlab
节省钱8 天前
【Git】如何在 Git 提交后补充 Change-Id
服务器·git·gitee·gitlab·github·gitcode
dujunqiu8 天前
gitlab处理空文件夹的提交或空文件夹提交失败
git·gitlab·github
摸鱼仙人~8 天前
将本地项目上传到 GitLab/GitHub
elasticsearch·gitlab·github
pingxiaozhao9 天前
Windows的docker中安装gitlab
docker·容器·gitlab
Channing Lewis9 天前
如何实现gitlab和jira连通
gitlab·jira
一颗大樱桃9 天前
Ubuntu安装GitLab
linux·ubuntu·gitlab