Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2019-12-10 02:31:36 -0500
committereric sciple <ericsciple@users.noreply.github.com>2019-12-10 02:31:36 -0500
commit18fbf40df59f4ca8e36d9954c30159dd21b41b43 (patch)
tree544c6ccfba4db66ef836bd43ad309cb330071fdb
parent32470e948187059a8541c783d3895fe9ddb1e0c5 (diff)
.
-rw-r--r--dist/index.js47
-rw-r--r--src/github-api-helper.ts66
2 files changed, 69 insertions, 44 deletions
diff --git a/dist/index.js b/dist/index.js
index f49291a..2bb2354 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -8380,26 +8380,9 @@ function downloadRepository(accessToken, owner, repo, ref, commit, repositoryPat
const fileStream = fs.createWriteStream(archivePath);
const fileStreamClosed = getFileClosedPromise(fileStream);
try {
- // Get the archive URL using the GitHub REST API
- core.info('Getting archive URL from GitHub REST API');
- const octokit = new github.GitHub(accessToken);
- const params = {
- method: 'HEAD',
- archive_format: IS_WINDOWS ? 'zipball' : 'tarball',
- owner: owner,
- repo: repo,
- ref: refHelper.getDownloadRef(ref, commit)
- };
- const response = yield octokit.repos.getArchiveLink(params);
- console.log('GOT THE RESPONSE');
- console.log(`status=${response.status}`);
- console.log(`headers=${JSON.stringify(response.headers)}`);
- if (response.status != 200) {
- throw new Error(`Unexpected response from GitHub API. Status: '${response.status}'`);
- }
- console.log('GETTING THE LOCATION');
- const archiveUrl = response.headers['Location']; // Do not print the archive URL because it has an embedded token
- assert.ok(archiveUrl, `Expected GitHub API response to contain 'Location' header`);
+ // Get the archive URL
+ core.info('Getting archive URL');
+ const archiveUrl = yield getArchiveUrl(accessToken, owner, repo, ref, commit);
// Download the archive
core.info('Downloading the archive'); // Do not print the archive URL because it has an embedded token
yield downloadFile(archiveUrl, fileStream);
@@ -8460,6 +8443,30 @@ function downloadRepository(accessToken, owner, repo, ref, commit, repositoryPat
});
}
exports.downloadRepository = downloadRepository;
+function getArchiveUrl(accessToken, owner, repo, ref, commit) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const octokit = new github.GitHub(accessToken);
+ const params = {
+ method: 'HEAD',
+ owner: owner,
+ repo: repo,
+ archive_format: IS_WINDOWS ? 'zipball' : 'tarball',
+ ref: refHelper.getDownloadRef(ref, commit)
+ };
+ const response = yield octokit.repos.getArchiveLink(params);
+ console.log('GOT THE RESPONSE');
+ console.log(`status=${response.status}`);
+ console.log(`headers=${JSON.stringify(response.headers)}`);
+ console.log(`headers=${JSON.stringify(response.data)}`);
+ if (response.status != 200) {
+ throw new Error(`Unexpected response from GitHub API. Status: '${response.status}'`);
+ }
+ console.log('GETTING THE LOCATION');
+ const archiveUrl = response.headers['Location']; // Do not print the archive URL because it has an embedded token
+ assert.ok(archiveUrl, `Expected GitHub API response to contain 'Location' header`);
+ return archiveUrl;
+ });
+}
function downloadFile(url, fileStream) {
return new Promise((resolve, reject) => {
try {
diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts
index 3407c25..1b1cf65 100644
--- a/src/github-api-helper.ts
+++ b/src/github-api-helper.ts
@@ -40,30 +40,14 @@ export async function downloadRepository(
const fileStreamClosed = getFileClosedPromise(fileStream)
try {
- // Get the archive URL using the GitHub REST API
- core.info('Getting archive URL from GitHub REST API')
- const octokit = new github.GitHub(accessToken)
- const params: RequestOptions & ReposGetArchiveLinkParams = {
- method: 'HEAD',
- archive_format: IS_WINDOWS ? 'zipball' : 'tarball',
- owner: owner,
- repo: repo,
- ref: refHelper.getDownloadRef(ref, commit)
- }
- const response = await octokit.repos.getArchiveLink(params)
- console.log('GOT THE RESPONSE')
- console.log(`status=${response.status}`)
- console.log(`headers=${JSON.stringify(response.headers)}`)
- if (response.status != 200) {
- throw new Error(
- `Unexpected response from GitHub API. Status: '${response.status}'`
- )
- }
- console.log('GETTING THE LOCATION')
- const archiveUrl = response.headers['Location'] // Do not print the archive URL because it has an embedded token
- assert.ok(
- archiveUrl,
- `Expected GitHub API response to contain 'Location' header`
+ // Get the archive URL
+ core.info('Getting archive URL')
+ const archiveUrl = await getArchiveUrl(
+ accessToken,
+ owner,
+ repo,
+ ref,
+ commit
)
// Download the archive
@@ -137,6 +121,40 @@ export async function downloadRepository(
} as ExecOptions)
}
+async function getArchiveUrl(
+ accessToken: string,
+ owner: string,
+ repo: string,
+ ref: string,
+ commit: string
+): Promise<string> {
+ const octokit = new github.GitHub(accessToken)
+ const params: RequestOptions & ReposGetArchiveLinkParams = {
+ method: 'HEAD',
+ owner: owner,
+ repo: repo,
+ archive_format: IS_WINDOWS ? 'zipball' : 'tarball',
+ ref: refHelper.getDownloadRef(ref, commit)
+ }
+ const response = await octokit.repos.getArchiveLink(params)
+ console.log('GOT THE RESPONSE')
+ console.log(`status=${response.status}`)
+ console.log(`headers=${JSON.stringify(response.headers)}`)
+ console.log(`headers=${JSON.stringify(response.data)}`)
+ if (response.status != 200) {
+ throw new Error(
+ `Unexpected response from GitHub API. Status: '${response.status}'`
+ )
+ }
+ console.log('GETTING THE LOCATION')
+ const archiveUrl = response.headers['Location'] // Do not print the archive URL because it has an embedded token
+ assert.ok(
+ archiveUrl,
+ `Expected GitHub API response to contain 'Location' header`
+ )
+ return archiveUrl
+}
+
function downloadFile(url: string, fileStream: WriteStream): Promise<void> {
return new Promise((resolve, reject) => {
try {