Skip to content

Commit b503e0a

Browse files
Refactor input handling to include readmePath and improve type annotations
1 parent 681c6ea commit b503e0a

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ jobs:
4949
# Required: true
5050
token: ${{ secrets.GITHUB_TOKEN }}
5151

52-
# Path to the settings file
52+
# Path to the settings file
5353
#
5454
# By default, .github/preview-updater.yml
5555
#
5656
# Required: false
5757
config: ''
58+
59+
# Specifies the path to the README file.
60+
#
61+
# By default, README.md
62+
#
63+
# Required: false
64+
readme: ''
5865
```
5966
6067
The action is setting the following outputs:
@@ -82,8 +89,6 @@ All fields are optional—omitted ones fall back to defaults.
8289
```yaml
8390
# $schema: https://raw.githubusercontent.com/TheDragonCode/github-preview-updater/refs/heads/main/resources/schema.json
8491
85-
path: README.md # Target file to update
86-
8792
package:
8893
# Declares the use of the package manager.
8994
# It is a regular string that will be substituted into the URL address.

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ inputs:
1919
description: Path to the preview configuration YAML file.
2020
default: '.github/preview-updater.yml'
2121
required: false
22+
23+
readme:
24+
description: Specifies the path to the README file.
25+
default: 'README.md'
26+
required: false

src/main.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ import { readConfig } from "./utils/config";
1212
import type { LockFile } from "./types/lockFile";
1313
import type { Data } from "./types/data";
1414
import type { Repository as Credentials } from "./types/repository";
15-
import {
16-
defaultConfig,
17-
defaultPackage,
18-
defaultPullRequest,
19-
} from "./libs/defaults";
15+
import { defaultPackage, defaultPullRequest } from "./libs/defaults";
2016
import type { GitHub } from "@actions/github/lib/utils";
2117

2218
const previewUpdater = async () => {
2319
// Inputs
24-
const { token, configPath } = parse();
20+
const { token, configPath, readmePath } = parse();
2521

2622
// Credentials
2723
const credentials: Credentials = {
@@ -53,7 +49,7 @@ const previewUpdater = async () => {
5349
// Read names
5450
const packageLock: LockFile = getPackageManager(config);
5551

56-
config.readme ||= defaultConfig.readme || "README.md";
52+
config.readme = readmePath;
5753

5854
config.package ||= defaultPackage;
5955
config.data ||= <Data>{};
@@ -71,8 +67,8 @@ const previewUpdater = async () => {
7167
await repo.authenticate();
7268

7369
// Read file
74-
const content = readFile(config, config.readme);
75-
const preview = setPreview(content, config, packageLock);
70+
const content: string = readFile(config, config.readme);
71+
const preview: string = setPreview(content, config, packageLock);
7672

7773
if (content === preview) {
7874
info(`File "${config.readme}" is up to date`);
@@ -81,7 +77,7 @@ const previewUpdater = async () => {
8177
}
8278

8379
// Checkout branch
84-
const branchExists = await repo.branchExists();
80+
const branchExists: boolean = await repo.branchExists();
8581
info(
8682
`Checkout ${branchExists ? "existing" : "new"} branch named "${repo.branchName()}"`,
8783
);

src/utils/inputs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ import { getInput } from "@actions/core";
22

33
export const TOKEN = {
44
name: "token",
5-
env: "INPUT_TOKEN",
65
};
76

87
export const CONFIG_PATH = {
98
name: "config",
10-
env: "INPUT_CONFIG_PATH",
119
defaultValue: ".github/preview-updater.yml",
1210
};
1311

12+
export const README_PATH = {
13+
name: "readme",
14+
defaultValue: "README.md",
15+
};
16+
1417
export const parse = () => {
1518
const token = getInput(TOKEN.name, { required: true });
1619
const configPath = getInput(CONFIG_PATH.name) || CONFIG_PATH.defaultValue;
20+
const readmePath = getInput(README_PATH.name) || README_PATH.defaultValue;
1721

1822
return {
1923
token,
2024
configPath,
25+
readmePath,
2126
};
2227
};

0 commit comments

Comments
 (0)