Skip to content

Commit

Permalink
Fixed runtime argument error
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Jul 9, 2021
1 parent d6127d8 commit 4d96d92
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions scripts/github-releases.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
const assert = require("assert");
const program = require("commander");
const { Octokit } = require("@octokit/rest");
const path = require("path");
const fs = require("fs");
const assert = require('assert');
const program = require('commander');
const { Octokit } = require('@octokit/rest');
const path = require('path');
const fs = require('fs');

const { wrapCommand } = require("./utils");
const { wrapCommand } = require('./utils');

const {
GITHUB_TOKEN,
GITHUB_OWNER,
GITHUB_REPO
} = process.env;
const { GITHUB_TOKEN, GITHUB_OWNER, GITHUB_REPO } = process.env;

assert(GITHUB_TOKEN, "Expected a GITHUB_TOKEN environment variable");
assert(GITHUB_OWNER, "Expected a GITHUB_OWNER environment variable");
assert(GITHUB_REPO, "Expected a GITHUB_REPO environment variable");
assert(GITHUB_TOKEN, 'Expected a GITHUB_TOKEN environment variable');
assert(GITHUB_OWNER, 'Expected a GITHUB_OWNER environment variable');
assert(GITHUB_REPO, 'Expected a GITHUB_REPO environment variable');

const octokit = new Octokit({
auth: GITHUB_TOKEN,
});

function determinContentType(assetPath) {
if (assetPath.endsWith('.tgz') || assetPath.endsWith('.tar.gz')) {
return "application/tar+gzip";
return 'application/tar+gzip';
} else if (assetPath.endsWith('.exe')) {
return "application/vnd.microsoft.portable-executable";
return 'application/vnd.microsoft.portable-executable';
} else if (assetPath.endsWith('.zip')) {
return "application/zip";
return 'application/zip';
} else if (assetPath.endsWith('.dmg')) {
return "application/x-apple-diskimage";
return 'application/x-apple-diskimage';
} else if (assetPath.endsWith('.AppImage')) {
// @see https://cgit.freedesktop.org/xdg/shared-mime-info/commit/?id=01fa61fc002afdcf43f61e7df2d6cc6f6968d8d2
return "application/x-iso9660-appimage";
return 'application/x-iso9660-appimage';
}
}

program
.command("upload-asset <tag> <asset-path>")
.action(wrapCommand(async (tag, assetPath) => {
program.command('upload-asset <tag> <asset-path>').action(
wrapCommand(async (tag, assetPath) => {
// Request all releases, as we cannot request by tag name for draft releases
const { data: releases } = await octokit.repos.listReleases({
owner: GITHUB_OWNER,
Expand All @@ -55,8 +50,8 @@ program
const assetContent = fs.readFileSync(assetPath);
await octokit.repos.uploadReleaseAsset({
headers: {
"content-length": assetContent.length,
"content-type": assetContentType
'content-length': assetContent.length,
'content-type': assetContentType,
},
url: release.upload_url,
name: path.basename(assetPath),
Expand All @@ -65,11 +60,11 @@ program
} else {
throw new Error("Couldn't find the release");
}
}));
}),
);

program
.command("create-draft <tag> <release notes path>")
.action(wrapCommand(async (tag, releaseNotesPath) => {
program.command('create-draft <tag> <release-notes-path>').action(
wrapCommand(async (tag, releaseNotesPath) => {
// Read the content of the release notes
const releaseNotes = fs.readFileSync(releaseNotesPath, 'utf8');
// Create a draft release
Expand All @@ -79,13 +74,13 @@ program
tag_name: tag,
name: tag.substring(1),
body: releaseNotes,
draft: true
draft: true,
});
}));
}),
);

program
.command("publish <tag>")
.action(wrapCommand(async (tag, releaseNotesPath) => {
program.command('publish <tag>').action(
wrapCommand(async tag => {
// Request all releases, as we cannot request by tag name for draft releases
const { data: releases } = await octokit.repos.listReleases({
owner: GITHUB_OWNER,
Expand All @@ -103,52 +98,57 @@ program
} else {
throw new Error("Couldn't find the release");
}
}));
}),
);

program
.command("create-pull-request <head> <base> <title>")
.command('create-pull-request <head> <base> <title>')
.option('-a, --assignee [github-handle]', 'Who should be assigned the PR?')
.option('-r, --reviewer [github-handle]', 'Who should be reviewing the PR?')
.option('-p, --print-number', 'Should the PR number be printed?')
.action(wrapCommand(async (head, base, title, { assignee, reviewer, printNumber }) => {
// Create a pull request
const pr = await octokit.pulls.create({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
title,
head,
base,
});
if (reviewer) {
try {
await octokit.pulls.createReviewRequest({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
pull_number: pr.data.number,
reviewers: [ reviewer ],
});
} catch (err) {
// A failed review request should not fail command.
console.warn(err.message);
}
}
if (assignee) {
try {
await octokit.issues.addAssignees({
.action(
wrapCommand(
async (head, base, title, { assignee, reviewer, printNumber }) => {
// Create a pull request
const pr = await octokit.pulls.create({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
issue_number: pr.data.number,
assignees: [ assignee ],
title,
head,
base,
});
} catch (err) {
// A failed assignment should not fail command.
console.warn(err.message);
}
}
// Print the number if we're asked to
if (printNumber) {
console.log(pr.data.number);
}
}));
if (reviewer) {
try {
await octokit.pulls.createReviewRequest({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
pull_number: pr.data.number,
reviewers: [reviewer],
});
} catch (err) {
// A failed review request should not fail command.
console.warn(err.message);
}
}
if (assignee) {
try {
await octokit.issues.addAssignees({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
issue_number: pr.data.number,
assignees: [assignee],
});
} catch (err) {
// A failed assignment should not fail command.
console.warn(err.message);
}
}
// Print the number if we're asked to
if (printNumber) {
console.log(pr.data.number);
}
},
),
);

program.parse(process.argv);

0 comments on commit 4d96d92

Please sign in to comment.