Skip to content

Commit

Permalink
feat: add locale input (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedaviddias authored Aug 4, 2023
1 parent 994a0c6 commit 1e8a695
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ jobs:
jira_ticket_prefix: "ABC"
jira_instance_url: "https://example.atlassian.net"
time_zone_offset: "-4" # Toronto (Canada - Ontario)
locale: "fr-FR"


30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,26 @@ jobs:
contributor_replace_regex: "-"
contributor_replace_char: "."
time_zone_offset: "-4" # Toronto (Canada - Ontario)
locale: "fr-FR"
```
#### Inputs
| Name | Required | Default | Description |
| --------------------------- | -------- | ------------------------- | --------------------------------------------------------------------------------------------------------- |
| `github_token` | yes | | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret |
| `repo` | no | | Name of the repo (e.g. owner/repo) if not the current one |
| `tag_regex` | no | ^v[0-9]+\.[0-9]+\.[0-9]+$ | Regex to accommodate varying tag formatting. |
| `time_zone_offset` | no | 0 | Timezone offset in minutes from UTC. |
| `contributor_replace_regex` | no | | Regular expression (regex) pattern to identify characters in the `contributor` name that will be replaced |
| `contributor_replace_char` | no | | The character that will replace specific characters in the `contributor` name |
| `slack_webhook_urls` | no | | Slack webhook URL to receive release notifications |
| `jira_ticket_prefix` | no | | Prefix for JIRA ticket references in PR titles (e.g. ABC) |
| `jira_instance_url` | no | | URL for your JIRA instance to generate JIRA ticket links (e.g. https://your-jira-instance.com) |
| `sentry_project_name` | no | | ID of the Sentry project for error tracking |
| `sentry_project_name` | no | | Name of the Sentry project for error tracking |
| `grafana_dashboard_link` | no | | Link to the Grafana dashboard for monitoring |
| Name | Required | Default | Description |
| --------------------------- | -------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `github_token` | yes | | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret |
| `repo` | no | | Name of the repo (e.g. owner/repo) if not the current one |
| `tag_regex` | no | ^v[0-9]+\.[0-9]+\.[0-9]+$ | Regex to accommodate varying tag formatting. |
| `time_zone_offset` | no | 0 | Timezone offset in minutes from UTC. |
| `locale` | no | en-US | Preferred locale for date formatting, adhering to the BCP 47 language tag standard (e.g., 'en-US' for American English) |
| `contributor_replace_regex` | no | | Regular expression (regex) pattern to identify characters in the `contributor` name that will be replaced |
| `contributor_replace_char` | no | | The character that will replace specific characters in the `contributor` name |
| `slack_webhook_urls` | no | | Slack webhook URL to receive release notifications |
| `jira_ticket_prefix` | no | | Prefix for JIRA ticket references in PR titles (e.g. ABC) |
| `jira_instance_url` | no | | URL for your JIRA instance to generate JIRA ticket links (e.g. https://your-jira-instance.com) |
| `sentry_project_name` | no | | ID of the Sentry project for error tracking |
| `sentry_project_name` | no | | Name of the Sentry project for error tracking |
| `grafana_dashboard_link` | no | | Link to the Grafana dashboard for monitoring |


### Outputs
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ inputs:
required: false
default: '0' # Default is 0, i.e., UTC time

locale:
description: 'Locale for date formatting'
required: false
default: 'en-US' # Default locale is American English

runs:
using: node16
main: dist/index.js
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('run function', () => {
contributorReplaceRegex: '-',
tagRegex: '^v[0-9]+.[0-9]+.[0-9]+$',
timeZoneOffset: '0',
locale: 'fr-FR'
})

const getOwnerAndRepoMock = jest.spyOn(getOwnerAndRepoModule, 'getOwnerAndRepo')
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/__mocks__/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export const MOCK_GET_INPUTS = {
contributorReplaceRegex: '-',
tagRegex: '^v[0-9]+.[0-9]+.[0-9]+$',
timeZoneOffset: '0',
locale: 'fr-FR'
}
6 changes: 6 additions & 0 deletions src/utils/__tests__/getInputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('getInputs', () => {
return 'my-tag-regex'
case 'time_zone_offset':
return 'GTM-0'
case 'locale':
return 'locale'
default:
return ''
}
Expand All @@ -48,6 +50,7 @@ describe('getInputs', () => {
contributorReplaceRegex: '-',
tagRegex: 'my-tag-regex',
timeZoneOffset: '0',
locale: 'locale',
}

expect(getInputs()).toEqual(expectedInputs)
Expand Down Expand Up @@ -106,6 +109,8 @@ describe('getInputs', () => {
return '^v[0-9]+.[0-9]+.[0-9]+$'
case 'time_zone_offset':
return '0'
case 'locale':
return 'fr-FR'
default:
return ''
}
Expand All @@ -127,6 +132,7 @@ describe('getInputs', () => {
contributorReplaceRegex: '-',
tagRegex: '^v[0-9]+.[0-9]+.[0-9]+$',
timeZoneOffset: '0',
locale: 'fr-FR',
}

expect(getInputs()).toEqual(expectedInputs)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getCurrentDate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function getCurrentDate(timeZoneOffset: string): string {
export function getCurrentDate(timeZoneOffset: string, locale: string): string {
const offset = Number(timeZoneOffset)

const date = new Date()
const utcDate = date.getTime() + date.getTimezoneOffset() * 60 * 1000
const targetDate = new Date(utcDate + offset * 60 * 60 * 1000)

return targetDate.toLocaleString('en-US', {
return targetDate.toLocaleString(locale, {
year: 'numeric',
month: 'long',
day: 'numeric',
Expand Down
3 changes: 3 additions & 0 deletions src/utils/getInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface GetInputsType {
contributorReplaceChar: string
contributorReplaceRegex: string
timeZoneOffset: string
locale: string
}

/**
Expand All @@ -53,6 +54,7 @@ export function getInputs(): GetInputsType {
const contributorReplaceChar = core.getInput('contributor_replace_char') || ''
const contributorReplaceRegex = core.getInput('contributor_replace_regex') || ''
let timeZoneOffset = core.getInput('time_zone_offset') || '0'
const locale = core.getInput('locale') || 'en-US'

// Input value checking example for URLs
if (grafanaDashboardLink && !isValidUrl(grafanaDashboardLink)) {
Expand Down Expand Up @@ -121,5 +123,6 @@ export function getInputs(): GetInputsType {
contributorReplaceChar,
contributorReplaceRegex,
timeZoneOffset,
locale,
}
}
2 changes: 1 addition & 1 deletion src/utils/handleSlackNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function handleSlackNotification({
)

// Get the current date in the specified time zone
const currentDate = getCurrentDate(options.timeZoneOffset)
const currentDate = getCurrentDate(options.timeZoneOffset, options.locale)

// Generate the Slack message data, which includes information about the repository, the release, the commit of the current tag,
// the list of pull requests, and the current date
Expand Down

0 comments on commit 1e8a695

Please sign in to comment.