Skip to content

Commit

Permalink
Merge pull request #31 from issue-ops/ncalteen
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
ncalteen authored Nov 1, 2023
2 parents ddbe611 + fd567e5 commit 90b5de7
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
9 changes: 4 additions & 5 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ on:
paths-ignore:
- '**.md'

permissions:
contents: read

jobs:
check-dist:
name: Check dist/
runs-on: ubuntu-latest

permissions:
contents: read
statuses: write

steps:
- name: Checkout
id: checkout
Expand All @@ -30,7 +29,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: .node-version
cache: npm

- name: Install Dependencies
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches:
- main

# This is required to be able to update tags and create releases
permissions:
contents: write

Expand All @@ -16,18 +15,17 @@ jobs:
name: Release Version
runs-on: ubuntu-latest

# Only run this job if the PR was merged
if: ${{ github.event.pull_request.merged == true }}
if: |
github.event.pull_request.merged == true &&
startsWith(github.head_ref, 'dependabot/') == false
steps:
# Checkout the repository with fetch-tags set to true
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-tags: true

# Get the version and update the tags to use in the release
- name: Tag
id: tag
uses: issue-ops/semver@v0.1.0
Expand All @@ -36,8 +34,6 @@ jobs:
workspace: ${{ github.workspace }}
ref: main

# Use the version output from the previous step for the release
# Prepend a 'v' to the beginning (e.g. 'v1.2.3')
- name: Create Release
id: release
uses: issue-ops/releaser@v0.1.2
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ on:
branches:
- main

permissions:
actions: read
checks: write
contents: read

jobs:
continuous-integration:
name: Continuous Integration
runs-on: ubuntu-latest

permissions:
actions: read
checks: write
contents: read
statuses: write

steps:
- name: Checkout
id: checkout
Expand All @@ -28,7 +27,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: .node-version
cache: npm

- name: Install Dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issue-created.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: .node-version
cache: npm

# Next, install the dependencies from `package.json`.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
uses: actions/setup-node@v3
with:
node-version: 20
node-version-file: .node-version
cache: npm

- name: Install Dependencies
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.6.0
12 changes: 9 additions & 3 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

import * as main from '../src/main'

let runMock: jest.SpyInstance

describe('index', () => {
it('calls run when imported', async () => {
jest.spyOn(main, 'run').mockImplementation()
beforeEach(() => {
jest.clearAllMocks()

runMock = jest.spyOn(main, 'run').mockImplementation()
})

it('calls run when imported', async () => {
require('../src/index')

expect(main.run).toHaveBeenCalled()
expect(runMock).toHaveBeenCalled()
})
})
9 changes: 4 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ jest.mock('@octokit/rest', () => ({
Octokit: jest.fn()
}))

jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(core, 'setFailed').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation()

describe('main', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.resetAllMocks()

jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(core, 'setFailed').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation()
})

it('retrieves the inputs', async () => {
Expand Down
22 changes: 4 additions & 18 deletions __tests__/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ jest.mock('@octokit/rest', () => ({
describe('validate', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('validates each input type', async () => {
jest.spyOn(core, 'error').mockImplementation()
jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(input, 'validateInput').mockImplementation()
jest.spyOn(textarea, 'validateTextarea').mockImplementation()
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
})

it('validates each input type', async () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false)

await validate(
Expand Down Expand Up @@ -67,11 +69,6 @@ describe('validate', () => {
})

it('skips custom validation if no config is present', async () => {
jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(input, 'validateInput').mockImplementation()
jest.spyOn(textarea, 'validateTextarea').mockImplementation()
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
jest.spyOn(fs, 'existsSync').mockReturnValue(false)

const errors: string[] = await validate(
Expand All @@ -91,12 +88,7 @@ describe('validate', () => {
})

it('passes custom validation if config is present and inputs are valid', async () => {
jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(core, 'getInput').mockReturnValue('1234')
jest.spyOn(input, 'validateInput').mockImplementation()
jest.spyOn(textarea, 'validateTextarea').mockImplementation()
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
jest.spyOn(fs, 'existsSync').mockReturnValue(true)

const mocktokit = {
Expand Down Expand Up @@ -137,13 +129,7 @@ describe('validate', () => {
})

it('fails custom validation if config is present and inputs are invalid', async () => {
jest.spyOn(core, 'info').mockImplementation()
jest.spyOn(core, 'getInput').mockReturnValue('1234')
jest.spyOn(core, 'error').mockImplementation()
jest.spyOn(input, 'validateInput').mockImplementation()
jest.spyOn(textarea, 'validateTextarea').mockImplementation()
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
jest.spyOn(fs, 'existsSync').mockReturnValue(true)

const mocktokit = {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "validator",
"description": "Validate issue form submissions",
"version": "0.2.0",
"version": "0.2.1",
"author": "Nick Alteen <ncalteen@github.com>",
"homepage": "https://github.com/issue-ops/validator#readme",
"repository": {
Expand All @@ -25,13 +25,14 @@
"scripts": {
"bundle": "npm run format:write && npm run package",
"ci-test": "jest",
"coverage": "make-coverage-badge --output-path ./badges/coverage.svg",
"format:write": "prettier --write '**/*.ts'",
"format:check": "prettier --check '**/*.ts'",
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
"package": "ncc build src/index.ts -o dist --source-map --license licenses.txt",
"package:watch": "npm run package -- --watch",
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
"all": "npm run format:write && npm run lint && npm run test && npm run package"
"test": "jest",
"all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"
},
"license": "MIT",
"jest": {
Expand Down

0 comments on commit 90b5de7

Please sign in to comment.