Skip to content

Commit

Permalink
build: switch to ESLint from TSLint (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored Jul 26, 2023
1 parent cfbef6a commit d03bcb8
Show file tree
Hide file tree
Showing 6 changed files with 1,162 additions and 159 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"env": {
"es2021": true
},
"extends": "standard-with-typescript",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"@types/node-fetch": "^2.5.4",
"@types/pino-std-serializers": "^4.0.0",
"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^36.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^6.0.0",
"jest": "^29.0.0",
"lint-staged": "^10.4.2",
Expand All @@ -41,9 +47,7 @@
"sinon": "^15.2.0",
"smee-client": "^1.2.3",
"ts-jest": "^29.0.0",
"tslint": "^5.20.1",
"tslint-config-airbnb": "^5.11.2",
"typescript": "^4.8.4"
"typescript": "*"
},
"lint-staged": {
"{src,spec}/**/*.ts": "prettier --write **/*.ts"
Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationFunction, Context } from 'probot';
import { ApplicationFunction } from 'probot';

import {
backportImpl,
Expand Down Expand Up @@ -28,7 +28,12 @@ import {
updateBackportValidityCheck,
} from './utils/checks-util';
import { register } from './utils/prom';
import { SimpleWebHookRepoContext, WebHookPR, WebHookPRContext } from './types';
import {
SimpleWebHookRepoContext,
WebHookIssueContext,
WebHookPR,
WebHookPRContext,
} from './types';

// Built in fetch doesn't support global-agent...
// @ts-ignore
Expand Down Expand Up @@ -446,8 +451,9 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
);

// Backport pull requests to labeled targets when PR is merged.
robot.on('pull_request.closed', async (context) => {
const pr = context.payload.pull_request;
robot.on('pull_request.closed', async (context: WebHookPRContext) => {
const { pull_request: pr } = context.payload;

const oldPRNumbers = getPRNumbersFromPRBody(pr, true);
if (pr.merged) {
if (oldPRNumbers.length > 0) {
Expand Down Expand Up @@ -493,7 +499,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
const TROP_COMMAND_PREFIX = '/trop ';

// Manually trigger backporting process on trigger comment phrase.
robot.on('issue_comment.created', async (context) => {
robot.on('issue_comment.created', async (context: WebHookIssueContext) => {
const { issue, comment } = context.payload;

const isPullRequest = (i: { number: number; html_url: string }) =>
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ export type WebHookPRContext = Context<
| 'pull_request.labeled'
| 'pull_request.unlabeled'
>;

export type WebHookIssueContext = Context<'issue_comment.created'>;

export type SimpleWebHookRepoContext = Pick<
WebHookRepoContext,
'octokit' | 'repo' | 'payload'
>;

export type WebHookRepoContext = Omit<WebHookPRContext, 'payload'> & {
payload: Omit<
WebHookPRContext['payload'],
'pull_request' | 'number' | 'action'
>;
};

export type WebHookPR = WebHookPRContext['payload']['pull_request'];

export type WebHookIssueComment = WebHookIssueContext['payload']['comment'];
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { TryBackportOptions } from './interfaces';
import { client, register } from './utils/prom';
import {
SimpleWebHookRepoContext,
WebHookIssueContext,
WebHookPR,
WebHookRepoContext,
} from './types';
Expand Down Expand Up @@ -251,7 +252,7 @@ const tryBackportSquashCommit = async (opts: TryBackportOptions) => {
};

export const isAuthorizedUser = async (
context: Context<'issue_comment'>,
context: WebHookIssueContext,
username: string,
) => {
const { data } = await context.octokit.repos.getCollaboratorPermissionLevel(
Expand Down
Loading

0 comments on commit d03bcb8

Please sign in to comment.