Skip to content

Commit e765013

Browse files
reviewed changes
1 parent bb559db commit e765013

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

danger/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ jobs:
2929
* type: string
3030
* required: false
3131
* default: `${{ github.token }}`
32-
* extra-dangerfile: Path to an additional dangerfile to run custom checks.
33-
* extra-install-packages: Additional packages that are required by the extra-dangerfile, you can find a list of packages here: https://packages.debian.org/search?suite=bookworm&keywords=curl.
32+
33+
* `extra-dangerfile`: Path to an additional dangerfile to run custom checks.
34+
* type: string
35+
* required: false
36+
* default: ""
37+
38+
* `extra-install-packages`: Additional packages that are required by the extra-dangerfile, you can find a list of packages here: https://packages.debian.org/search?suite=bookworm&keywords=curl.
39+
* type: string
40+
required: false
41+
default: ""
3442

3543
## Outputs
3644

@@ -54,4 +62,18 @@ The Danger action runs the following checks:
5462
- **Conventional commits**: Validates commit message format and PR title conventions
5563
- **Cross-repo links**: Checks for proper formatting of links in changelog entries
5664

57-
For detailed rule implementations, see [dangerfile.js](dangerfile.js).
65+
For detailed rule implementations, see [dangerfile.js](dangerfile.js).
66+
67+
## Extra Danger File
68+
69+
When using an extra dangerfile, the file must be inside the repository and written in CommonJS syntax. You can use the following snippet to export your dangerfile:
70+
71+
```JavaScript
72+
module.exports = async function ({ fail, warn, message, markdown, danger }) {
73+
...
74+
const gitUrl = danger.github.pr.head.repo.git_url;
75+
...
76+
warn('...');
77+
}
78+
79+
```

danger/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ runs:
6565
-e DANGER_DISABLE_TRANSPILATION="true" \
6666
-e EXTRA_DANGERFILE_INPUT="${{ inputs.extra-dangerfile }}" \
6767
ghcr.io/danger/danger-js:${{ steps.config.outputs.version }} \
68-
ghcr.io/danger/danger-js:${{ steps.config.outputs.version }} \
6968
-c "sleep infinity"
7069
7170
- name: Setup additional packages

danger/dangerfile.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { getFlavorConfig, extractPRFlavor } = require('./dangerfile-utils.js');
2-
const fs = require('fs');
32

43
const headRepoName = danger.github.pr.head.repo.git_url;
54
const baseRepoName = danger.github.pr.base.repo.git_url;
@@ -190,11 +189,22 @@ async function checkActionsArePinned() {
190189
async function CheckFromExternalChecks() {
191190
// Get the external dangerfile path from environment variable (passed via workflow input)
192191
// Priority: EXTRA_DANGERFILE (absolute path) -> EXTRA_DANGERFILE_INPUT (relative path)
193-
const customPath = process.env.EXTRA_DANGERFILE || process.env.EXTRA_DANGERFILE_INPUT;
194-
console.log(`::debug:: Checking from external checks: ${customPath}`);
195-
if (customPath) {
192+
const extraDangerFilePath = process.env.EXTRA_DANGERFILE || process.env.EXTRA_DANGERFILE_INPUT;
193+
console.log(`::debug:: Checking from external checks: ${extraDangerFilePath}`);
194+
if (extraDangerFilePath) {
196195
try {
196+
const workspaceDir = '/github/workspace';
197+
const customPath = path.join('/github/workspace', extraDangerFilePath);
198+
if (!customPath.startsWith(workspaceDir)) {
199+
fail(`Invalid dangerfile path: ${customPath}. Path traversal is not allowed.`);
200+
return;
201+
}
202+
197203
const extraModule = require(`/github/workspace/${customPath}`);
204+
if (typeof extraModule !== 'function') {
205+
warn(`EXTRA_DANGERFILE must export a function at ${customPath}`);
206+
return;
207+
}
198208
await extraModule({
199209
fail: fail,
200210
warn: warn,

0 commit comments

Comments
 (0)