-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinputs.ts
More file actions
67 lines (56 loc) · 1.75 KB
/
Copy pathinputs.ts
File metadata and controls
67 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as fs from 'fs'
import * as core from '@actions/core'
const DEFAULT_INSTRUCTIONS_PATH = '.github/release-notes-instructions.md'
export interface ActionInputs {
baseRef: string
headRef: string
instructionsPath: string | undefined
model: string | undefined
prStrategy: 'merge-commits' | 'github-api'
}
export function getInputs(): ActionInputs {
const baseRef = core.getInput('base-ref', {required: true})
if (!baseRef) {
throw new Error('base-ref is required')
}
const headRef = core.getInput('head-ref') || 'HEAD'
const instructionsPath = resolveInstructionsPath(
core.getInput('instructions') || undefined
)
const model = core.getInput('model') || undefined
const prStrategyRaw = core.getInput('pr-strategy') || 'merge-commits'
if (prStrategyRaw !== 'merge-commits' && prStrategyRaw !== 'github-api') {
throw new Error(
`Invalid pr-strategy: ${prStrategyRaw}. Must be 'merge-commits' or 'github-api'`
)
}
return {
baseRef,
headRef,
instructionsPath,
model,
prStrategy: prStrategyRaw
}
}
/**
* Resolve the instructions file path:
* 1. If explicitly provided via input, use that
* 2. Otherwise, check for .github/release-notes-instructions.md in the workspace
* 3. If neither exists, return undefined (generic mode)
*/
function resolveInstructionsPath(
explicit: string | undefined
): string | undefined {
if (explicit) {
core.info(`📖 Using explicit instructions: ${explicit}`)
return explicit
}
if (fs.existsSync(DEFAULT_INSTRUCTIONS_PATH)) {
core.info(
`📖 Auto-discovered instructions: ${DEFAULT_INSTRUCTIONS_PATH}`
)
return DEFAULT_INSTRUCTIONS_PATH
}
core.info('📖 No custom instructions found — using generic mode')
return undefined
}