Skip to content

Commit 8d7def1

Browse files
Extract randomizer function to strings.ts as randomString and update references in repository.ts for better modularity.
1 parent 2ccb339 commit 8d7def1

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/utils/randomizer.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/utils/repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Config } from "../types/config";
2-
import { randomizer } from "./randomizer";
32
import type { GitHub } from "@actions/github/lib/utils";
43
import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types";
54
import { exec } from "./processes";
5+
import { randomString } from "./strings";
66

77
export class Repository {
88
private _config: Config;
@@ -179,7 +179,7 @@ export class Repository {
179179
if (this._currentBranch === "") {
180180
this._currentBranch = this._config.repository.commit.branch.replace(
181181
"{random}",
182-
randomizer(),
182+
randomString(),
183183
);
184184
}
185185

src/utils/strings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ export const encodeUri = (value: string | undefined): string => {
2323

2424
return encodeURIComponent(value);
2525
};
26+
27+
export const randomString = (length: number = 8) => {
28+
const chars = "abcdefghijklmnopqrstuvwxyz";
29+
30+
let result: string = "";
31+
32+
for (let i: number = 0; i < length; i++) {
33+
result += chars.charAt(Math.floor(Math.random() * chars.length));
34+
}
35+
36+
return result;
37+
};

0 commit comments

Comments
 (0)