google-apps-script - 如何使用 Google Apps 脚本将 .git 从 GitHub 克隆到 Google Drive?
问题描述
我正在编写一个 Google Apps 脚本,以经常将我的所有 GitHub 存储库备份到 Google Drive。
对于 JSON 响应,它工作正常。
对于 .git 档案本身,我没有找到任何解决方案。
我的目标是获取包含所有分支的 .git 存档。
我的最后一次尝试:
const response = UrlFetchApp.fetch('https://' + accessToken + ':x-oauth-basic@github.com/' + repoFullName + '.git');
const content = response.getContentText();
DriveApp.createFile('Repository.git', content);
导致 GitHub 下载的 HTML 页面“找不到页面”:-(
和:
const response = UrlFetchApp.fetch('http://github.com/' + repo.full_name + '/zipball/master/', { headers: { Authorization: 'token ' + accessToken } });
const content = response.getContent();
DriveApp.createFile('Repository.zip', content);
导致 macOS 无法读取的存档。
任何想法?
此致,
丹尼斯
解决方案
谢谢你的想法。我的目标是备份所有问题、评论、文件等。
我解决了将主分支下载为 zip 文件的问题,如下所示:
const gitFileResponse = UrlFetchApp.fetch('http://github.com/' + repo.full_name + '/zipball/master/', { headers: { Authorization: 'token ' + accessToken } })
const gitFileContent = gitFileResponse.getBlob()
gitFileContent.setContentTypeFromExtension()
DriveApp.createFile(gitFileContent).setName('Master.zip')
:-)
推荐阅读
- django - Django REST Serializer 使用错误的模型进行序列化
- python - python文件写入程序运行时如何更新桌面上的文件大小
- javascript - 使用 d3.js 更新表数据
- c# - C#捕获从不在进程中的函数返回的异常?
- r - 如何设置仅在输入 3 时才显示集合向量的函数?
- javascript - 如果 URI 没有改变,例如在单页应用程序上,如何检测用户是否在新页面上?
- angular - Angular Kendo UI 全局访问
- php - 内连接循环通过
- git - 如何 git rebase 从另一个分支直接到 master 分支?
- javascript - 受控数字比例映射