Skip to content

Commit

Permalink
Implemented linting (#10)
Browse files Browse the repository at this point in the history
Implemented
[`@eng-automation/js-style`](https://github.com/paritytech/opstooling-js-style)
with the linting method.

Created CI step for it to be tested.

Closes #4
  • Loading branch information
Bullrich authored Jul 14, 2023
1 parent 0175c47 commit 8cb2bfa
Show file tree
Hide file tree
Showing 10 changed files with 2,317 additions and 210 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {
getConfiguration,
getTypescriptOverride,
} = require("@eng-automation/js-style/src/eslint/configuration");

const tsConfParams = { rootDir: __dirname };

const conf = getConfiguration({ typescript: tsConfParams });

const tsConfOverride = getTypescriptOverride(tsConfParams);

module.exports = {
...conf,
overrides: [
...conf.overrides,
{
...tsConfOverride,
rules: {
...tsConfOverride.rules,
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
},
},
],
};
10 changes: 9 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ jobs:
- name: Check that the image builds
run: docker build . --file Dockerfile

test-code:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn build

test-versions:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -44,7 +52,7 @@ jobs:

tag:
if: github.event_name == 'push'
needs: [test-image, test-versions]
needs: [test-image, test-versions, test-code]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@eng-automation/js-style/src/prettier/configuration")
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"description": "GitHub action that finds stale PRs and produce an output with them",
"main": "src/index.ts",
"scripts": {
"build": "ncc build"
"build": "ncc build",
"typecheck": "tsc --noEmit",
"lint": "yarn eslint --quiet '{*,**/*}.{js,ts}' && yarn prettier --check '{*,**/*}.json'",
"fix:eslint": "eslint --fix",
"fix:prettier": "prettier --write",
"fix": "yarn fix:eslint '{*,**/*}.{js,ts}' && yarn fix:prettier '{*,**/*}.json'"
},
"repository": {
"type": "git",
Expand All @@ -27,13 +32,13 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@eng-automation/integrations": "^4.0.0",
"@eng-automation/integrations": "^4.1.0",
"moment": "^2.29.4"
},
"devDependencies": {
"@types/moment": "^2.13.0",
"@types/node": "^18.15.11",
"@eng-automation/js-style": "^2.1.0",
"@types/node": "^20.4.2",
"@vercel/ncc": "^0.36.1",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
}
}
16 changes: 7 additions & 9 deletions src/filters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import moment from "moment";

import { PullRequest } from "./types";

export const olderThanDays = (pr: PullRequest, daysStale: number): boolean => {
return moment().diff(moment(pr.updated_at), "days") > daysStale;
}
export const olderThanDays = (pr: PullRequest, daysStale: number): boolean =>
moment().diff(moment(pr.updated_at), "days") > daysStale;

export const byNoReviews = (pr: PullRequest): boolean => {
return !pr.reviews || pr.reviews.length === 0;
}
export const byNoReviews = (pr: PullRequest): boolean => !pr.reviews || pr.reviews.length === 0;

export const byLabels = (pr: PullRequest, labels: string[]): boolean => {
return pr.labels && pr.labels.map(l => l.name.toLowerCase()).some(l => labels.map(l => l.toLowerCase()).includes(l));
}
export const byLabels = (pr: PullRequest, labels: string[]): boolean =>
pr.labels &&
pr.labels.map((l) => l.name.toLowerCase()).some((l) => labels.map((label) => label.toLowerCase()).includes(l));
27 changes: 15 additions & 12 deletions src/githubApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { debug } from "@actions/core";
import { github } from "@eng-automation/integrations";

import { PullRequest, Repo } from "./types";

export const getPullRequestWithReviews = async (octokitInstance: github.GitHubInstance, repo: Repo): Promise<PullRequest[]> => {
const prs = await github.getPullRequests({ state: "open", ...repo }, { octokitInstance });
debug(`Found a total of ${prs.length} PRs`);
export const getPullRequestWithReviews = async (
octokitInstance: github.GitHubInstance,
repo: Repo,
): Promise<PullRequest[]> => {
const prs = await github.getPullRequests({ state: "open", ...repo }, { octokitInstance });
debug(`Found a total of ${prs.length} PRs`);

let reviews: PullRequest[] = [];
for (const pr of prs) {
debug(`Fetching reviews for PR #${pr.number}`);
const { data } = await octokitInstance.rest.pulls.listReviews({ pull_number: pr.number, ...repo });
reviews.push({ ...pr, reviews: data });
}
const reviews: PullRequest[] = [];
for (const pr of prs) {
debug(`Fetching reviews for PR #${pr.number}`);
const { data } = await octokitInstance.rest.pulls.listReviews({ pull_number: pr.number, ...repo });
reviews.push({ ...pr, reviews: data });
}

const sortedPrs = reviews.sort((a, b) => { return b.updated_at > a.updated_at ? -1 : b.updated_at < a.updated_at ? 1 : 0 });
return sortedPrs;
}
return reviews.sort((a, b) => (b.updated_at > a.updated_at ? -1 : b.updated_at < a.updated_at ? 1 : 0));
};
Loading

0 comments on commit 8cb2bfa

Please sign in to comment.