@@ -3,6 +3,7 @@ import { Feature } from "../feature-flags";
33import {
44 RepositoryProperties ,
55 RepositoryPropertyName ,
6+ StringRepositoryPropertyNames ,
67} from "../feature-flags/properties" ;
78
89/** Enumerates input names. */
@@ -29,23 +30,35 @@ export type ComputedInput = {
2930} ;
3031
3132/**
32- * Gets the computed `tools` input. This comes from either the workflow or
33+ * Represents options for how to compute an input.
34+ */
35+ export interface ComputedInputOptions {
36+ repositoryPropertyName ?: StringRepositoryPropertyNames ;
37+ }
38+
39+ /**
40+ * Gets the computed input for `name`. This comes from either the workflow or
3341 * the repository property.
3442 *
3543 * @param action The Action state.
3644 * @param repositoryProperties The values of known repository properties.
45+ * @param name The name of the input to compute.
46+ * @param options Options for how to compute the input value.
47+ *
3748 * @returns The computed input or `undefined` if there is no input.
3849 */
39- export async function getToolsInput (
50+ export async function getComputedInput (
4051 action : ActionState < [ "Logger" , "Actions" , "FeatureFlags" ] > ,
41- repositoryProperties : Partial < RepositoryProperties > ,
52+ repositoryProperties : RepositoryProperties ,
53+ name : InputName ,
54+ options : ComputedInputOptions ,
4255) : Promise < ComputedInput | undefined > {
43- const name = InputName . Tools ;
4456 const input = action . actions . getOptionalInput ( name ) ;
45- const propertyValue = repositoryProperties [ RepositoryPropertyName . TOOLS ] ;
46- const allowRepositoryProperty = await action . features . getValue (
47- Feature . ToolsRepositoryProperty ,
48- ) ;
57+ const allowRepositoryProperty = options . repositoryPropertyName !== undefined ;
58+ const propertyValue =
59+ options . repositoryPropertyName !== undefined
60+ ? repositoryProperties [ options . repositoryPropertyName ]
61+ : undefined ;
4962
5063 // The repository property takes precedence if it starts with an '!'.
5164 if ( allowRepositoryProperty && propertyValue ?. startsWith ( "!" ) ) {
@@ -79,3 +92,25 @@ export async function getToolsInput(
7992 // There's no input.
8093 return undefined ;
8194}
95+
96+ /**
97+ * Gets the computed `tools` input. This comes from either the workflow or
98+ * the repository property.
99+ *
100+ * @param action The Action state.
101+ * @param repositoryProperties The values of known repository properties.
102+ * @returns The computed input or `undefined` if there is no input.
103+ */
104+ export async function getToolsInput (
105+ action : ActionState < [ "Logger" , "Actions" , "FeatureFlags" ] > ,
106+ repositoryProperties : Partial < RepositoryProperties > ,
107+ ) : Promise < ComputedInput | undefined > {
108+ const allowRepositoryProperty = await action . features . getValue (
109+ Feature . ToolsRepositoryProperty ,
110+ ) ;
111+ return getComputedInput ( action , repositoryProperties , InputName . Tools , {
112+ repositoryPropertyName : allowRepositoryProperty
113+ ? RepositoryPropertyName . TOOLS
114+ : undefined ,
115+ } ) ;
116+ }
0 commit comments