Skip to content

Commit

Permalink
Use Node.js 20 (#2)
Browse files Browse the repository at this point in the history
* Use Node.js 20

* Use node20

* Apply Prettier formats
  • Loading branch information
LitoMore committed Mar 13, 2024
1 parent 5276be7 commit 6273151
Show file tree
Hide file tree
Showing 12 changed files with 1,703 additions and 7,712 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Setup node 14
uses: actions/setup-node@v2
- uses: actions/checkout@v4
- name: Setup node 20
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 20.x
- run: npm install
- run: npm run build
- run: npm test
4 changes: 2 additions & 2 deletions .github/workflows/licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest
name: Check licenses
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npm ci
- name: Install licensed
run: |
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status
- run: licensed status
2 changes: 1 addition & 1 deletion .licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ allowed:
- unlicense

reviewed:
npm:
npm:
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
4 changes: 2 additions & 2 deletions __mocks__/@actions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const context = {
},
},
repo: {
owner: "monalisa",
repo: "helloworld",
owner: 'monalisa',
repo: 'helloworld',
},
};

Expand Down
28 changes: 14 additions & 14 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { checkGlobs } from "../src/labeler";
import { checkGlobs } from '../src/labeler';

import * as core from "@actions/core";
import * as core from '@actions/core';

jest.mock("@actions/core");
jest.mock('@actions/core');

beforeAll(() => {
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
return jest.requireActual("@actions/core").getInput(name, options);
jest.spyOn(core, 'getInput').mockImplementation((name, options) => {
return jest.requireActual('@actions/core').getInput(name, options);
});
});

const matchConfig = [{ any: ["*.txt"], status: ["added", "modified"] }];
const matchConfig = [{ any: ['*.txt'], status: ['added', 'modified'] }];

describe("checkGlobs", () => {
it("returns true when our pattern does match changed files & status", () => {
describe('checkGlobs', () => {
it('returns true when our pattern does match changed files & status', () => {
const changedFiles = [
{ filename: "foo.txt", status: "modified" },
{ filename: "bar.txt", status: "modified" },
{ filename: 'foo.txt', status: 'modified' },
{ filename: 'bar.txt', status: 'modified' },
];
const result = checkGlobs(changedFiles, matchConfig);

expect(result).toBeTruthy();
});

it("returns false when our pattern does not match changed files", () => {
const changedFiles = [{ filename: "foo.docx", status: "modified" }];
it('returns false when our pattern does not match changed files', () => {
const changedFiles = [{ filename: 'foo.docx', status: 'modified' }];
const result = checkGlobs(changedFiles, matchConfig);

expect(result).toBeFalsy();
});

it("returns false when our pattern does not match changed files status", () => {
const changedFiles = [{ filename: "foo.docx", status: "removed" }];
it('returns false when our pattern does not match changed files status', () => {
const changedFiles = [{ filename: 'foo.docx', status: 'removed' }];
const result = checkGlobs(changedFiles, matchConfig);

expect(result).toBeFalsy();
Expand Down
88 changes: 44 additions & 44 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import { run } from "../src/labeler";
import { GitHub } from "@actions/github";
import * as core from "@actions/core";
import { run } from '../src/labeler';
import { GitHub } from '@actions/github';
import * as core from '@actions/core';

const fs = jest.requireActual("fs");
const fs = jest.requireActual('fs');

jest.mock("@actions/core");
jest.mock("@actions/github");
jest.mock('@actions/core');
jest.mock('@actions/github');

const gh = new GitHub("_");
const addLabelsMock = jest.spyOn(gh.issues, "addLabels");
const removeLabelMock = jest.spyOn(gh.issues, "removeLabel");
const reposMock = jest.spyOn(gh.repos, "getContents");
const paginateMock = jest.spyOn(gh, "paginate");
const getPullMock = jest.spyOn(gh.pulls, "get");
const gh = new GitHub('_');
const addLabelsMock = jest.spyOn(gh.issues, 'addLabels');
const removeLabelMock = jest.spyOn(gh.issues, 'removeLabel');
const reposMock = jest.spyOn(gh.repos, 'getContents');
const paginateMock = jest.spyOn(gh, 'paginate');
const getPullMock = jest.spyOn(gh.pulls, 'get');

const yamlFixtures = {
"only_pdfs.yml": fs.readFileSync("__tests__/fixtures/only_pdfs.yml"),
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml'),
};

afterAll(() => jest.restoreAllMocks());

describe("run", () => {
it("adds labels to PRs that match our glob patterns", async () => {
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.pdf");
describe('run', () => {
it('adds labels to PRs that match our glob patterns', async () => {
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.pdf');

await run();

expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(1);
expect(addLabelsMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
owner: 'monalisa',
repo: 'helloworld',
issue_number: 123,
labels: ["touched-a-pdf-file"],
labels: ['touched-a-pdf-file'],
});
});

it("does not add labels to PRs that do not match our glob patterns", async () => {
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
it('does not add labels to PRs that do not match our glob patterns', async () => {
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');

await run();

expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(0);
});

it("(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern", async () => {
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": true,
'repo-token': 'foo',
'configuration-path': 'bar',
'sync-labels': true,
};

jest
.spyOn(core, "getInput")
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);

usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');
getPullMock.mockResolvedValue(<any>{
data: {
labels: [{ name: "touched-a-pdf-file" }],
labels: [{ name: 'touched-a-pdf-file' }],
},
});

Expand All @@ -71,29 +71,29 @@ describe("run", () => {
expect(addLabelsMock).toHaveBeenCalledTimes(0);
expect(removeLabelMock).toHaveBeenCalledTimes(1);
expect(removeLabelMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
owner: 'monalisa',
repo: 'helloworld',
issue_number: 123,
name: "touched-a-pdf-file",
name: 'touched-a-pdf-file',
});
});

it("(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern", async () => {
it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": false,
'repo-token': 'foo',
'configuration-path': 'bar',
'sync-labels': false,
};

jest
.spyOn(core, "getInput")
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);

usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');
getPullMock.mockResolvedValue(<any>{
data: {
labels: [{ name: "touched-a-pdf-file" }],
labels: [{ name: 'touched-a-pdf-file' }],
},
});

Expand All @@ -106,11 +106,11 @@ describe("run", () => {

function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
reposMock.mockResolvedValue(<any>{
data: { content: yamlFixtures[fixtureName], encoding: "utf8" },
data: { content: yamlFixtures[fixtureName], encoding: 'utf8' },
});
}

function mockGitHubResponseChangedFiles(...files: string[]): void {
const returnValue = files.map((f) => ({ filename: f, status: "modified" }));
const returnValue = files.map((f) => ({ filename: f, status: 'modified' }));
paginateMock.mockReturnValue(<any>returnValue);
}
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ inputs:
required: false

runs:
using: 'node12'
using: 'node20'
main: 'dist/index.js'
Loading

0 comments on commit 6273151

Please sign in to comment.