Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing CI #366

Merged
merged 4 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js 16.x
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- name: Set up Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
- name: Install dependencies
run: yarn install --dev
- name: Lint files
Expand All @@ -18,4 +18,4 @@ jobs:
env:
CI: true
- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.15.0
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine as builder
FROM node:18-alpine as builder

RUN mkdir -p /opt/autoupdate/dist

Expand All @@ -8,7 +8,7 @@ COPY . /opt/autoupdate/

RUN yarn install --frozen-lockfile && yarn run build

FROM node:16-alpine as runner
FROM node:18-alpine as runner

LABEL com.github.actions.name="Auto-update pull requests with changes from their base branch"
LABEL com.github.actions.description="A GitHub Action that auto-updates PRs with changes from their base branch"
Expand Down
20 changes: 20 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
"clearMocks": true,
"collectCoverage": true,
"coverageDirectory": "coverage",
"coverageProvider": "v8",
"preset": "ts-jest",
"setupFiles": [
"<rootDir>/test/config.ts"
],
"testEnvironment": "node",
"transform": {
".(ts|tsx)": [
"ts-jest",
{
tsconfig: "tsconfig.tests.json",
compiler: "ttypescript",
}
]
},
}
59 changes: 20 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autoupdate-action",
"version": "1.0.0",
"version": "1.7.0",
"description": "A GitHub Action that auto-updates PRs with changes from their base branch.",
"main": "src/autoupdater.ts",
"repository": "https://github.com/chinthakagodawita/autoupdate",
Expand All @@ -18,48 +18,29 @@
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.0.0",
"@octokit/types": "^6.31.3",
"@octokit/webhooks": "^9.12.0",
"@octokit/webhooks-definitions": "^3.67.3",
"@types/node": "^16.10.2",
"@vercel/ncc": "^0.28.6",
"ttypescript": "^1.5.12",
"typescript": "^4.4.2"
"@actions/github": "^5.1.1",
"@octokit/types": "^9.0.0",
"@octokit/webhooks": "^10.7.0",
"@octokit/webhooks-types": "^6.10.0",
"@types/node": "^18.15.10",
"@vercel/ncc": "^0.36.1",
"ttypescript": "^1.5.15",
"typescript": "^4.9.5"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.3.6",
"@types/jest": "^29.5.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"jest-ts-auto-mock": "^2.0.0",
"jest": "^29.5.0",
"jest-ts-auto-mock": "^2.1.0",
"nock": "^13.1.3",
"prettier": "^2.3.2",
"ts-auto-mock": "^3.5.0",
"ts-jest": "^26.5.6"
},
"jest": {
"clearMocks": true,
"collectCoverage": true,
"coverageDirectory": "coverage",
"coverageProvider": "v8",
"globals": {
"ts-jest": {
"compiler": "ttypescript"
}
},
"preset": "ts-jest",
"setupFiles": [
"<rootDir>/test/config.ts"
],
"testEnvironment": "node",
"transform": {
".(ts|tsx)": "ts-jest"
}
"ts-auto-mock": "^3.6.4",
"ts-jest": "^29.0.5"
}
}
11 changes: 5 additions & 6 deletions src/autoupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
WebhookEvent,
WorkflowRunEvent,
WorkflowDispatchEvent,
} from '@octokit/webhooks-definitions/schema';
} from '@octokit/webhooks-types/schema';
import { ConfigLoader } from './config-loader';
import { Output } from './Output';
import { isRequestError } from './helpers/isRequestError';

type PullRequestResponse =
octokit.Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response'];
Expand Down Expand Up @@ -463,14 +464,12 @@ export class AutoUpdater {
* probably because we don't have access to it.
*/
if (
'status' in e &&
(e as octokit.RequestError).status === 403 &&
isRequestError(e) &&
e.status === 403 &&
sourceEventOwner !== mergeOpts.owner
) {
const error = e as Error;

ghCore.error(
`Could not update pull request #${prNumber} due to an authorisation error. This is probably because this pull request is from a fork and the current token does not have write access to the forked repository. Error was: ${error.message}`,
`Could not update pull request #${prNumber} due to an authorisation error. This is probably because this pull request is from a fork and the current token does not have write access to the forked repository. Error was: ${e.message}`,
);

setOutputFn(Output.Conflicted, false);
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/isRequestError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* For some reason, an `instanceof` check doesn't work with Octokit's `RequestError`.
* This typeguard provides similar functionality, since realistically all
* we care about is `status`.
*/
export function isRequestError(
error: Error,
): error is Error & { status: number } {
return 'status' in error;
}
2 changes: 1 addition & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebhookEvent } from '@octokit/webhooks-definitions/schema';
import { WebhookEvent } from '@octokit/webhooks-types';
import { AutoUpdater } from '../src/autoupdater';
import { ConfigLoader } from '../src/config-loader';

Expand Down
2 changes: 1 addition & 1 deletion test/autoupdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
WebhookEvent,
WorkflowDispatchEvent,
WorkflowRunEvent,
} from '@octokit/webhooks-definitions/schema';
} from '@octokit/webhooks-types/schema';

type PullRequestResponse =
Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response'];
Expand Down
19 changes: 19 additions & 0 deletions test/helpers/isRequestError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isRequestError } from '../../src/helpers/isRequestError';

describe('isRequestError', () => {
class MockRequestError extends Error {
constructor(public readonly status: number) {
super();
}
}

it('should return true if a request error with a status is provided', () => {
const error = new MockRequestError(403);
expect(isRequestError(error)).toBe(true);
});

it('should return false if a non-request error is provided', () => {
const error = new Error('not a request error');
expect(isRequestError(error)).toBe(false);
});
});
2 changes: 1 addition & 1 deletion test/router.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from '../src/config-loader';
import { AutoUpdater } from '../src/autoupdater';
import { Router } from '../src/router';
import { WebhookEvent } from '@octokit/webhooks-definitions/schema';
import { WebhookEvent } from '@octokit/webhooks-types/schema';

jest.mock('../src/config-loader');
jest.mock('../src/autoupdater');
Expand Down
13 changes: 2 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"*": ["src/*", "bin/*"]
},
"plugins": [
{
"transform": "ts-auto-mock/transformer",
"cacheBetweenTests": false
},
]
"rootDir": "."
},
"include": ["src/**/*"],
"include": ["src/**/*", "bin/**/*"],
"exclude": ["**/*.test.ts"]
}
12 changes: 12 additions & 0 deletions tsconfig.tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"plugins": [
{
"transform": "ts-auto-mock/transformer",
"cacheBetweenTests": false
},
]
},
"exclude": ["node_modules"]
}
Loading