generated from dsanders11/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62650d5
commit 4ec05f4
Showing
12 changed files
with
315 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import * as core from '@actions/core'; | ||
|
||
import * as index from '../src/find-project'; | ||
import { findProject } from '../src/lib'; | ||
import { mockGetInput } from './utils'; | ||
|
||
jest.mock('@actions/core'); | ||
jest.mock('../src/lib'); | ||
|
||
// Spy the action's entrypoint | ||
const findProjectActionSpy = jest.spyOn(index, 'findProjectAction'); | ||
|
||
const owner = 'dsanders11'; | ||
const projectNumber = '94'; | ||
const projectId = 'project-id'; | ||
const fieldCount = 4; | ||
const itemCount = 50; | ||
const shortDescription = 'Description'; | ||
const title = 'My Title'; | ||
const readme = 'README'; | ||
const url = 'url'; | ||
|
||
describe('findProjectAction', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('requires the title input', async () => { | ||
mockGetInput({ owner }); | ||
|
||
await index.findProjectAction(); | ||
expect(findProjectActionSpy).toHaveReturned(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledTimes(1); | ||
expect(core.setFailed).toHaveBeenLastCalledWith( | ||
'Input required and not supplied: title' | ||
); | ||
}); | ||
|
||
it('handles project not found', async () => { | ||
mockGetInput({ owner, title }); | ||
jest.mocked(findProject).mockResolvedValue(null); | ||
|
||
await index.findProjectAction(); | ||
expect(findProjectActionSpy).toHaveReturned(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledTimes(1); | ||
expect(core.setFailed).toHaveBeenLastCalledWith( | ||
`Project not found: ${title}` | ||
); | ||
}); | ||
|
||
it('handles generic errors', async () => { | ||
mockGetInput({ owner, title }); | ||
jest.mocked(findProject).mockImplementation(() => { | ||
throw new Error('Server error'); | ||
}); | ||
|
||
await index.findProjectAction(); | ||
expect(findProjectActionSpy).toHaveReturned(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledTimes(1); | ||
expect(core.setFailed).toHaveBeenLastCalledWith('Server error'); | ||
}); | ||
|
||
it('stringifies non-errors', async () => { | ||
mockGetInput({ owner, title }); | ||
jest.mocked(findProject).mockImplementation(() => { | ||
throw 42; // eslint-disable-line no-throw-literal | ||
}); | ||
|
||
await index.findProjectAction(); | ||
expect(findProjectActionSpy).toHaveReturned(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledTimes(1); | ||
expect(core.setFailed).toHaveBeenLastCalledWith('42'); | ||
}); | ||
|
||
it('sets output', async () => { | ||
mockGetInput({ owner, title }); | ||
jest.mocked(findProject).mockResolvedValue({ | ||
id: projectId, | ||
number: parseInt(projectNumber), | ||
fields: { | ||
totalCount: fieldCount | ||
}, | ||
items: { | ||
totalCount: itemCount | ||
}, | ||
url, | ||
title, | ||
readme, | ||
shortDescription, | ||
public: true, | ||
closed: false, | ||
owner: { | ||
type: 'Organization', | ||
login: owner | ||
} | ||
}); | ||
|
||
await index.findProjectAction(); | ||
expect(findProjectActionSpy).toHaveReturned(); | ||
|
||
expect(core.setOutput).toHaveBeenCalledTimes(10); | ||
expect(core.setOutput).toHaveBeenCalledWith('id', projectId); | ||
expect(core.setOutput).toHaveBeenCalledWith('url', url); | ||
expect(core.setOutput).toHaveBeenCalledWith('closed', false); | ||
expect(core.setOutput).toHaveBeenCalledWith('public', true); | ||
expect(core.setOutput).toHaveBeenCalledWith('field-count', fieldCount); | ||
expect(core.setOutput).toHaveBeenCalledWith('item-count', itemCount); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
'number', | ||
parseInt(projectNumber) | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith('readme', readme); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
'description', | ||
shortDescription | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith('title', title); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# `project-actions/find-project` | ||
|
||
[![Release](https://img.shields.io/github/v/release/dsanders11/project-actions?color=blue)](https://github.com/dsanders11/project-actions/releases) | ||
|
||
Find a GitHub project | ||
|
||
## Inputs | ||
|
||
| Name | Description | Required | Default | | ||
|-------------------|----------------------------------------------------|----------|----------------------------------------------| | ||
| `token` | A GitHub access token - either a classic PAT or a GitHub app installation token. | Yes | | | ||
| `owner` | The owner of the project - either an organization or a user. If not provided, it defaults to the repository owner. | No | `${{ github.repository_owner }}` | | ||
| `title` | The title of the project to find. | Yes | | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|-------------------|----------------------------------------------------| | ||
| `id` | The global ID for the project. | | ||
| `closed` | The closed state of the project. | | ||
| `field-count` | The number of fields on the project. | | ||
| `item-count` | The number of items in the project. | | ||
| `number` | The project number of the project. | | ||
| `public` | The public visibility of the project. | | ||
| `readme` | The readme description of the project. | | ||
| `description` | The short description of the project. | | ||
| `title` | The title of the project. | | ||
| `url` | The URL of the project. | | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Find Project | ||
description: Find a GitHub project | ||
author: David Sanders | ||
|
||
inputs: | ||
token: | ||
description: A GitHub access token - either a classic PAT or a GitHub app installation token | ||
required: true | ||
owner: | ||
description: The owner of the project - either an organization or a user | ||
required: false | ||
default: ${{ github.repository_owner }} | ||
title: | ||
description: The title of the project to find | ||
required: true | ||
|
||
outputs: | ||
id: | ||
description: The global ID for the project | ||
closed: | ||
description: The closed state of the project | ||
field-count: | ||
description: The number of fields on the project | ||
item-count: | ||
description: The number of items in the project | ||
number: | ||
description: The project number of the project | ||
public: | ||
description: The public visibility of the project | ||
readme: | ||
description: The readme description of the project | ||
description: | ||
description: The short description of the project | ||
title: | ||
description: The title of the project | ||
url: | ||
description: The URL of the project | ||
|
||
runs: | ||
using: node20 | ||
main: ../dist/find-project.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { findProjectAction } from '../src/find-project'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
findProjectAction(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.