首页 > 解决方案 > 如何使用 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 无法读取的存档。

任何想法?

此致,

丹尼斯

标签: google-apps-scriptgithub-api

解决方案


谢谢你的想法。我的目标是备份所有问题、评论、文件等。

我解决了将主分支下载为 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')

:-)


推荐阅读