Fix code scanning alert - Pinned-Dependencies #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# SPDX-FileCopyrightText: GitHub, Inc. and contributors | |
# SPDX-License-Identifier: MIT | |
# | |
# Automatically edits an issue's descriptions with a header, | |
# one of: | |
# | |
# - Bug report | |
# - Crash report | |
# - Feature or enhancement | |
name: Add issue header | |
on: # yamllint disable-line rule:truthy | |
issues: | |
types: | |
# Only ever run once | |
- opened | |
permissions: | |
contents: read | |
jobs: | |
add-header: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
steps: | |
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # V7.0.1 | |
with: | |
# language=JavaScript | |
script: | | |
// https://devguide.python.org/triage/labels/#type-labels | |
const HEADERS = new Map([ | |
['type-bug', 'Bug report'], | |
['type-crash', 'Crash report'], | |
['type-feature', 'Feature or enhancement'], | |
]); | |
let issue_data = await github.rest.issues.get({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}).then(issue => issue.data); | |
let header = ''; | |
for (const label_data of issue_data.labels) { | |
const label_name = (typeof label_data === 'string') ? label_data : label_data.name; | |
if (HEADERS.has(label_name)) { | |
header = HEADERS.get(label_name); | |
break; | |
} | |
} | |
if (header !== '') { | |
console.log(`Setting new header: ${header}`); | |
await github.rest.issues.update({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `# ${header}\n\n${issue_data.body.replaceAll('\r', '')}` | |
}); | |
} |