Skip to content

Commit 080fe7c

Browse files
committedMay 18, 2023
fix: updated code
1 parent 87297e8 commit 080fe7c

File tree

7 files changed

+2619
-4103
lines changed

7 files changed

+2619
-4103
lines changed
 

‎__tests__/main.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as process from 'process'
22
import * as cp from 'child_process'
33
import * as path from 'path'
44

5-
import {sanitize} from '../src/sanitize'
5+
import {sanitize} from '../src/main'
66

77
test('its supports cyrrilic', () => {
88
expect(sanitize('ref/branch/русский-бранч')).toEqual('russkiy-branch')

‎dist/index.js

+2,535-171
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/licenses.txt

+63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/sourcemap-register.js

+1-3,910
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/main.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
import * as core from '@actions/core'
2-
import {sanitize} from './sanitize'
2+
import {slugify} from 'transliteration'
33

4-
async function run(): Promise<void> {
4+
export function sanitize(ref: string): string {
5+
const splittedRef = ref.split('/')
6+
// Если передали github.head_ref, то мы получим просто имя ветки
7+
const branchName =
8+
splittedRef.length > 2 ? splittedRef.slice(2).join('/') : ref
9+
10+
return slugify(branchName, {replace: {'&': '-and-'}})
11+
}
12+
13+
;(async (): Promise<void> => {
514
try {
6-
const ref = process.env.GITHUB_REF
15+
const ref = core.getInput('ref', {required: true})
16+
17+
if (ref == null || ref === '') {
18+
core.setFailed('No ref input found')
719

8-
if (ref == null) {
9-
core.setFailed('No GITHUB_REF env variable found')
1020
return
1121
}
1222

1323
const branchNameSlug = sanitize(ref)
1424

25+
core.info(`Got ref: ${ref}`)
1526
core.info(`Sanitized branch name is ${branchNameSlug}`)
1627

1728
core.setOutput('branch_name', branchNameSlug)
1829

1930
core.exportVariable('BRANCH_NAME', branchNameSlug)
2031
} catch (error: unknown) {
21-
if (error instanceof Error) {
22-
core.setFailed(error)
23-
return
24-
}
25-
core.setFailed(String(error))
32+
core.setFailed((error as Error).message)
2633
}
27-
}
28-
29-
run()
34+
})()

‎src/sanitize.ts

-7
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.