Skip to content

Commit f84a21d

Browse files
Fixed types
1 parent efc188c commit f84a21d

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

dist/index.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34392,7 +34392,6 @@ const previewUpdater = async () => {
3439234392
repository: {
3439334393
owner: github_1.context.repo.owner,
3439434394
repo: github_1.context.repo.repo,
34395-
octokit: (0, github_1.getOctokit)(token),
3439634395
},
3439734396
}, configPath);
3439834397
// Read names
@@ -34404,7 +34403,7 @@ const previewUpdater = async () => {
3440434403
// Show working directory
3440534404
(0, core_1.info)(`Working directory: ${config.directory}`);
3440634405
// Authenticate
34407-
const repo = new repository_1.Repository(config);
34406+
const repo = new repository_1.Repository(config, (0, github_1.getOctokit)(token));
3440834407
await repo.authenticate();
3440934408
// Read file
3441034409
const content = (0, filesystem_1.readFile)(config, config.path.readme);
@@ -34463,8 +34462,8 @@ exports.defaultConfig = {
3446334462
fontSize: "100px",
3446434463
icon: "code",
3446534464
packageManager: "auto",
34466-
packageName: undefined,
3446734465
packageGlobal: false,
34466+
packageName: undefined,
3446834467
title: undefined,
3446934468
description: undefined,
3447034469
},
@@ -34754,7 +34753,8 @@ const setPreview = (content, config) => {
3475434753
content = `# ${title}\n\n${content}`;
3475534754
}
3475634755
const images = (0, image_1.getImages)(config);
34757-
return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, "$1" + images + "\n\n");
34756+
const replace = "$1";
34757+
return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, `${replace}${images}\n\n`);
3475834758
};
3475934759
exports.setPreview = setPreview;
3476034760

