diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index b2a6490..ea29752 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -3,7 +3,7 @@ # `index.js` is the code that will run. # For our project, we generate this file through a build process from other source files. # We need to make sure the checked-in `index.js` actually matches what we expect it to be. -name: Check dist/ +name: Check dist on: # push: diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 3fa88a4..c0dadd5 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -8,6 +8,7 @@ test('test runs', () => { // process.env['INPUT_REPO'] = '' // process.env['INPUT_CURRENT_TAG'] = '' // process.env['INPUT_PREVIOUS_TAG'] = '' + // process.env['INPUT_RETURN_TYPE'] = '' const np = process.execPath const ip = path.join(__dirname, '..', 'lib', 'main.js') diff --git a/action.yml b/action.yml index 43a035b..97b7e0b 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ inputs: description: The GitHub token to use. required: true repo: - description: 'The repository to use. Defaults to current repository. Expected format: owner/repo' + description: 'The repository to use. Defaults to current repository. Expected format: owner/repo.' required: false current_tag: description: The current tag to use. Defaults to current/latest tag. @@ -14,6 +14,10 @@ inputs: previous_tag: description: The previous tag to use. Defaults to one tag before the current tag. required: false + return_type: + description: 'What data to return. Options are: title_only (default), all.' + required: false + default: default outputs: pull_requests: description: The pull requests merged between the 2 tags. diff --git a/src/main.ts b/src/main.ts index 53860bf..ac26029 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,11 +6,18 @@ import {components} from '@octokit/openapi-types' // eslint-disable-next-line import/no-unresolved import {Api} from '@octokit/plugin-rest-endpoint-methods/dist-types/types' +const ALLOWED_RETURN_TYPES: string[] = ['title_only', 'all'] +const DEFAULT_RETURN_TYPE = 'title_only' + interface Repo { owner: string repo: string } +interface PullRequestDefault { + title: string +} + const getRepo = (): Repo => { const repo = core.getInput('repo') if (repo && repo.includes('/')) { @@ -65,6 +72,15 @@ const getPreviousTag = async ( return tags.data[index + 1].name } +const getReturnType = (): string => { + const returnType = core.getInput('return_type') + if (returnType && ALLOWED_RETURN_TYPES.includes(returnType)) { + return returnType + } + + return DEFAULT_RETURN_TYPE +} + const getCommits = async ( client: Octokit & Api, repo: Repo, @@ -87,7 +103,11 @@ const getPullRequests = async ( repo: Repo, currentTag: string, previousTag: string -): Promise => { +): Promise< + | PullRequestDefault[] + | components['schemas']['issue-search-result-item'][] + | [] +> => { const commits = await getCommits(client, repo, currentTag, previousTag) if (!commits) { @@ -100,9 +120,6 @@ const getPullRequests = async ( for (let i = 0; i < commits.length; i++) { hashes.push(commits[i].sha) - // eslint-disable-next-line no-console - console.log('MAX?', i === commits.length - 1) - if (i % 5 === 0 || i === commits.length - 1) { const newItems = ( await client.rest.search.issuesAndPullRequests({ @@ -117,7 +134,14 @@ const getPullRequests = async ( } } - return items + switch (getReturnType()) { + case 'all': + return items + default: + return items.map(item => ({ + title: item.title + })) + } } const run = async (): Promise => {