Compile actions folder (#23049)

This commit is contained in:
Cheena Malhotra
2023-05-08 17:30:55 -07:00
committed by GitHub
parent 9db608d800
commit a525f3cb85
4 changed files with 51 additions and 56 deletions

View File

@@ -41,17 +41,18 @@ class OctoKit {
}; };
for await (const pageResponse of this.octokit.paginate.iterator(options)) { for await (const pageResponse of this.octokit.paginate.iterator(options)) {
await timeout(); await timeout();
await (0, utils_1.logRateLimit)(this.token); await utils_1.logRateLimit(this.token);
const page = pageResponse.data; const page = pageResponse.data;
yield page.map((issue) => new OctoKitIssue(this.token, this.params, this.octokitIssueToIssue(issue))); yield page.map((issue) => new OctoKitIssue(this.token, this.params, this.octokitIssueToIssue(issue)));
} }
} }
async createIssue(owner, repo, title, body) { async createIssue(owner, repo, title, body) {
(0, core_1.debug)(`Creating issue \`${title}\` on ${owner}/${repo}`); core_1.debug(`Creating issue \`${title}\` on ${owner}/${repo}`);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.create({ owner, repo, title, body }); await this.octokit.issues.create({ owner, repo, title, body });
} }
octokitIssueToIssue(issue) { octokitIssueToIssue(issue) {
var _a, _b, _c, _d, _e, _f;
return { return {
author: { name: issue.user.login, isGitHubApp: issue.user.type === 'Bot' }, author: { name: issue.user.login, isGitHubApp: issue.user.type === 'Bot' },
body: issue.body, body: issue.body,
@@ -62,8 +63,8 @@ class OctoKit {
locked: issue.locked, locked: issue.locked,
numComments: issue.comments, numComments: issue.comments,
reactions: issue.reactions, reactions: issue.reactions,
assignee: issue.assignee?.login ?? issue.assignees?.[0]?.login, assignee: (_b = (_a = issue.assignee) === null || _a === void 0 ? void 0 : _a.login) !== null && _b !== void 0 ? _b : (_d = (_c = issue.assignees) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.login,
milestoneId: issue.milestone?.number ?? null, milestoneId: (_f = (_e = issue.milestone) === null || _e === void 0 ? void 0 : _e.number) !== null && _f !== void 0 ? _f : null,
createdAt: +new Date(issue.created_at), createdAt: +new Date(issue.created_at),
updatedAt: +new Date(issue.updated_at), updatedAt: +new Date(issue.updated_at),
closedAt: issue.closed_at ? +new Date(issue.closed_at) : undefined, closedAt: issue.closed_at ? +new Date(issue.closed_at) : undefined,
@@ -71,10 +72,10 @@ class OctoKit {
} }
async hasWriteAccess(user) { async hasWriteAccess(user) {
if (user.name in this.writeAccessCache) { if (user.name in this.writeAccessCache) {
(0, core_1.debug)('Got permissions from cache for ' + user); core_1.debug('Got permissions from cache for ' + user);
return this.writeAccessCache[user.name]; return this.writeAccessCache[user.name];
} }
(0, core_1.debug)('Fetching permissions for ' + user); core_1.debug('Fetching permissions for ' + user);
const permissions = (await this.octokit.repos.getCollaboratorPermissionLevel({ const permissions = (await this.octokit.repos.getCollaboratorPermissionLevel({
...this.params, ...this.params,
username: user.name, username: user.name,
@@ -94,14 +95,14 @@ class OctoKit {
} }
} }
async createLabel(name, color, description) { async createLabel(name, color, description) {
(0, core_1.debug)('Creating label ' + name); core_1.debug('Creating label ' + name);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.createLabel({ ...this.params, color, description, name }); await this.octokit.issues.createLabel({ ...this.params, color, description, name });
else else
this.mockLabels.add(name); this.mockLabels.add(name);
} }
async deleteLabel(name) { async deleteLabel(name) {
(0, core_1.debug)('Deleting label ' + name); core_1.debug('Deleting label ' + name);
try { try {
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.deleteLabel({ ...this.params, name }); await this.octokit.issues.deleteLabel({ ...this.params, name });
@@ -114,7 +115,7 @@ class OctoKit {
} }
} }
async readConfig(path) { async readConfig(path) {
(0, core_1.debug)('Reading config at ' + path); core_1.debug('Reading config at ' + path);
const repoPath = `.github/${path}.json`; const repoPath = `.github/${path}.json`;
const data = (await this.octokit.repos.getContents({ ...this.params, path: repoPath })).data; const data = (await this.octokit.repos.getContents({ ...this.params, path: repoPath })).data;
if ('type' in data && data.type === 'file') { if ('type' in data && data.type === 'file') {
@@ -126,10 +127,10 @@ class OctoKit {
throw Error('Found directory at config path when expecting file' + JSON.stringify(data)); throw Error('Found directory at config path when expecting file' + JSON.stringify(data));
} }
async releaseContainsCommit(release, commit) { async releaseContainsCommit(release, commit) {
if ((0, utils_1.getInput)('commitReleasedDebuggingOverride')) { if (utils_1.getInput('commitReleasedDebuggingOverride')) {
return true; return true;
} }
return new Promise((resolve, reject) => (0, child_process_1.exec)(`git -C ./repo merge-base --is-ancestor ${commit} ${release}`, (err) => !err || err.code === 1 ? resolve(!err) : reject(err))); return new Promise((resolve, reject) => child_process_1.exec(`git -C ./repo merge-base --is-ancestor ${commit} ${release}`, (err) => !err || err.code === 1 ? resolve(!err) : reject(err)));
} }
} }
exports.OctoKit = OctoKit; exports.OctoKit = OctoKit;
@@ -140,7 +141,7 @@ class OctoKitIssue extends OctoKit {
this.issueData = issueData; this.issueData = issueData;
} }
async addAssignee(assignee) { async addAssignee(assignee) {
(0, core_1.debug)('Adding assignee ' + assignee + ' to ' + this.issueData.number); core_1.debug('Adding assignee ' + assignee + ' to ' + this.issueData.number);
if (!this.options.readonly) { if (!this.options.readonly) {
await this.octokit.issues.addAssignees({ await this.octokit.issues.addAssignees({
...this.params, ...this.params,
@@ -150,7 +151,7 @@ class OctoKitIssue extends OctoKit {
} }
} }
async closeIssue() { async closeIssue() {
(0, core_1.debug)('Closing issue ' + this.issueData.number); core_1.debug('Closing issue ' + this.issueData.number);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.update({ await this.octokit.issues.update({
...this.params, ...this.params,
@@ -159,13 +160,13 @@ class OctoKitIssue extends OctoKit {
}); });
} }
async lockIssue() { async lockIssue() {
(0, core_1.debug)('Locking issue ' + this.issueData.number); core_1.debug('Locking issue ' + this.issueData.number);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.lock({ ...this.params, issue_number: this.issueData.number }); await this.octokit.issues.lock({ ...this.params, issue_number: this.issueData.number });
} }
async getIssue() { async getIssue() {
if (isIssue(this.issueData)) { if (isIssue(this.issueData)) {
(0, core_1.debug)('Got issue data from query result ' + this.issueData.number); core_1.debug('Got issue data from query result ' + this.issueData.number);
return this.issueData; return this.issueData;
} }
const issue = (await this.octokit.issues.get({ const issue = (await this.octokit.issues.get({
@@ -176,7 +177,7 @@ class OctoKitIssue extends OctoKit {
return (this.issueData = this.octokitIssueToIssue(issue)); return (this.issueData = this.octokitIssueToIssue(issue));
} }
async postComment(body) { async postComment(body) {
(0, core_1.debug)(`Posting comment ${body} on ${this.issueData.number}`); core_1.debug(`Posting comment ${body} on ${this.issueData.number}`);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.createComment({ await this.octokit.issues.createComment({
...this.params, ...this.params,
@@ -185,7 +186,7 @@ class OctoKitIssue extends OctoKit {
}); });
} }
async deleteComment(id) { async deleteComment(id) {
(0, core_1.debug)(`Deleting comment ${id} on ${this.issueData.number}`); core_1.debug(`Deleting comment ${id} on ${this.issueData.number}`);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.deleteComment({ await this.octokit.issues.deleteComment({
owner: this.params.owner, owner: this.params.owner,
@@ -194,7 +195,7 @@ class OctoKitIssue extends OctoKit {
}); });
} }
async setMilestone(milestoneId) { async setMilestone(milestoneId) {
(0, core_1.debug)(`Setting milestone for ${this.issueData.number} to ${milestoneId}`); core_1.debug(`Setting milestone for ${this.issueData.number} to ${milestoneId}`);
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.update({ await this.octokit.issues.update({
...this.params, ...this.params,
@@ -203,7 +204,7 @@ class OctoKitIssue extends OctoKit {
}); });
} }
async *getComments(last) { async *getComments(last) {
(0, core_1.debug)('Fetching comments for ' + this.issueData.number); core_1.debug('Fetching comments for ' + this.issueData.number);
const response = this.octokit.paginate.iterator(this.octokit.issues.listComments.endpoint.merge({ const response = this.octokit.paginate.iterator(this.octokit.issues.listComments.endpoint.merge({
...this.params, ...this.params,
issue_number: this.issueData.number, issue_number: this.issueData.number,
@@ -220,7 +221,7 @@ class OctoKitIssue extends OctoKit {
} }
} }
async addLabel(name) { async addLabel(name) {
(0, core_1.debug)(`Adding label ${name} to ${this.issueData.number}`); core_1.debug(`Adding label ${name} to ${this.issueData.number}`);
if (!(await this.repoHasLabel(name))) { if (!(await this.repoHasLabel(name))) {
throw Error(`Action could not execute becuase label ${name} is not defined.`); throw Error(`Action could not execute becuase label ${name} is not defined.`);
} }
@@ -232,7 +233,7 @@ class OctoKitIssue extends OctoKit {
}); });
} }
async removeLabel(name) { async removeLabel(name) {
(0, core_1.debug)(`Removing label ${name} from ${this.issueData.number}`); core_1.debug(`Removing label ${name} from ${this.issueData.number}`);
try { try {
if (!this.options.readonly) if (!this.options.readonly)
await this.octokit.issues.removeLabel({ await this.octokit.issues.removeLabel({
@@ -249,6 +250,7 @@ class OctoKitIssue extends OctoKit {
} }
} }
async getClosingInfo() { async getClosingInfo() {
var _a;
if ((await this.getIssue()).open) { if ((await this.getIssue()).open) {
return; return;
} }
@@ -262,7 +264,7 @@ class OctoKitIssue extends OctoKit {
for (const timelineEvent of timelineEvents) { for (const timelineEvent of timelineEvents) {
if (timelineEvent.event === 'closed') { if (timelineEvent.event === 'closed') {
closingCommit = { closingCommit = {
hash: timelineEvent.commit_id ?? undefined, hash: (_a = timelineEvent.commit_id) !== null && _a !== void 0 ? _a : undefined,
timestamp: +new Date(timelineEvent.created_at), timestamp: +new Date(timelineEvent.created_at),
}; };
} }

View File

@@ -7,15 +7,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.TestbedIssue = exports.Testbed = void 0; exports.TestbedIssue = exports.Testbed = void 0;
class Testbed { class Testbed {
constructor(config) { constructor(config) {
var _a, _b, _c, _d, _e;
this.config = { this.config = {
globalLabels: config?.globalLabels ?? [], globalLabels: (_a = config === null || config === void 0 ? void 0 : config.globalLabels) !== null && _a !== void 0 ? _a : [],
configs: config?.configs ?? {}, configs: (_b = config === null || config === void 0 ? void 0 : config.configs) !== null && _b !== void 0 ? _b : {},
writers: config?.writers ?? [], writers: (_c = config === null || config === void 0 ? void 0 : config.writers) !== null && _c !== void 0 ? _c : [],
releasedCommits: config?.releasedCommits ?? [], releasedCommits: (_d = config === null || config === void 0 ? void 0 : config.releasedCommits) !== null && _d !== void 0 ? _d : [],
queryRunner: config?.queryRunner ?? queryRunner: (_e = config === null || config === void 0 ? void 0 : config.queryRunner) !== null && _e !== void 0 ? _e : async function* () {
async function* () { yield [];
yield []; },
},
}; };
} }
async *query(query) { async *query(query) {
@@ -48,15 +48,16 @@ class Testbed {
exports.Testbed = Testbed; exports.Testbed = Testbed;
class TestbedIssue extends Testbed { class TestbedIssue extends Testbed {
constructor(globalConfig, issueConfig) { constructor(globalConfig, issueConfig) {
var _a, _b, _c;
super(globalConfig); super(globalConfig);
issueConfig = issueConfig ?? {}; issueConfig = issueConfig !== null && issueConfig !== void 0 ? issueConfig : {};
issueConfig.comments = issueConfig?.comments ?? []; issueConfig.comments = (_a = issueConfig === null || issueConfig === void 0 ? void 0 : issueConfig.comments) !== null && _a !== void 0 ? _a : [];
issueConfig.labels = issueConfig?.labels ?? []; issueConfig.labels = (_b = issueConfig === null || issueConfig === void 0 ? void 0 : issueConfig.labels) !== null && _b !== void 0 ? _b : [];
issueConfig.issue = { issueConfig.issue = {
author: { name: 'JacksonKearl' }, author: { name: 'JacksonKearl' },
body: 'issue body', body: 'issue body',
locked: false, locked: false,
numComments: issueConfig?.comments?.length || 0, numComments: ((_c = issueConfig === null || issueConfig === void 0 ? void 0 : issueConfig.comments) === null || _c === void 0 ? void 0 : _c.length) || 0,
number: 1, number: 1,
open: true, open: true,
title: 'issue title', title: 'issue title',
@@ -90,7 +91,7 @@ class TestbedIssue extends Testbed {
} }
async postComment(body, author) { async postComment(body, author) {
this.issueConfig.comments.push({ this.issueConfig.comments.push({
author: { name: author ?? 'bot' }, author: { name: author !== null && author !== void 0 ? author : 'bot' },
body, body,
id: Math.random(), id: Math.random(),
timestamp: +new Date(), timestamp: +new Date(),

View File

@@ -8,15 +8,15 @@ const core = require("@actions/core");
const github_1 = require("@actions/github"); const github_1 = require("@actions/github");
const octokit_1 = require("../api/octokit"); const octokit_1 = require("../api/octokit");
const utils_1 = require("../utils/utils"); const utils_1 = require("../utils/utils");
const token = (0, utils_1.getRequiredInput)('token'); const token = utils_1.getRequiredInput('token');
const label = (0, utils_1.getRequiredInput)('label'); const label = utils_1.getRequiredInput('label');
async function main() { async function main() {
const pr = new octokit_1.OctoKitIssue(token, github_1.context.repo, { number: github_1.context.issue.number }); const pr = new octokit_1.OctoKitIssue(token, github_1.context.repo, { number: github_1.context.issue.number });
pr.addLabel(label); pr.addLabel(label);
} }
main() main()
.then(() => (0, utils_1.logRateLimit)(token)) .then(() => utils_1.logRateLimit(token))
.catch(async (error) => { .catch(async (error) => {
core.setFailed(error.message); core.setFailed(error.message);
await (0, utils_1.logErrorToIssue)(error.message, true, token); await utils_1.logErrorToIssue(error.message, true, token);
}); });

View File

@@ -9,11 +9,9 @@ const core = require("@actions/core");
const github_1 = require("@actions/github"); const github_1 = require("@actions/github");
const axios_1 = require("axios"); const axios_1 = require("axios");
const octokit_1 = require("../api/octokit"); const octokit_1 = require("../api/octokit");
const getInput = (name) => core.getInput(name) || undefined; exports.getInput = (name) => core.getInput(name) || undefined;
exports.getInput = getInput; exports.getRequiredInput = (name) => core.getInput(name, { required: true });
const getRequiredInput = (name) => core.getInput(name, { required: true }); exports.normalizeIssue = (issue) => {
exports.getRequiredInput = getRequiredInput;
const normalizeIssue = (issue) => {
const { body, title } = issue; const { body, title } = issue;
const isBug = body.includes('bug_report_template') || /Issue Type:.*Bug.*/.test(body); const isBug = body.includes('bug_report_template') || /Issue Type:.*Bug.*/.test(body);
const isFeatureRequest = body.includes('feature_request_template') || /Issue Type:.*Feature Request.*/.test(body); const isFeatureRequest = body.includes('feature_request_template') || /Issue Type:.*Feature Request.*/.test(body);
@@ -36,25 +34,20 @@ const normalizeIssue = (issue) => {
issueType: isBug ? 'bug' : isFeatureRequest ? 'feature_request' : 'unknown', issueType: isBug ? 'bug' : isFeatureRequest ? 'feature_request' : 'unknown',
}; };
}; };
exports.normalizeIssue = normalizeIssue; exports.loadLatestRelease = async (quality) => (await axios_1.default.get(`https://vscode-update.azurewebsites.net/api/update/darwin/${quality}/latest`)).data;
const loadLatestRelease = async (quality) => (await axios_1.default.get(`https://vscode-update.azurewebsites.net/api/update/darwin/${quality}/latest`)).data; exports.daysAgoToTimestamp = (days) => +new Date(Date.now() - days * 24 * 60 * 60 * 1000);
exports.loadLatestRelease = loadLatestRelease; exports.daysAgoToHumanReadbleDate = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString().replace(/\.\d{3}\w$/, '');
const daysAgoToTimestamp = (days) => +new Date(Date.now() - days * 24 * 60 * 60 * 1000); exports.logRateLimit = async (token) => {
exports.daysAgoToTimestamp = daysAgoToTimestamp;
const daysAgoToHumanReadbleDate = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString().replace(/\.\d{3}\w$/, '');
exports.daysAgoToHumanReadbleDate = daysAgoToHumanReadbleDate;
const logRateLimit = async (token) => {
const usageData = (await new github_1.GitHub(token).rateLimit.get()).data.resources; const usageData = (await new github_1.GitHub(token).rateLimit.get()).data.resources;
['core', 'graphql', 'search'].forEach(async (category) => { ['core', 'graphql', 'search'].forEach(async (category) => {
const usage = 1 - usageData[category].remaining / usageData[category].limit; const usage = 1 - usageData[category].remaining / usageData[category].limit;
const message = `Usage at ${usage} for ${category}`; const message = `Usage at ${usage} for ${category}`;
if (usage > 0.5) { if (usage > 0.5) {
await (0, exports.logErrorToIssue)(message, false, token); await exports.logErrorToIssue(message, false, token);
} }
}); });
}; };
exports.logRateLimit = logRateLimit; exports.logErrorToIssue = async (message, ping, token) => {
const logErrorToIssue = async (message, ping, token) => {
// Attempt to wait out abuse detection timeout if present // Attempt to wait out abuse detection timeout if present
await new Promise((resolve) => setTimeout(resolve, 10000)); await new Promise((resolve) => setTimeout(resolve, 10000));
const dest = github_1.context.repo.repo === 'vscode-internalbacklog' const dest = github_1.context.repo.repo === 'vscode-internalbacklog'
@@ -75,4 +68,3 @@ ${JSON.stringify(github_1.context, null, 2).replace(/<!--/gu, '<@--').replace(/-
--> -->
`); `);
}; };
exports.logErrorToIssue = logErrorToIssue;