Skip to content
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GitHub Actions (TypeScript)",
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
"image": "mcr.microsoft.com/devcontainers/typescript-node:24",
"postCreateCommand": "npm install",
"customizations": {
"codespaces": {
Expand Down
4 changes: 1 addition & 3 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
env:
node: true
es6: true
jest: true

globals:
Atomics: readonly
Expand All @@ -13,6 +12,7 @@ ignorePatterns:
- '**/dist/.*'
- '**/coverage/.*'
- '*.json'
- 'vitest.config.ts'

parser: '@typescript-eslint/parser'

Expand All @@ -24,14 +24,12 @@ parserOptions:
- './tsconfig.json'

plugins:
- jest
- '@typescript-eslint'

extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:jest/recommended

rules:
{
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ jobs:
run: |
echo "Issue Number: ${{ steps.test-action.outputs.issue-number }}"

sleep 10 # Wait for eventual consistency

- name: Test Local Action - Partial Update
id: partial-update-action
uses: ./
Expand All @@ -188,8 +190,8 @@ jobs:
with:
repository: benlei/internal-issues
token: ${{ steps.app-token.outputs.token }}
update-option: patch
title: 'Test Partial Update from CI ${{ github.run_id }}'
update-option: patch
fields: |
Release Name, goodbye, world!
Release Version, "${newVersion}"
Expand All @@ -204,6 +206,7 @@ jobs:

- name: Close Issue
uses: peter-evans/close-issue@v3
if: always()
with:
repository: benlei/internal-issues
token: ${{ steps.app-token.outputs.token }}
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/linter.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21.6.2
24.15.0
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# benlei/create-issue-templateless

[![GitHub Super-Linter](https://github.com/benlei/create-issue-templateless/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/benlei/create-issue-templateless/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/benlei/create-issue-templateless/actions/workflows/check-dist.yml/badge.svg)](https://github.com/benlei/create-issue-templateless/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/benlei/create-issue-templateless/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/benlei/create-issue-templateless/actions/workflows/codeql-analysis.yml)
Expand Down
5 changes: 3 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/**
* Unit tests for the action's entrypoint, src/index.ts
*/
import { describe, expect, it, vi } from 'vitest'

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

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()
const runMock = vi.spyOn(main, 'run').mockReturnValue(Promise.resolve())

describe('index', () => {
it('calls run when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')
await import('../src/index')

expect(runMock).toHaveBeenCalled()
})
Expand Down
61 changes: 35 additions & 26 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

import * as rawInputs from '../src/inputs/rawInputs'
import * as inputs from '../src/inputs'
import { repository } from '../src/inputs'

vi.mock('@actions/core', () => ({
setOutput: vi.fn(),
setFailed: vi.fn(),
warning: vi.fn(),
getInput: vi.fn(),
info: vi.fn()
}))

describe('fields', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.restoreAllMocks()
vi.clearAllMocks()
vi.restoreAllMocks()
})

it('should parse fields properly', () => {
jest
.spyOn(inputs, 'fieldsInput')
.mockReturnValue('key1, value1\nkey2, value2')
vi.spyOn(rawInputs, 'fieldsInput').mockReturnValue(
'key1, value1\nkey2, value2'
)

const result = inputs.fields()
expect(result).toEqual([
Expand All @@ -20,9 +31,9 @@ describe('fields', () => {
})

it('should ignore empty lines with whitespaces', () => {
jest
.spyOn(inputs, 'fieldsInput')
.mockReturnValue('key1, value1\n\n \n\t\nkey2, value2')
vi.spyOn(rawInputs, 'fieldsInput').mockReturnValue(
'key1, value1\n\n \n\t\nkey2, value2'
)

const result = inputs.fields()
expect(result).toEqual([
Expand All @@ -32,7 +43,7 @@ describe('fields', () => {
})

it('should technically key only line to have no value', () => {
jest.spyOn(inputs, 'fieldsInput').mockReturnValue('key1, value1\nkey2,')
vi.spyOn(rawInputs, 'fieldsInput').mockReturnValue('key1, value1\nkey2,')

const result = inputs.fields()
expect(result).toEqual([
Expand All @@ -45,11 +56,9 @@ describe('fields', () => {
const key2Value = '```yaml\nfoo: 123\nbar: baz\n```'
process.env.MY_ENV_VAR = key2Value
process.env.MY_OTHER_ENV_VAR = 'hello\nworld'
jest
.spyOn(inputs, 'fieldsInput')
.mockReturnValue(
`key1, value1\nkey2, "\${MY_ENV_VAR}"\nkey3, 123\nkey4, "\${MY_OTHER_ENV_VAR}"`
)
vi.spyOn(rawInputs, 'fieldsInput').mockReturnValue(
`key1, value1\nkey2, "\${MY_ENV_VAR}"\nkey3, 123\nkey4, "\${MY_OTHER_ENV_VAR}"`
)

const result = inputs.fields()
expect(result).toEqual([
Expand All @@ -63,52 +72,52 @@ describe('fields', () => {

describe('repository', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.restoreAllMocks()
vi.clearAllMocks()
vi.restoreAllMocks()
})

it('should parse default repository properly', () => {
process.env.GITHUB_REPOSITORY = 'owner/repo'
jest.spyOn(inputs, 'repositoryInput').mockReturnValue('')
vi.spyOn(rawInputs, 'repositoryInput').mockReturnValue('')

expect(repository()).toEqual({ owner: 'owner', repo: 'repo' })
})

it('should parse input repository properly', () => {
process.env.GITHUB_REPOSITORY = 'owner/repo'
jest.spyOn(inputs, 'repositoryInput').mockReturnValue('foo/bar')
vi.spyOn(rawInputs, 'repositoryInput').mockReturnValue('foo/bar')

expect(repository()).toEqual({ owner: 'foo', repo: 'bar' })
})

it('should throw an error if owner or repo is empty', () => {
jest.spyOn(inputs, 'repositoryInput').mockReturnValue('foo')
vi.spyOn(rawInputs, 'repositoryInput').mockReturnValue('foo')
expect(() => repository()).toThrow()

jest.spyOn(inputs, 'repositoryInput').mockReturnValue('/bar')
vi.spyOn(rawInputs, 'repositoryInput').mockReturnValue('/bar')
expect(() => repository()).toThrow()
})
})

describe('updateOption', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.restoreAllMocks()
vi.clearAllMocks()
vi.restoreAllMocks()
})

it('should return default if not in the list', () => {
jest.spyOn(inputs, 'updateOptionInput').mockReturnValue('foo')
vi.spyOn(rawInputs, 'updateOptionInput').mockReturnValue('foo')
expect(inputs.updateOption()).toEqual('default')
})

it('should return the value if in the list', () => {
jest.spyOn(inputs, 'updateOptionInput').mockReturnValue('patch')
vi.spyOn(rawInputs, 'updateOptionInput').mockReturnValue('patch')
expect(inputs.updateOption()).toEqual('patch')

jest.spyOn(inputs, 'updateOptionInput').mockReturnValue('upsert')
vi.spyOn(rawInputs, 'updateOptionInput').mockReturnValue('upsert')
expect(inputs.updateOption()).toEqual('upsert')

jest.spyOn(inputs, 'updateOptionInput').mockReturnValue('replace')
vi.spyOn(rawInputs, 'updateOptionInput').mockReturnValue('replace')
expect(inputs.updateOption()).toEqual('replace')
})
})
Loading
Loading