Skip to content

Commit

Permalink
fix(github-actions): no longer use promisify (#1084)
Browse files Browse the repository at this point in the history
Promisify for setTimeout is no longer available and instead the promise timeout is manually created.

PR Close #1084
  • Loading branch information
josephperrott committed Mar 31, 2023
1 parent 4d96664 commit 8b7f6b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 2 additions & 6 deletions github-actions/lock-closed/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core';
import {context} from '@actions/github';
import {Octokit} from '@octokit/rest';
import {ANGULAR_LOCK_BOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js';
import {setTimeout as setTimeoutPromise} from 'timers/promises';

async function lockIssue(
client: Octokit,
Expand All @@ -24,11 +25,6 @@ async function lockIssue(
});
}

/** Creates a promise which resolves after a set period of time. */
function timeout(ms: number) {
return setTimeout.__promisify__(ms);
}

async function main() {
const reposToBeChecked = core.getMultilineInput('repos', {required: true, trimWhitespace: true});
await core.group('Repos being checked for lockable issues:', async () =>
Expand Down Expand Up @@ -101,7 +97,7 @@ async function runLockClosedAction(github: Octokit, repo: string): Promise<void>
}
console.info(`Locking ${itemType} #${item.number}`);
await lockIssue(github, item.number, repo, message);
await timeout(250);
await setTimeoutPromise(250);
++lockCount;
} catch (error: any) {
// TODO(josephperrott): properly set typings for error.
Expand Down
18 changes: 8 additions & 10 deletions github-actions/lock-closed/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8326,7 +8326,7 @@ var require_lib4 = __commonJS({
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref$size = _ref.size;
let size = _ref$size === void 0 ? 0 : _ref$size;
var _ref$timeout = _ref.timeout;
let timeout2 = _ref$timeout === void 0 ? 0 : _ref$timeout;
let timeout = _ref$timeout === void 0 ? 0 : _ref$timeout;
if (body == null) {
body = null;
} else if (isURLSearchParams(body)) {
Expand All @@ -8350,7 +8350,7 @@ var require_lib4 = __commonJS({
error: null
};
this.size = size;
this.timeout = timeout2;
this.timeout = timeout;
if (body instanceof Stream) {
body.on("error", function(err) {
const error2 = err.name === "AbortError" ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, "system", err);
Expand Down Expand Up @@ -13220,7 +13220,7 @@ var require_lib6 = __commonJS({
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref$size = _ref.size;
let size = _ref$size === void 0 ? 0 : _ref$size;
var _ref$timeout = _ref.timeout;
let timeout2 = _ref$timeout === void 0 ? 0 : _ref$timeout;
let timeout = _ref$timeout === void 0 ? 0 : _ref$timeout;
if (body == null) {
body = null;
} else if (isURLSearchParams(body)) {
Expand All @@ -13244,7 +13244,7 @@ var require_lib6 = __commonJS({
error: null
};
this.size = size;
this.timeout = timeout2;
this.timeout = timeout;
if (body instanceof Stream) {
body.on("error", function(err) {
const error2 = err.name === "AbortError" ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, "system", err);
Expand Down Expand Up @@ -17609,7 +17609,7 @@ var require_lib8 = __commonJS({
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref$size = _ref.size;
let size = _ref$size === void 0 ? 0 : _ref$size;
var _ref$timeout = _ref.timeout;
let timeout2 = _ref$timeout === void 0 ? 0 : _ref$timeout;
let timeout = _ref$timeout === void 0 ? 0 : _ref$timeout;
if (body == null) {
body = null;
} else if (isURLSearchParams(body)) {
Expand All @@ -17633,7 +17633,7 @@ var require_lib8 = __commonJS({
error: null
};
this.size = size;
this.timeout = timeout2;
this.timeout = timeout;
if (body instanceof Stream) {
body.on("error", function(err) {
const error2 = err.name === "AbortError" ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, "system", err);
Expand Down Expand Up @@ -23471,6 +23471,7 @@ async function revokeActiveInstallationToken(githubOrToken) {
}

//
import { setTimeout as setTimeoutPromise } from "timers/promises";
async function lockIssue(client, issue, repo, message) {
await client.issues.createComment({
repo,
Expand All @@ -23484,9 +23485,6 @@ async function lockIssue(client, issue, repo, message) {
issue_number: issue
});
}
function timeout(ms) {
return setTimeout.__promisify__(ms);
}
async function main() {
const reposToBeChecked = core.getMultilineInput("repos", { required: true, trimWhitespace: true });
await core.group("Repos being checked for lockable issues:", async () => reposToBeChecked.forEach((repo) => core.info(`- ${repo}`)));
Expand Down Expand Up @@ -23542,7 +23540,7 @@ Read more about our [automatic conversation locking policy](${policyUrl}).
}
console.info(`Locking ${itemType} #${item.number}`);
await lockIssue(github, item.number, repo, message);
await timeout(250);
await setTimeoutPromise(250);
++lockCount;
} catch (error2) {
core.debug(error2);
Expand Down

0 comments on commit 8b7f6b9

Please sign in to comment.