Skip to content

Commit 6e76342

Browse files
committed
Generalise getToolsInput into getComputedInput
1 parent c54d34d commit 6e76342

3 files changed

Lines changed: 61 additions & 14 deletions

File tree

lib/entry-points.js

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/inputs.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Feature } from "../feature-flags";
33
import {
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+
}

src/feature-flags/properties.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export type AllRepositoryProperties = {
2929
[RepositoryPropertyName.TOOLS]: string;
3030
};
3131

32+
/** The subset of known repository properties which are of type `string`. */
33+
export type StringRepositoryPropertyNames = keyof {
34+
[K in keyof AllRepositoryProperties as AllRepositoryProperties[K] extends string
35+
? K
36+
: never]: AllRepositoryProperties[K];
37+
};
38+
3239
/** Parsed repository properties. */
3340
export type RepositoryProperties = Partial<AllRepositoryProperties>;
3441

0 commit comments

Comments
 (0)