Skip to content

Commit d28036a

Browse files
Merge pull request #13 from TheDragonCode/code-style-n10ywni
The code style has been fixed
2 parents aad9eb2 + 4684b4b commit d28036a

File tree

1 file changed

+74
-86
lines changed

1 file changed

+74
-86
lines changed

src/utils/repository.ts

Lines changed: 74 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,178 @@
1-
import type { Config } from '../types/config'
2-
import { exec } from './filesystem'
3-
import { randomizer } from './randomizer'
4-
5-
export class Repository
6-
{
7-
private _config: Config
8-
private _currentBranch: string = ''
9-
private _newBranch: boolean = false
10-
11-
constructor(config: Config)
12-
{
13-
this._config = config
1+
import type { Config } from "../types/config";
2+
import { exec } from "./filesystem";
3+
import { randomizer } from "./randomizer";
4+
5+
export class Repository {
6+
private _config: Config;
7+
private _currentBranch: string = "";
8+
private _newBranch: boolean = false;
9+
10+
constructor(config: Config) {
11+
this._config = config;
1412
}
1513

16-
async authenticate()
17-
{
14+
async authenticate() {
1815
try {
19-
const author = this._config.repository.commit.author
16+
const author = this._config.repository.commit.author;
2017

21-
await exec(`git config user.name "${ author.name }"`)
22-
await exec(`git config user.email "${ author.email }"`)
18+
await exec(`git config user.name "${author.name}"`);
19+
await exec(`git config user.email "${author.email}"`);
2320
} catch (error) {
2421
// @ts-expect-error
25-
error.message = `Error authenticating user "${ author.name }" with e-mail "${ author.email }": ${ error.message }`
22+
error.message = `Error authenticating user "${author.name}" with e-mail "${author.email}": ${error.message}`;
2623

27-
throw error
24+
throw error;
2825
}
2926
}
3027

31-
async branchExists()
32-
{
28+
async branchExists() {
3329
try {
3430
const hasLocalBranch = async () => {
3531
const result = await exec(
36-
`git branch --list "${ this.branchName() }"`
37-
)
32+
`git branch --list "${this.branchName()}"`,
33+
);
3834

39-
return result.includes(this.branchName())
40-
}
35+
return result.includes(this.branchName());
36+
};
4137

4238
const hasRemoteBranch = async () => {
4339
const result = await exec(
44-
`git ls-remote --heads origin "${ this.branchName() }"`
45-
)
40+
`git ls-remote --heads origin "${this.branchName()}"`,
41+
);
4642

47-
return result.includes(this.branchName())
48-
}
43+
return result.includes(this.branchName());
44+
};
4945

50-
return (await hasLocalBranch()) || (await hasRemoteBranch())
46+
return (await hasLocalBranch()) || (await hasRemoteBranch());
5147
} catch (error) {
5248
// @ts-expect-error
53-
error.message = `Error searching for branch "${ this.branchName() }": ${ error.message }`
49+
error.message = `Error searching for branch "${this.branchName()}": ${error.message}`;
5450

55-
throw error
51+
throw error;
5652
}
5753
}
5854

59-
async checkoutBranch(isNew: boolean)
60-
{
55+
async checkoutBranch(isNew: boolean) {
6156
try {
62-
this._newBranch = isNew
57+
this._newBranch = isNew;
6358

6459
await exec(
65-
`git switch ${ isNew ? '-c' : '' } "${ this.branchName() }"`
66-
)
60+
`git switch ${isNew ? "-c" : ""} "${this.branchName()}"`,
61+
);
6762
} catch (error) {
6863
// @ts-expect-error
69-
error.message = `Error checking out ${ isNew ? 'new' : 'existing' } branch "${ this.branchName() }": ${ error.message }`
64+
error.message = `Error checking out ${isNew ? "new" : "existing"} branch "${this.branchName()}": ${error.message}`;
7065

71-
throw error
66+
throw error;
7267
}
7368
}
7469

75-
async stage()
76-
{
70+
async stage() {
7771
try {
78-
await exec('git add ' + this._config.path.readme)
72+
await exec("git add " + this._config.path.readme);
7973
} catch (error) {
8074
// @ts-expect-error
81-
error.message = `Error staging file "${ this._config.path.readme }": ${ error.message }`
75+
error.message = `Error staging file "${this._config.path.readme}": ${error.message}`;
8276

83-
throw error
77+
throw error;
8478
}
8579
}
8680

87-
async commit()
88-
{
81+
async commit() {
8982
try {
9083
const message =
9184
this._config.repository.commit.title +
92-
'\n' +
93-
this._config.repository.commit.body
85+
"\n" +
86+
this._config.repository.commit.body;
9487

95-
await exec(`git commit -m "${ message }"`)
88+
await exec(`git commit -m "${message}"`);
9689
} catch (error) {
9790
// @ts-expect-error
98-
error.message = `Error committing file "${ this._config.path.readme }": ${ error.message }`
91+
error.message = `Error committing file "${this._config.path.readme}": ${error.message}`;
9992

100-
throw error
93+
throw error;
10194
}
10295
}
10396

104-
async push()
105-
{
97+
async push() {
10698
try {
107-
let cmd = 'git push'
99+
let cmd = "git push";
108100

109101
if (this._newBranch) {
110-
cmd += ` --set-upstream origin ${ this.branchName() }`
102+
cmd += ` --set-upstream origin ${this.branchName()}`;
111103
}
112104

113-
await exec(cmd)
105+
await exec(cmd);
114106
} catch (error) {
115107
// @ts-expect-error
116-
error.message = `Error pushing changes to "${ this.branchName() } branch": ${ error.message }`
108+
error.message = `Error pushing changes to "${this.branchName()} branch": ${error.message}`;
117109

118-
throw error
110+
throw error;
119111
}
120112
}
121113

122-
async createPullRequest()
123-
{
114+
async createPullRequest() {
124115
try {
125116
const defaultBranch = await exec(
126-
`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`
127-
)
117+
`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`,
118+
);
128119

129120
return this._config.repository.octokit.rest.pulls.create({
130121
owner: this._config.repository.owner,
131122
repo: this._config.repository.repo,
132123
title: this._config.repository.pullRequest.title,
133124
body: this._config.repository.pullRequest.body,
134125
head: this.branchName(),
135-
base: defaultBranch
136-
})
126+
base: defaultBranch,
127+
});
137128
} catch (error) {
138129
// @ts-expect-error
139-
error.message = `Error when creating pull request from ${ this.branchName() }: ${ error.message }`
130+
error.message = `Error when creating pull request from ${this.branchName()}: ${error.message}`;
140131

141-
throw error
132+
throw error;
142133
}
143134
}
144135

145-
async assignee(issueNumber: number, assignees: string[])
146-
{
136+
async assignee(issueNumber: number, assignees: string[]) {
147137
try {
148138
return this._config.repository.octokit.rest.issues.addAssignees({
149139
owner: this._config.repository.owner,
150140
repo: this._config.repository.repo,
151141
issue_number: issueNumber,
152-
assignees: assignees
153-
})
142+
assignees: assignees,
143+
});
154144
} catch (error) {
155145
// @ts-expect-error
156-
error.message = `Error when adding assignees to issue ${ issueNumber }: ${ error.message }`
146+
error.message = `Error when adding assignees to issue ${issueNumber}: ${error.message}`;
157147

158-
throw error
148+
throw error;
159149
}
160150
}
161151

162-
async addLabels(issueNumber: number, labels: string[])
163-
{
152+
async addLabels(issueNumber: number, labels: string[]) {
164153
try {
165154
return this._config.repository.octokit.rest.issues.addLabels({
166155
owner: this._config.repository.owner,
167156
repo: this._config.repository.repo,
168157
issue_number: issueNumber,
169-
labels
170-
})
158+
labels,
159+
});
171160
} catch (error) {
172161
// @ts-expect-error
173-
error.message = `Error when adding labels to issue ${ issueNumber }: ${ error.message }`
162+
error.message = `Error when adding labels to issue ${issueNumber}: ${error.message}`;
174163

175-
throw error
164+
throw error;
176165
}
177166
}
178167

179-
branchName(): string
180-
{
181-
if (this._currentBranch === '') {
168+
branchName(): string {
169+
if (this._currentBranch === "") {
182170
this._currentBranch = this._config.repository.commit.branch.replace(
183-
'{random}',
184-
randomizer()
185-
)
171+
"{random}",
172+
randomizer(),
173+
);
186174
}
187175

188-
return this._currentBranch
176+
return this._currentBranch;
189177
}
190178
}

0 commit comments

Comments
 (0)