Skip to content

Commit

Permalink
Merge pull request #2 from BondOrigination/lewis-update-fork-2
Browse files Browse the repository at this point in the history
Update fork
  • Loading branch information
lewis-jackson-bots authored Jul 10, 2024
2 parents 88aa487 + 974645f commit 4766cb2
Show file tree
Hide file tree
Showing 15 changed files with 2,010 additions and 3,055 deletions.
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ on:
jobs:
autoupdate:
name: autoupdate
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: docker://chinthakagodawita/autoupdate-action:v1
env:
Expand Down Expand Up @@ -154,7 +154,7 @@ Here's a screenshot:
- Branch updates events caused by this action will not trigger any subsequent workflows
- [This is a documented limitation](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#about-workflow-events) for all GH actions:
> An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
- There is [an open issue in the Github community forum](https://github.community/t5/GitHub-Actions/Triggering-a-new-workflow-from-another-workflow/td-p/31676) tracking this
- There is [an open issue in the Github community forum](https://github.com/orgs/community/discussions/43427) tracking this

## Coming soon

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",
}
]
},
}
65 changes: 23 additions & 42 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 @@ -17,49 +17,30 @@
"test:watch": "jest --watchAll"
},
"dependencies": {
"@actions/core": "^1.5.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/core": "^1.10.0",
"@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",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"jest-ts-auto-mock": "^2.0.0",
"@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": "^4.2.1",
"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"
}
"prettier": "^2.8.7",
"ts-auto-mock": "^3.6.4",
"ts-jest": "^29.0.5"
}
}
21 changes: 11 additions & 10 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 @@ -243,7 +244,11 @@ export class AutoUpdater {
}

const mergeComment = this.config.mergeComment();
if (mergeComment !== null && mergeComment.length > 0) {
if (
mergeComment !== null &&
mergeComment !== undefined &&
mergeComment.length > 0
) {
await this.octokit.rest.issues.createComment({
owner: pull.head.repo.owner.login,
issue_number: pull.number,
Expand Down Expand Up @@ -476,24 +481,20 @@ 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);

return false;
}

if (
'status' in e &&
(e as octokit.RequestError).status === 404) {
if (isRequestError(e) && e.status === 404) {
const error = e as Error;

ghCore.error(
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

0 comments on commit 4766cb2

Please sign in to comment.