Skip to content

Commit 1408a76

Browse files
author
Jakub N
authored
EISSWSCN-34439 Actions loaded are missing hyphens (#12)
* Merge branch 'main' of https://github.com/GetTuh/load-available-actions-gettuh * update main.ts * update main.ts and utils.ts * Remove sanitize * Disable sanitizaiton test * Uploading as artifact * switch sanitize to opening/closing tags * Adjusted tests & bug fix * Revert testing changes * Removed redundant logs * bugfix: replace only one occurence
1 parent 73ec10b commit 1408a76

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

.github/workflows/testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
exit 1
6666
fi
6767
68-
# upload the second result file as an artefact
68+
# upload the first result file as an artefact
6969
- name: Upload result file as artefact
7070
if: always()
7171
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2

__tests__/utils.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ test(`check parseYAML with normal strings`, () => {
1515
const content = `
1616
name: 'test-name'
1717
author: 'test-author'
18-
description: 'testing'
18+
description: 'email@testing.com-+-'
1919
runs:\n using: 'test'`
2020
const filePath = 'test'
2121
const result = parseYAML(filePath, 'test', content)
2222

23-
expect(result.name).toBe('testname')
24-
expect(result.author).toBe('testauthor')
25-
expect(result.description).toBe('testing')
23+
expect(result.name).toBe('test-name')
24+
expect(result.author).toBe('test-author')
25+
expect(result.description).toBe('email@testing.com-+-')
2626
expect(result.using).toBe('test')
2727
})
2828

29-
test(`check parseYAML with quoted strings`, () => {
29+
test(`check parseYAML with greater/less than`, () => {
3030
const content = `
31-
name: 'test "name"'
32-
author: 'test "author"'
33-
description: 'testing "with quotes"'
31+
name: '<test script="injection">'
32+
author: '<injection test in author>'
33+
description: '<injection test in description>'
3434
runs:\n using: 'testwithquote"'
3535
`
3636

3737
const filePath = 'test'
3838
const result = parseYAML(filePath, 'test', content)
3939

40-
expect(result.name).toBe('test name')
41-
expect(result.author).toBe('test author')
42-
expect(result.description).toBe('testing with quotes')
40+
expect(result.name).toBe('&#60;test script="injection"&#62;')
41+
expect(result.author).toBe('&#60;injection test in author&#62;')
42+
expect(result.description).toBe('&#60;injection test in description&#62;')
4343
expect(result.using).toBe('testwithquote')
4444
})
4545

src/main.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,22 @@ async function run(): Promise<void> {
9999
core.setFailed(`Error running action: : ${error.message}`)
100100
}
101101
}
102-
103-
export class ActionContent {
102+
class ContentBase{
104103
name: string | undefined
105-
owner: string | undefined
106104
repo: string | undefined
107105
downloadUrl: string | undefined
108-
author: string | undefined
109106
description: string | undefined
110107
forkedfrom: string | undefined
108+
isArchived: boolean | undefined
109+
}
110+
export class ActionContent extends ContentBase{
111+
owner: string | undefined
112+
author: string | undefined
111113
readme: string | undefined
112114
using: string | undefined
113-
isArchived: boolean | undefined
114115
}
115116

116-
export class WorkflowContent {
117-
name: string | undefined
118-
repo: string | undefined
119-
downloadUrl: string | undefined
120-
description: string | undefined
121-
forkedfrom: string | undefined
122-
isArchived: boolean | undefined
117+
export class WorkflowContent extends ContentBase{
123118
visibility: string | undefined
124119
}
125120

@@ -131,6 +126,7 @@ async function getAllActions(
131126

132127
// get all action files (action.yml and action.yaml) from the user or organization
133128
let actionFiles = await getAllNormalActions(client, user, organization, isEnterpriseServer)
129+
134130
// load the information inside of the action definition files
135131
actionFiles = await enrichActionFiles(client, actionFiles)
136132

@@ -580,7 +576,6 @@ async function getAllActionsUsingSearch(
580576
const filePath = searchResult[index].path
581577
const repoName = searchResult[index].repository.name
582578
const repoOwner = searchResult[index].repository.owner.login
583-
584579
// Push file to action list if filename matches action.yaml or action.yml
585580
if (fileName == 'action.yaml' || fileName == 'action.yml') {
586581
core.info(`Found action in ${repoName}/${filePath}`)

src/utils.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ export function parseYAML(
2222

2323
try {
2424
const parsed = YAML.parse(content)
25-
name = parsed.name ? sanitize(parsed.name) : defaultValue
26-
author = parsed.author ? sanitize(parsed.author) : defaultValue
27-
description = parsed.description
28-
? sanitize(parsed.description)
29-
: defaultValue
25+
name = removeGreaterLessThan(parsed.name) || defaultValue
26+
author = removeGreaterLessThan(parsed.author) || defaultValue
27+
description = removeGreaterLessThan(parsed.description) || defaultValue
3028

3129
if (parsed.runs) {
3230
using = parsed.runs.using ? sanitize(parsed.runs.using) : defaultValue
@@ -45,6 +43,7 @@ export function parseYAML(
4543
}
4644
return {name, author, description, using}
4745
}
46+
const removeGreaterLessThan = (item:string) => item.replace(/\>/g,'&#62;').replace(/\</g,'&#60;')
4847

4948
export function sanitize(value: string) {
5049
return string.sanitize.keepSpace(value)

0 commit comments

Comments
 (0)