Skip to content

Commit 789d7a6

Browse files
committed
[ts] Use double quotes
1 parent 9896a46 commit 789d7a6

File tree

9 files changed

+105
-106
lines changed

9 files changed

+105
-106
lines changed

typescript/.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tabWidth": 4,
44
"useTabs": false,
55
"semi": false,
6-
"singleQuote": true,
6+
"singleQuote": false,
77
"trailingComma": "none",
88
"bracketSpacing": false,
99
"arrowParens": "avoid"

typescript/package-lock.json

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

typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@typescript-eslint/parser": "^6.19.0",
3535
"@vercel/ncc": "^0.38.1",
3636
"eslint": "^8.56.0",
37+
"eslint-plugin-prettier": "^5.1.3",
3738
"eslint-plugin-github": "^4.10.1",
3839
"js-yaml": "^4.1.0",
3940
"prettier": "3.2.2",

typescript/src/commit-validator.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {Commit} from './commit'
1+
import {Commit} from "./commit"
22

33
export enum Status {
4-
Failure = 'Failure',
5-
Warning = 'Warning',
6-
Ok = 'Correct'
4+
Failure = "Failure",
5+
Warning = "Warning",
6+
Ok = "Correct"
77
}
88

99
export class Result {
1010
status: Status = Status.Failure
11-
message = ''
11+
message = ""
1212
commit: Commit | undefined = undefined
1313

14-
constructor(status: Status, message = '', commit: Commit | undefined = undefined) {
14+
constructor(status: Status, message = "", commit: Commit | undefined = undefined) {
1515
this.status = status
1616
this.message = message
1717
this.commit = commit
@@ -35,9 +35,9 @@ export class Result {
3535
if (this.commit !== undefined) {
3636
msg += ` | ${this.commit.hexsha} - ${this.commit.summary()}`
3737
}
38-
if (this.message !== '') {
38+
if (this.message !== "") {
3939
if (this.commit === undefined) {
40-
msg += ' |'
40+
msg += " |"
4141
}
4242
msg += `\n : ${this.message}`
4343
}
@@ -52,9 +52,9 @@ export class CommitValidator {
5252
}
5353

5454
static split_message(message: string): [string, string] {
55-
const res: string[] = message.split('\n', 1)
55+
const res: string[] = message.split("\n", 1)
5656
if (res.length === 1) {
57-
return [res[0], '']
57+
return [res[0], ""]
5858
}
5959
return [res[0], res[1]]
6060
}
@@ -71,6 +71,6 @@ export class CommitValidator {
7171
}
7272

7373
validate_message(_summary: string, _description: string): Result {
74-
return new Result(Status.Ok, '')
74+
return new Result(Status.Ok, "")
7575
}
7676
}

typescript/src/commit.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export class User {
55

66
constructor(data: object) {
77
type key = keyof typeof data
8-
this.email = data['email' as key]
9-
this.name = data['name' as key]
10-
this.username = data['username' as key]
8+
this.email = data["email" as key]
9+
this.name = data["name" as key]
10+
this.username = data["username" as key]
1111
}
1212
}
1313

@@ -21,22 +21,22 @@ export class Commit {
2121

2222
constructor(commit: object, sha = "", timestamp = "") {
2323
type key = keyof typeof commit
24-
this.author = new User(commit['author' as key])
25-
this.committer = new User(commit['committer' as key])
26-
this.distinct = commit['distinct' as key] ?? false
27-
this.hexsha = commit['id' as key] ?? sha
28-
const timestamp_raw = commit['timestamp' as key] ?? timestamp
24+
this.author = new User(commit["author" as key])
25+
this.committer = new User(commit["committer" as key])
26+
this.distinct = commit["distinct" as key] ?? false
27+
this.hexsha = commit["id" as key] ?? sha
28+
const timestamp_raw = commit["timestamp" as key] ?? timestamp
2929
if (timestamp_raw !== undefined) {
3030
this.timestamp = new Date(timestamp_raw)
3131
}
32-
this.message = commit['message' as key]
32+
this.message = commit["message" as key]
3333
}
3434

3535
// return empty string if message is undefined
3636
summary(): string {
3737
if (this.message === undefined) {
38-
return ''
38+
return ""
3939
}
40-
return this.message.split('\n', 1)[0]
40+
return this.message.split("\n", 1)[0]
4141
}
4242
}

typescript/src/gh-utils.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
// GitHub support utility.
22

33
import {resolve} from "path"
4-
import {GitHub} from "@actions/github/lib/utils";
5-
import * as github from "@actions/github";
6-
import * as core from "@actions/core";
7-
import fs from "fs";
8-
import {Commit} from "./commit";
9-
import {Result, Status} from "./commit-validator";
10-
import {pathToFileURL} from "url";
4+
import {GitHub} from "@actions/github/lib/utils"
5+
import * as github from "@actions/github"
6+
import * as core from "@actions/core"
7+
import fs from "fs"
8+
import {Commit} from "./commit"
9+
import {Result, Status} from "./commit-validator"
10+
import {pathToFileURL} from "url"
1111

1212
// return html url to validator file and local filepath to downloaded file
13-
export async function download_validator_file(validator_file: string, octokit: InstanceType<typeof GitHub>): Promise<[string, string]> {
13+
export async function download_validator_file(
14+
validator_file: string,
15+
octokit: InstanceType<typeof GitHub>
16+
): Promise<[string, string]> {
1417
const response = await octokit.rest.repos.getContent({
1518
path: validator_file,
1619
owner: github.context.repo.owner,
1720
repo: github.context.repo.repo,
18-
ref: github.context.sha,
21+
ref: github.context.sha
1922
})
2023
if (response.status !== 200) {
2124
core.error(JSON.stringify(response.data))
@@ -30,17 +33,17 @@ export async function download_validator_file(validator_file: string, octokit: I
3033
core.setFailed(`download of '${response.url}' failed`)
3134
return ["", ""]
3235
}
33-
const buffer = Buffer.from(response.data.content, 'base64').toString('utf-8')
36+
const buffer = Buffer.from(response.data.content, "base64").toString("utf-8")
3437
const output_path = pathToFileURL(resolve("./validator.mjs"))
3538
fs.writeFileSync(output_path, buffer)
3639
return [response.data.html_url || "", output_path.toString()]
3740
}
3841

3942
export async function get_commit_creation(octokit: InstanceType<typeof GitHub>): Promise<string> {
40-
const response = await octokit.request('GET /repos/{owner}/{repo}/git/commits/{commit_sha}', {
43+
const response = await octokit.request("GET /repos/{owner}/{repo}/git/commits/{commit_sha}", {
4144
owner: github.context.repo.owner,
4245
repo: github.context.repo.repo,
43-
commit_sha: github.context.payload.pull_request?.base.sha,
46+
commit_sha: github.context.payload.pull_request?.base.sha
4447
})
4548
if (response.status !== 200) {
4649
core.error(JSON.stringify(response.data))
@@ -55,16 +58,16 @@ export async function get_commit_creation(octokit: InstanceType<typeof GitHub>):
5558
export async function get_commits(octokit: InstanceType<typeof GitHub>): Promise<Commit[]> {
5659
const commits: Commit[] = []
5760
switch (github.context.eventName) {
58-
case 'pull_request': {
61+
case "pull_request": {
5962
const pages = Math.floor(github.context.payload.pull_request?.commits / 100) + 1
6063
for (let page = 1; page <= pages; page++) {
61-
const response = await octokit.request('GET /repos/{owner}/{repo}/commits', {
64+
const response = await octokit.request("GET /repos/{owner}/{repo}/commits", {
6265
owner: github.context.payload.pull_request?.head.repo.owner.login,
6366
repo: github.context.payload.pull_request?.head.repo.name,
6467
sha: github.context.payload.pull_request?.head.ref,
6568
since: await get_commit_creation(octokit),
6669
per_page: 100,
67-
page,
70+
page
6871
})
6972
if (response.status !== 200) {
7073
core.error(JSON.stringify(response.data))
@@ -80,15 +83,15 @@ export async function get_commits(octokit: InstanceType<typeof GitHub>): Promise
8083
}
8184
break
8285
}
83-
case 'push':
86+
case "push":
8487
default: {
85-
if ('commits' in github.context.payload && github.context.payload['commits'].length > 0) {
86-
for (const commit of github.context.payload['commits']) {
88+
if ("commits" in github.context.payload && github.context.payload["commits"].length > 0) {
89+
for (const commit of github.context.payload["commits"]) {
8790
commits.push(new Commit(commit))
8891
}
8992
// on tags or if commits was empty
90-
} else if ('head_commit' in github.context.payload) {
91-
commits.push(new Commit(github.context.payload['head_commit']))
93+
} else if ("head_commit" in github.context.payload) {
94+
commits.push(new Commit(github.context.payload["head_commit"]))
9295
}
9396
}
9497
}

typescript/src/main.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import * as core from '@actions/core'
2-
import * as github from '@actions/github'
3-
import {CommitValidator, Result} from './commit-validator'
1+
import * as core from "@actions/core"
2+
import * as github from "@actions/github"
3+
import {CommitValidator, Result} from "./commit-validator"
44
import {GitHub} from "@actions/github/lib/utils"
5-
import * as utils from './utils'
6-
import * as gh_utils from './gh-utils'
5+
import * as utils from "./utils"
6+
import * as gh_utils from "./gh-utils"
77

88
async function run(): Promise<void> {
99
try {
10-
const validator_file: string = core.getInput('validator_file')
11-
const validator_name: string = core.getInput('validator')
12-
const options: string[] = core.getMultilineInput('options')
13-
const access_token: string = core.getInput('access_token')
10+
const validator_file: string = core.getInput("validator_file")
11+
const validator_name: string = core.getInput("validator")
12+
const options: string[] = core.getMultilineInput("options")
13+
const access_token: string = core.getInput("access_token")
1414
// just to be sure
1515
core.setSecret(access_token)
1616
core.debug(JSON.stringify(github.context))
1717

18-
if (validator_file !== '' && validator_name !== '') {
18+
if (validator_file !== "" && validator_name !== "") {
1919
core.setFailed("Please provide only 'validator' or 'validator_file'!")
2020
return
2121
}
22-
if (validator_file === '' && validator_name === '') {
22+
if (validator_file === "" && validator_name === "") {
2323
core.setFailed("Please provide either 'validator' or 'validator_file'!")
2424
return
2525
}

typescript/src/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import {Commit} from './commit'
2-
import {CommitValidator, Result, Status} from './commit-validator'
3-
import * as validation from './validation'
1+
import {Commit} from "./commit"
2+
import {CommitValidator, Result, Status} from "./commit-validator"
3+
import * as validation from "./validation"
44

55
export async function get_shipped_validator_cls(validator: string): Promise<typeof CommitValidator> {
66
switch (validator.toLowerCase()) {
7-
case 'simpletag':
7+
case "simpletag":
88
return validation.SimpleTag
9-
case 'regex':
9+
case "regex":
1010
return validation.RegEx
1111
default:
12-
throw Error('Invalid validator name!')
12+
throw Error("Invalid validator name!")
1313
}
1414
}
1515

16-
const _importDynamic = new Function('modulePath', 'return import(modulePath)')
16+
const _importDynamic = new Function("modulePath", "return import(modulePath)")
1717

1818
export async function import_validator_cls(validator_file: string): Promise<typeof CommitValidator> {
1919
const validation_mod = await _importDynamic(validator_file)

0 commit comments

Comments
 (0)