@@ -34791,10 +34791,11 @@ exports.Repository = void 0;
3479134791
const filesystem_1 = __nccwpck_require__(9742);
3479234792
const randomizer_1 = __nccwpck_require__(3678);
3479334793
class Repository {
34794-
constructor(config) {
34795-
this._currentBranch = '';
34794+
constructor(config, octokit) {
34795+
this._currentBranch = "";
3479634796
this._newBranch = false;
3479734797
this._config = config;
34798+
this._octokit = octokit;
3479834799
}
3479934800
async authenticate() {
3480034801
try {
@@ -34829,17 +34830,17 @@ class Repository {
3482934830
async checkoutBranch(isNew) {
3483034831
try {
3483134832
this._newBranch = isNew;
34832-
await (0, filesystem_1.exec)(`git switch ${isNew ? '-c' : ''} "${this.branchName()}"`);
34833+
await (0, filesystem_1.exec)(`git switch ${isNew ? "-c" : ""} "${this.branchName()}"`);
3483334834
}
3483434835
catch (error) {
3483534836
// @ts-expect-error
34836-
error.message = `Error checking out ${isNew ? 'new' : 'existing'} branch "${this.branchName()}": ${error.message}`;
34837+
error.message = `Error checking out ${isNew ? "new" : "existing"} branch "${this.branchName()}": ${error.message}`;
3483734838
throw error;
3483834839
}
3483934840
}
3484034841
async stage() {
3484134842
try {
34842-
await (0, filesystem_1.exec)('git add ' + this._config.path.readme);
34843+
await (0, filesystem_1.exec)(`git add ${this._config.path.readme}`);
3484334844
}
3484434845
catch (error) {
3484534846
// @ts-expect-error
@@ -34850,7 +34851,7 @@ class Repository {
3485034851
async commit() {
3485134852
try {
3485234853
const message = this._config.repository.commit.title +
34853-
'\n' +
34854+
"\n" +
3485434855
this._config.repository.commit.body;
3485534856
await (0, filesystem_1.exec)(`git commit -m "${message}"`);
3485634857
}
@@ -34862,7 +34863,7 @@ class Repository {
3486234863
}
3486334864
async push() {
3486434865
try {
34865-
let cmd = 'git push';
34866+
let cmd = "git push";
3486634867
if (this._newBranch) {
3486734868
cmd += ` --set-upstream origin ${this.branchName()}`;
3486834869
}
@@ -34877,13 +34878,13 @@ class Repository {
3487734878
async createPullRequest() {
3487834879
try {
3487934880
const defaultBranch = await (0, filesystem_1.exec)(`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`);
34880-
return this._config.repository.octokit.rest.pulls.create({
34881+
return this._octokit.rest.pulls.create({
3488134882
owner: this._config.repository.owner,
3488234883
repo: this._config.repository.repo,
3488334884
title: this._config.repository.pullRequest.title,
3488434885
body: this._config.repository.pullRequest.body,
3488534886
head: this.branchName(),
34886-
base: defaultBranch
34887+
base: defaultBranch,
3488734888
});
3488834889
}
3488934890
catch (error) {
@@ -34894,11 +34895,11 @@ class Repository {
3489434895
}
3489534896
async assignee(issueNumber, assignees) {
3489634897
try {
34897-
return this._config.repository.octokit.rest.issues.addAssignees({
34898+
return this._octokit.rest.issues.addAssignees({
3489834899
owner: this._config.repository.owner,
3489934900
repo: this._config.repository.repo,
3490034901
issue_number: issueNumber,
34901-
assignees: assignees
34902+
assignees: assignees,
3490234903
});
3490334904
}
3490434905
catch (error) {
@@ -34909,11 +34910,11 @@ class Repository {
3490934910
}
3491034911
async addLabels(issueNumber, labels) {
3491134912
try {
34912-
return this._config.repository.octokit.rest.issues.addLabels({
34913+
return this._octokit.rest.issues.addLabels({
3491334914
owner: this._config.repository.owner,
3491434915
repo: this._config.repository.repo,
3491534916
issue_number: issueNumber,
34916-
labels
34917+
labels,
3491734918
});
3491834919
}
3491934920
catch (error) {
@@ -34923,8 +34924,8 @@ class Repository {
3492334924
}
3492434925
}
3492534926
branchName() {
34926-
if (this._currentBranch === '') {
34927-
this._currentBranch = this._config.repository.commit.branch.replace('{random}', (0, randomizer_1.randomizer)());
34927+
if (this._currentBranch === "") {
34928+
this._currentBranch = this._config.repository.commit.branch.replace("{random}", (0, randomizer_1.randomizer)());
3492834929
}
3492934930
return this._currentBranch;
3493034931
}

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const previewUpdater = async () => {
2121
repository: {
2222
owner: context.repo.owner,
2323
repo: context.repo.repo,
24-
octokit: getOctokit(token),
2524
},
2625
},
2726
configPath,
@@ -39,7 +38,7 @@ const previewUpdater = async () => {
3938
info(`Working directory: ${config.directory}`);
4039

4140
// Authenticate
42-
const repo = new Repository(config);
41+
const repo = new Repository(config, getOctokit(token));
4342
await repo.authenticate();
4443

4544
// Read file

src/types/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { GitHub } from "@actions/github/lib/utils";
2-
31
export interface ImageParameters {
42
pattern: string;
53
style: string;
@@ -41,7 +39,6 @@ export interface PullRequest {
4139
export interface Repository {
4240
owner?: string;
4341
repo?: string;
44-
octokit?: InstanceType<typeof GitHub>;
4542

4643
commit: Commit;
4744
pullRequest: PullRequest;

src/utils/repository.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import type { Config } from "../types/config";
22
import { exec } from "./filesystem";
33
import { randomizer } from "./randomizer";
4+
import type { GitHub } from "@actions/github/lib/utils";
5+
import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types";
46

57
export class Repository {
68
private _config: Config;
79
private _currentBranch: string = "";
810
private _newBranch: boolean = false;
11+
private _octokit: InstanceType<typeof GitHub>;
912

10-
constructor(config: Config) {
13+
constructor(config: Config, octokit: InstanceType<typeof GitHub>) {
1114
this._config = config;
15+
this._octokit = octokit;
1216
}
1317

1418
async authenticate() {
@@ -117,7 +121,9 @@ export class Repository {
117121
`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`,
118122
);
119123

120-
return this._config.repository.octokit.rest.pulls.create({
124+
return this._octokit.rest.pulls.create(<
125+
RestEndpointMethodTypes["pulls"]["create"]["parameters"]
126+
>{
121127
owner: this._config.repository.owner,
122128
repo: this._config.repository.repo,
123129
title: this._config.repository.pullRequest.title,
@@ -135,7 +141,9 @@ export class Repository {
135141

136142
async assignee(issueNumber: number, assignees: string[]) {
137143
try {
138-
return this._config.repository.octokit.rest.issues.addAssignees({
144+
return this._octokit.rest.issues.addAssignees(<
145+
RestEndpointMethodTypes["issues"]["addAssignees"]["parameters"]
146+
>{
139147
owner: this._config.repository.owner,
140148
repo: this._config.repository.repo,
141149
issue_number: issueNumber,
@@ -151,7 +159,9 @@ export class Repository {
151159

152160
async addLabels(issueNumber: number, labels: string[]) {
153161
try {
154-
return this._config.repository.octokit.rest.issues.addLabels({
162+
return this._octokit.rest.issues.addLabels(<
163+
RestEndpointMethodTypes["issues"]["addLabels"]["parameters"]
164+
>{
155165
owner: this._config.repository.owner,
156166
repo: this._config.repository.repo,
157167
issue_number: issueNumber,

0 commit comments

Comments
 (0)