Skip to content

Commit

Permalink
fix: update jira instance url input value
Browse files Browse the repository at this point in the history
  • Loading branch information
thedaviddias committed Aug 3, 2023
1 parent bae1a57 commit 12e5c72
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ jobs:
sentry_project_id: ${{ secrets.SENTRY_PROJECT_ID }}
grafana_dashboard_link: https://example.grafana.net/d/xxxx/web-overview?orgId=1
jira_ticket_prefix: "ABC"
jira_instance_url: "https://example.atlassian.net/browse"
jira_instance_url: "https://example.atlassian.net"


4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: https://hooks.slack.com/services/XXXXXX/XXXXX/XXXXXXX
jira_ticket_prefix: ABC
jira_instance_url: https://your-jira-instance.com/browse
jira_instance_url: https://your-jira-instance.com
sentry_project_name: MyProject
sentry_project_id: 1234
grafana_dashboard_link: https://grafana.com/dashboards/XXXX
Expand All @@ -57,7 +57,7 @@ jobs:
| `contributor_replace_char` | no | | The character that will replace specific characters in the `contributor` name |
| `slack_webhook_url` | 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/browse) |
| `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 |
Expand Down
24 changes: 24 additions & 0 deletions src/utils/__tests__/appendBrowseToUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { appendBrowseToUrl } from '../appendBrowseToUrl'

describe('appendBrowseToUrl', () => {
it('should append /browse/ to url without trailing slash', () => {
const url = 'http://jira.example.com'
const expected = 'http://jira.example.com/browse/'
const result = appendBrowseToUrl(url)
expect(result).toEqual(expected)
})

it('should append /browse/ to url with trailing slash', () => {
const url = 'http://jira.example.com/'
const expected = 'http://jira.example.com/browse/'
const result = appendBrowseToUrl(url)
expect(result).toEqual(expected)
})

it('should return empty string when given an empty string', () => {
const url = ''
const expected = ''
const result = appendBrowseToUrl(url)
expect(result).toEqual(expected)
})
})
6 changes: 3 additions & 3 deletions src/utils/__tests__/getInputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('getInputs', () => {
sentryProjectName: 'my-project-name',
sentryProjectId: 'invalid-project-id',
slackWebhookUrl: 'invalid-webhook-url',
jiraInstanceUrl: 'invalid-jira-ticket-link',
jiraInstanceUrl: 'invalid-jira-ticket-link/browse/',
jiraTicketPrefix: 'ABC',
contributorReplaceChar: '.',
contributorReplaceRegex: '-',
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('getInputs', () => {
case 'slack_webhook_url':
return 'https://hooks.slack.com/services/XXXX/XXXX/XXXX'
case 'jira_instance_url':
return 'https://example.atlassian.net/browse' // Note: this is a valid URL
return 'https://example.atlassian.net' // Note: this is a valid URL
case 'jira_ticket_prefix':
return 'ABC' // Note: this is a valid prefix
case 'contributor_replace_char':
Expand All @@ -105,7 +105,7 @@ describe('getInputs', () => {
sentryProjectName: 'my-project-name',
sentryProjectId: '1234',
slackWebhookUrl: 'https://hooks.slack.com/services/XXXX/XXXX/XXXX',
jiraInstanceUrl: 'https://example.atlassian.net/browse',
jiraInstanceUrl: 'https://example.atlassian.net/browse/',
jiraTicketPrefix: 'ABC',
contributorReplaceChar: '.',
contributorReplaceRegex: '-',
Expand Down
14 changes: 14 additions & 0 deletions src/utils/appendBrowseToUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Appends '/browse/' to the provided URL.
*
* @param {string} url - The URL to modify.
* @return {string} The modified URL. If the input URL is empty, it is returned unchanged.
*/
export function appendBrowseToUrl(url: string): string {
if (!url) return url

// Ensure url ends with a slash
const formattedUrl = url.endsWith('/') ? url : `${url}/`

return `${formattedUrl}browse/`
}
1 change: 1 addition & 0 deletions src/utils/generateJiraTicketLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function generateJiraTicketLink(
ticketNumber: string,
instanceUrl: string
): string {

// Ensure instanceUrl ends with a slash
const formattedInstanceUrl = instanceUrl.endsWith('/')
? instanceUrl
Expand Down
5 changes: 4 additions & 1 deletion src/utils/getInputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import { appendBrowseToUrl } from './appendBrowseToUrl'

// Simple URL validation function
function isValidUrl(string: string): boolean {
Expand Down Expand Up @@ -89,14 +90,16 @@ export function getInputs(): GetInputsType {
)
}

const jiraInstanceUrlProcessed = appendBrowseToUrl(jiraInstanceUrl)

return {
repo,
grafanaDashboardLink,
sentryProjectName,
sentryProjectId,
slackWebhookUrl,
jiraTicketPrefix,
jiraInstanceUrl,
jiraInstanceUrl: jiraInstanceUrlProcessed,
contributorReplaceChar,
contributorReplaceRegex,
}
Expand Down

0 comments on commit 12e5c72

Please sign in to comment.