Compare commits

...

2 Commits

Author SHA1 Message Date
Ross Brodbeck
1e5e734da7 Update to latest actions and octokit libraries (#124)
Upgrade to latest libraries but use "any" for the client until I figure out how to use the right type
2020-07-24 08:44:53 -04:00
Ross Brodbeck
5420e6bbac Update eslint config to latest (#123) 2020-07-24 08:17:50 -04:00
5 changed files with 1810 additions and 21767 deletions

View File

@@ -1,6 +1,6 @@
{ {
"plugins": ["jest", "@typescript-eslint"], "plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"], "extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"ecmaVersion": 9, "ecmaVersion": 9,
@@ -16,11 +16,10 @@
"@typescript-eslint/no-require-imports": "error", "@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error", "@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error", "@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error", "@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off", "camelcase": "off",
"@typescript-eslint/class-name-casing": "error", "@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/func-call-spacing": ["error", "never"], "@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error", "@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error", "@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
@@ -30,7 +29,6 @@
"@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error", "@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn", "@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-object-literal-type-assertion": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error", "@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error", "@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error", "@typescript-eslint/no-useless-constructor": "error",
@@ -38,7 +36,6 @@
"@typescript-eslint/prefer-for-of": "warn", "@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn", "@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error", "@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error", "@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error", "@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error", "@typescript-eslint/require-array-sort-compare": "error",

22651
dist/index.js vendored

File diff suppressed because it is too large Load Diff

856
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -26,8 +26,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.4", "@actions/core": "^1.2.4",
"@actions/github": "^2.2.0", "@actions/github": "^4.0.0",
"@octokit/rest": "^16.43.1", "@octokit/rest": "^18.0.2",
"semver": "^7.3.2" "semver": "^7.3.2"
}, },
"devDependencies": { "devDependencies": {
@@ -37,7 +37,7 @@
"@typescript-eslint/parser": "^3.7.0", "@typescript-eslint/parser": "^3.7.0",
"@zeit/ncc": "^0.20.5", "@zeit/ncc": "^0.20.5",
"eslint": "^5.16.0", "eslint": "^5.16.0",
"eslint-plugin-github": "^2.0.0", "eslint-plugin-github": "^4.0.1",
"eslint-plugin-jest": "^23.18.0", "eslint-plugin-jest": "^23.18.0",
"jest": "^24.9.0", "jest": "^24.9.0",
"jest-circus": "^26.1.0", "jest-circus": "^26.1.0",

View File

@@ -1,8 +1,6 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as github from '@actions/github'; import {context, getOctokit} from '@actions/github';
import {Octokit} from '@octokit/rest'; import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
type OctoKitIssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
export interface Issue { export interface Issue {
title: string; title: string;
@@ -58,9 +56,9 @@ export interface IssueProcessorOptions {
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
*/ */
export class IssueProcessor { export class IssueProcessor {
readonly client: github.GitHub; readonly client: any; // need to make this the correct type
readonly options: IssueProcessorOptions; readonly options: IssueProcessorOptions;
private operationsLeft: number = 0; private operationsLeft = 0;
readonly staleIssues: Issue[] = []; readonly staleIssues: Issue[] = [];
readonly closedIssues: Issue[] = []; readonly closedIssues: Issue[] = [];
@@ -80,7 +78,7 @@ export class IssueProcessor {
) { ) {
this.options = options; this.options = options;
this.operationsLeft = options.operationsPerRun; this.operationsLeft = options.operationsPerRun;
this.client = new github.GitHub(options.repoToken); this.client = getOctokit(options.repoToken);
if (getIssues) { if (getIssues) {
this.getIssues = getIssues; this.getIssues = getIssues;
@@ -101,7 +99,7 @@ export class IssueProcessor {
} }
} }
async processIssues(page: number = 1): Promise<number> { async processIssues(page = 1): Promise<number> {
// get the next batch of issues // get the next batch of issues
const issues: Issue[] = await this.getIssues(page); const issues: Issue[] = await this.getIssues(page);
this.operationsLeft -= 1; this.operationsLeft -= 1;
@@ -268,12 +266,11 @@ export class IssueProcessor {
const filteredComments = comments.filter( const filteredComments = comments.filter(
comment => comment =>
comment.user.type === 'User' && comment.user.type === 'User' && comment.user.login !== context.actor
comment.user.login !== github.context.actor
); );
core.info( core.info(
`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}` `Comments not made by ${context.actor} or another bot: ${filteredComments.length}`
); );
// if there are any user comments returned // if there are any user comments returned
@@ -288,8 +285,8 @@ export class IssueProcessor {
// find any comments since date on the given issue // find any comments since date on the given issue
try { try {
const comments = await this.client.issues.listComments({ const comments = await this.client.issues.listComments({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issueNumber, issue_number: issueNumber,
since: sinceDate since: sinceDate
}); });
@@ -302,11 +299,15 @@ export class IssueProcessor {
// grab issues from github in baches of 100 // grab issues from github in baches of 100
private async getIssues(page: number): Promise<Issue[]> { private async getIssues(page: number): Promise<Issue[]> {
// generate type for response
const endpoint = this.client.issues.listForRepo;
type OctoKitIssueList = GetResponseTypeFromEndpointMethod<typeof endpoint>;
try { try {
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo( const issueResult: OctoKitIssueList = await this.client.issues.listForRepo(
{ {
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
state: 'open', state: 'open',
labels: this.options.onlyLabels, labels: this.options.onlyLabels,
per_page: 100, per_page: 100,
@@ -346,8 +347,8 @@ export class IssueProcessor {
if (!skipMessage) { if (!skipMessage) {
try { try {
await this.client.issues.createComment({ await this.client.issues.createComment({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
body: staleMessage body: staleMessage
}); });
@@ -358,8 +359,8 @@ export class IssueProcessor {
try { try {
await this.client.issues.addLabels({ await this.client.issues.addLabels({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
labels: [staleLabel] labels: [staleLabel]
}); });
@@ -385,8 +386,8 @@ export class IssueProcessor {
if (closeMessage) { if (closeMessage) {
try { try {
await this.client.issues.createComment({ await this.client.issues.createComment({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
body: closeMessage body: closeMessage
}); });
@@ -397,8 +398,8 @@ export class IssueProcessor {
try { try {
await this.client.issues.update({ await this.client.issues.update({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
state: 'closed' state: 'closed'
}); });
@@ -423,8 +424,8 @@ export class IssueProcessor {
try { try {
await this.client.issues.removeLabel({ await this.client.issues.removeLabel({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
name: encodeURIComponent(label) // A label can have a "?" in the name name: encodeURIComponent(label) // A label can have a "?" in the name
}); });
@@ -444,8 +445,8 @@ export class IssueProcessor {
this.operationsLeft -= 1; this.operationsLeft -= 1;
const options = this.client.issues.listEvents.endpoint.merge({ const options = this.client.issues.listEvents.endpoint.merge({
owner: github.context.repo.owner, owner: context.repo.owner,
repo: github.context.repo.repo, repo: context.repo.repo,
per_page: 100, per_page: 100,
issue_number: issue.number issue_number: issue.number
}); });