Skip to content

Commit

Permalink
remove context functions input
Browse files Browse the repository at this point in the history
  • Loading branch information
upalatucci committed Feb 14, 2022
1 parent f5f5443 commit a0a1288
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
19 changes: 9 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
var _a, _b;
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(6241));
const github_1 = __importDefault(__nccwpck_require__(1338));
const github = __importStar(__nccwpck_require__(1338));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const js_yaml_1 = __importDefault(__nccwpck_require__(72));
function pickRandomReviewers(context, allReviewers, numberReviewers) {
function pickRandomReviewers(allReviewers, numberReviewers) {
var _a;
const author = (_a = context.payload.sender) === null || _a === void 0 ? void 0 : _a.login;
const author = (_a = github.context.payload.sender) === null || _a === void 0 ? void 0 : _a.login;
console.log("selecting random reviewers excluding", author);
const shuffled = [...allReviewers]
.filter((reviewers) => reviewers !== author)
Expand All @@ -56,14 +56,14 @@ function pickRandomReviewers(context, allReviewers, numberReviewers) {
core.setOutput("random-reviewers", randomReviewers);
return randomReviewers;
}
function addReviewers(context, prNumber, reviewers) {
function addReviewers(prNumber, reviewers) {
return __awaiter(this, void 0, void 0, function* () {
const token = process.env["GITHUB_TOKEN"] || core.getInput("token");
if (!token) {
console.log("token not specified");
}
const client = github_1.default.getOctokit(token);
yield client.rest.pulls.requestReviewers(Object.assign(Object.assign({}, context.repo), { pull_number: prNumber, reviewers }));
const client = github.getOctokit(token);
yield client.rest.pulls.requestReviewers(Object.assign(Object.assign({}, github.context.repo), { pull_number: prNumber, reviewers }));
});
}
try {
Expand All @@ -78,11 +78,10 @@ try {
core.setOutput("approvers", owners.approvers);
core.setOutput("reviewers", owners.reviewers);
if (numberReviewers) {
const context = github_1.default.context;
const selectedReviewers = pickRandomReviewers(context, owners.reviewers, parseInt(numberReviewers, 10));
const selectedReviewers = pickRandomReviewers(owners.reviewers, parseInt(numberReviewers, 10));
if (autoAddReviewers &&
((_a = context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) !== undefined) {
addReviewers(context, (_b = context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number, selectedReviewers).then(() => console.log("Successfully added reviewers"));
((_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) !== undefined) {
addReviewers((_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number, selectedReviewers).then(() => console.log("Successfully added reviewers"));
}
console.log("End");
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"build": "tsc && ncc build --source-map",
"package": "ncc build --source-map --license licenses.txt",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
17 changes: 7 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as core from '@actions/core'
import github from "@actions/github"
import * as github from '@actions/github'
import path from "path"
import fs from "fs"
import yaml from "js-yaml"
import { Context } from "@actions/github/lib/context";

function pickRandomReviewers(context: Context, allReviewers: string[], numberReviewers: number) {
const author = context.payload.sender?.login;
function pickRandomReviewers(allReviewers: string[], numberReviewers: number) {
const author = github.context.payload.sender?.login;

console.log("selecting random reviewers excluding", author);

Expand All @@ -22,7 +21,7 @@ function pickRandomReviewers(context: Context, allReviewers: string[], numberRev
return randomReviewers;
}

async function addReviewers(context: Context, prNumber: number, reviewers: string[]) {
async function addReviewers(prNumber: number, reviewers: string[]) {
const token = process.env["GITHUB_TOKEN"] || core.getInput("token");

if (!token) {
Expand All @@ -32,7 +31,7 @@ async function addReviewers(context: Context, prNumber: number, reviewers: strin
const client = github.getOctokit(token);

await client.rest.pulls.requestReviewers({
...context.repo,
...github.context.repo,
pull_number: prNumber,
reviewers,
});
Expand All @@ -59,19 +58,17 @@ try {
core.setOutput("reviewers", owners.reviewers);

if (numberReviewers) {
const context = github.context;

const selectedReviewers = pickRandomReviewers(
context,
owners.reviewers,
parseInt(numberReviewers, 10)
);

if (
autoAddReviewers &&
context.payload.pull_request?.number !== undefined
github.context.payload.pull_request?.number !== undefined
) {
addReviewers(context, context.payload.pull_request?.number, selectedReviewers).then(() =>
addReviewers(github.context.payload.pull_request?.number, selectedReviewers).then(() =>
console.log("Successfully added reviewers")
);
}
Expand Down

0 comments on commit a0a1288

Please sign in to comment.