|
1 | | -import { cwd, readConfig, readFile, writeFile } from './utils/filesystem' |
2 | | -import { context, getOctokit } from '@actions/github' |
3 | | -import { parse } from './utils/inputs' |
4 | | -import { info } from '@actions/core' |
5 | | -import { Config } from './types/config' |
6 | | -import { Repository } from './utils/repository' |
7 | | -import { setPreview } from './utils/preview' |
8 | | -import { setOutputs } from './utils/outputs' |
9 | | -import { getPackageManager } from './utils/packageManagers' |
10 | | -import { titleCase } from './utils/strings' |
| 1 | +import { cwd, readConfig, readFile, writeFile } from "./utils/filesystem"; |
| 2 | +import { context, getOctokit } from "@actions/github"; |
| 3 | +import { parse } from "./utils/inputs"; |
| 4 | +import { info } from "@actions/core"; |
| 5 | +import type { Config } from "./types/config"; |
| 6 | +import { Repository } from "./utils/repository"; |
| 7 | +import { setPreview } from "./utils/preview"; |
| 8 | +import { setOutputs } from "./utils/outputs"; |
| 9 | +import { getPackageManager } from "./utils/packageManagers"; |
| 10 | +import { titleCase } from "./utils/strings"; |
11 | 11 |
|
12 | 12 | const previewUpdater = async () => { |
13 | 13 | // Inputs |
14 | | - const { |
15 | | - token, |
16 | | - configPath |
17 | | - } = parse() |
| 14 | + const { token, configPath } = parse(); |
18 | 15 |
|
19 | 16 | // Load Config |
20 | | - let config: Config = readConfig(<Config>{ |
21 | | - directory: cwd(), |
22 | | - |
23 | | - repository: { |
24 | | - owner: context.repo.owner, |
25 | | - repo: context.repo.repo, |
26 | | - octokit: getOctokit(token) |
27 | | - } |
28 | | - }, configPath) |
| 17 | + const config: Config = readConfig( |
| 18 | + <Config>{ |
| 19 | + directory: cwd(), |
| 20 | + |
| 21 | + repository: { |
| 22 | + owner: context.repo.owner, |
| 23 | + repo: context.repo.repo, |
| 24 | + octokit: getOctokit(token), |
| 25 | + }, |
| 26 | + }, |
| 27 | + configPath, |
| 28 | + ); |
29 | 29 |
|
30 | 30 | // Read names |
31 | | - const packageManager = getPackageManager(config) |
| 31 | + const packageManager = getPackageManager(config); |
32 | 32 |
|
33 | | - config.image.parameters.packageName = packageManager.name |
34 | | - config.image.parameters.title = titleCase(config.repository.repo) |
35 | | - config.image.parameters.description = packageManager.description || config.repository.owner |
| 33 | + config.image.parameters.packageName = packageManager.name; |
| 34 | + config.image.parameters.title = titleCase(config.repository.repo); |
| 35 | + config.image.parameters.description = |
| 36 | + packageManager.description || config.repository.owner; |
36 | 37 |
|
37 | 38 | // Show working directory |
38 | | - info(`Working directory: ${ config.directory }`) |
| 39 | + info(`Working directory: ${config.directory}`); |
39 | 40 |
|
40 | 41 | // Authenticate |
41 | | - const repo = new Repository(config) |
42 | | - await repo.authenticate() |
| 42 | + const repo = new Repository(config); |
| 43 | + await repo.authenticate(); |
43 | 44 |
|
44 | 45 | // Read file |
45 | | - const content = readFile(config, config.path.readme) |
46 | | - const preview = setPreview(content, config) |
| 46 | + const content = readFile(config, config.path.readme); |
| 47 | + const preview = setPreview(content, config); |
47 | 48 |
|
48 | 49 | if (content === preview) { |
49 | | - info(`File "${ config.path.readme }" is up to date`) |
| 50 | + info(`File "${config.path.readme}" is up to date`); |
50 | 51 |
|
51 | | - return |
| 52 | + return; |
52 | 53 | } |
53 | 54 |
|
54 | 55 | // Checkout branch |
55 | | - const branchExists = await repo.branchExists() |
56 | | - info(`Checkout ${ branchExists ? 'existing' : 'new' } branch named "${ repo.branchName() }"`) |
57 | | - await repo.checkoutBranch(! branchExists) |
| 56 | + const branchExists = await repo.branchExists(); |
| 57 | + info( |
| 58 | + `Checkout ${branchExists ? "existing" : "new"} branch named "${repo.branchName()}"`, |
| 59 | + ); |
| 60 | + await repo.checkoutBranch(!branchExists); |
58 | 61 |
|
59 | 62 | // Write a file |
60 | | - info(`Update readme in "${ config.path.readme }" file`) |
61 | | - writeFile(config, config.path.readme, preview) |
| 63 | + info(`Update readme in "${config.path.readme}" file`); |
| 64 | + writeFile(config, config.path.readme, preview); |
62 | 65 |
|
63 | 66 | // Stage and commit changes |
64 | | - await repo.stage() |
65 | | - await repo.commit() |
66 | | - await repo.push() |
| 67 | + await repo.stage(); |
| 68 | + await repo.commit(); |
| 69 | + await repo.push(); |
67 | 70 |
|
68 | 71 | // Create a Pull Request |
69 | | - const pullRequest = await repo.createPullRequest() |
| 72 | + const pullRequest = await repo.createPullRequest(); |
70 | 73 |
|
71 | 74 | // Variables |
72 | | - const pullRequestNumber: number = pullRequest.data.number |
73 | | - const pullRequestUrl: string = pullRequest.data.html_url |
| 75 | + const pullRequestNumber: number = pullRequest.data.number; |
| 76 | + const pullRequestUrl: string = pullRequest.data.html_url; |
74 | 77 |
|
75 | 78 | if (config.repository.pullRequest.assignees.length > 0) { |
76 | | - await repo.assignee(pullRequestNumber, config.repository.pullRequest.assignees) |
| 79 | + await repo.assignee( |
| 80 | + pullRequestNumber, |
| 81 | + config.repository.pullRequest.assignees, |
| 82 | + ); |
77 | 83 | } |
78 | 84 |
|
79 | 85 | if (config.repository.pullRequest.labels.length > 0) { |
80 | | - await repo.addLabels(pullRequestNumber, config.repository.pullRequest.labels) |
| 86 | + await repo.addLabels( |
| 87 | + pullRequestNumber, |
| 88 | + config.repository.pullRequest.labels, |
| 89 | + ); |
81 | 90 | } |
82 | 91 |
|
83 | | - info(`Preview created in Pull Request #${ pullRequestNumber }: ${ pullRequestUrl }`) |
| 92 | + info( |
| 93 | + `Preview created in Pull Request #${pullRequestNumber}: ${pullRequestUrl}`, |
| 94 | + ); |
84 | 95 |
|
85 | | - setOutputs(repo.branchName(), pullRequestNumber, pullRequestUrl) |
86 | | -} |
| 96 | + setOutputs(repo.branchName(), pullRequestNumber, pullRequestUrl); |
| 97 | +}; |
87 | 98 |
|
88 | | -export default previewUpdater |
| 99 | +export default previewUpdater; |
0 commit comments