Skip to content

Commit

Permalink
[Feat] Allow support for return type
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwjn committed Aug 15, 2023
1 parent 2d55381 commit 8a5515a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ 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.
required: false
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.
Expand Down
34 changes: 29 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')) {
Expand Down Expand Up @@ -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,
Expand All @@ -87,7 +103,11 @@ const getPullRequests = async (
repo: Repo,
currentTag: string,
previousTag: string
): Promise<components['schemas']['issue-search-result-item'][] | []> => {
): Promise<
| PullRequestDefault[]
| components['schemas']['issue-search-result-item'][]
| []
> => {
const commits = await getCommits(client, repo, currentTag, previousTag)

if (!commits) {
Expand All @@ -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({
Expand All @@ -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<void> => {
Expand Down

0 comments on commit 8a5515a

Please sign in to comment.