Skip to content

Release/v0.2.1 beta #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 14, 2024
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 0.2.1-beta (July 1, 2024)

Below is a list of all new features, APIs, deprecations, and breaking changes.

## New Features

-

## Improvements

-

## Other Changes

-

## Bug Fixes

-
30 changes: 29 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,37 @@ branding:
# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
description: 'The number of milliseconds to wait before the action starts. '
required: true
default: '1000'
slack_enabled:
description: 'Enable Slack notifications'
required: false
default: 'false'
slack_channel_id:
description: 'The Slack channel ID to send notifications to'
slack_access_token:
description:
'The Slack access token that has the necessary permissions to send
messages to the channel'
locale:
description: 'The locale to use for the action'
required: false
default: 'en-us'
member_id_list_to_mention:
description:
'A list of member IDs to mention in the Slack message, comma separated'
api_documentation_url:
description: 'The URL to the API documentation'
required: false
openapi_file_path:
description: 'The path to the OpenAPI file'
required: false
default: 'openapi.json'
head_commit_message:
description: 'The message of the head commit'
head_commit_sha:
description: 'The SHA of the head commit'

# Define your outputs here.
outputs:
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 13 additions & 6 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/types/github-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export interface GithubInput {
*/
headCommitMessage?: string

/**
* The sha of the last commit which triggered the action
*/
headCommitSha?: string

/**
* URL of the api documentation - Optional
*/
Expand Down
10 changes: 8 additions & 2 deletions src/utils/get-file-from-branch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { execSync } from 'child_process'
import { readFileSync } from 'fs'

export function getFileFromBranch(branch: string, filePath: string): Buffer {
export function getFileFromBranch(
branch: string,
filePath: string,
offsetFromHead?: number
): Buffer {
const offset = offsetFromHead ? `~${offsetFromHead}` : ''

execSync(`git fetch origin ${branch}`)
execSync(`git checkout FETCH_HEAD -- ${filePath}`)
execSync(`git checkout FETCH_HEAD${offset} -- ${filePath}`)
return readFileSync(filePath)
}
20 changes: 16 additions & 4 deletions src/utils/validate-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,35 @@ export function validateInputAndSetConfig(): Config {
const baseCommittish = isOnPullRequest
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
process.env.GITHUB_BASE_REF!
: `${headCommittish}~1`
: headCommittish

// core.getInput() always returns a string, so nullish coalescing operator does not work.
const openapiFilePath =
core.getInput('openapi_file_path') ?? DEFAULT_OPENAPI_FILE_PATH
core.getInput('openapi_file_path') === ''
? DEFAULT_OPENAPI_FILE_PATH
: core.getInput('openapi_file_path')

baseFile = JSON.parse(
getFileFromBranch(baseCommittish, openapiFilePath).toString()
getFileFromBranch(
baseCommittish,
openapiFilePath,
isOnPullRequest ? undefined : 1
).toString()
)
headFile = JSON.parse(
getFileFromBranch(headCommittish, openapiFilePath).toString()
)
}

const sha =
core.getInput('head_commit_sha') === ''
? MOCKUP_SHA
: core.getInput('head_commit_sha')

const githubConfig: Config['githubConfig'] = {
repository: process.env.GITHUB_REPOSITORY ?? MOCKUP_REPOSITORY,
headCommitInfo: {
sha: process.env.GITHUB_SHA ?? MOCKUP_SHA,
sha,
message:
core.getInput('head_commit_message') === ''
? MOCKUP_MESSAGE
Expand Down
Loading