Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"includes": [
"**",
"!node_modules",
"!vendor",
"!composer.json",
"!composer.lock",
"!package.json",
"!package-lock.json",
"!analytics.*",
"!metrics.*",
"!coverage",
"!dist"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"json": {
"formatter": {
"enabled": true,
"bracketSpacing": true,
"expand": "always"
},
"parser": {
"allowComments": true
}
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
39 changes: 20 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34392,7 +34392,6 @@ const previewUpdater = async () => {
repository: {
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
octokit: (0, github_1.getOctokit)(token),
},
}, configPath);
// Read names
Expand All @@ -34404,7 +34403,7 @@ const previewUpdater = async () => {
// Show working directory
(0, core_1.info)(`Working directory: ${config.directory}`);
// Authenticate
const repo = new repository_1.Repository(config);
const repo = new repository_1.Repository(config, (0, github_1.getOctokit)(token));
await repo.authenticate();
// Read file
const content = (0, filesystem_1.readFile)(config, config.path.readme);
Expand Down Expand Up @@ -34463,8 +34462,8 @@ exports.defaultConfig = {
fontSize: "100px",
icon: "code",
packageManager: "auto",
packageName: undefined,
packageGlobal: false,
packageName: undefined,
title: undefined,
description: undefined,
},
Expand Down Expand Up @@ -34754,7 +34753,8 @@ const setPreview = (content, config) => {
content = `# ${title}\n\n${content}`;
}
const images = (0, image_1.getImages)(config);
return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, "$1" + images + "\n\n");
const replace = "$1";
return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, `${replace}${images}\n\n`);
};
exports.setPreview = setPreview;

Expand Down Expand Up @@ -34791,10 +34791,11 @@ exports.Repository = void 0;
const filesystem_1 = __nccwpck_require__(9742);
const randomizer_1 = __nccwpck_require__(3678);
class Repository {
constructor(config) {
this._currentBranch = '';
constructor(config, octokit) {
this._currentBranch = "";
this._newBranch = false;
this._config = config;
this._octokit = octokit;
}
async authenticate() {
try {
Expand Down Expand Up @@ -34829,17 +34830,17 @@ class Repository {
async checkoutBranch(isNew) {
try {
this._newBranch = isNew;
await (0, filesystem_1.exec)(`git switch ${isNew ? '-c' : ''} "${this.branchName()}"`);
await (0, filesystem_1.exec)(`git switch ${isNew ? "-c" : ""} "${this.branchName()}"`);
}
catch (error) {
// @ts-expect-error
error.message = `Error checking out ${isNew ? 'new' : 'existing'} branch "${this.branchName()}": ${error.message}`;
error.message = `Error checking out ${isNew ? "new" : "existing"} branch "${this.branchName()}": ${error.message}`;
throw error;
}
}
async stage() {
try {
await (0, filesystem_1.exec)('git add ' + this._config.path.readme);
await (0, filesystem_1.exec)(`git add ${this._config.path.readme}`);
}
catch (error) {
// @ts-expect-error
Expand All @@ -34850,7 +34851,7 @@ class Repository {
async commit() {
try {
const message = this._config.repository.commit.title +
'\n' +
"\n" +
this._config.repository.commit.body;
await (0, filesystem_1.exec)(`git commit -m "${message}"`);
}
Expand All @@ -34862,7 +34863,7 @@ class Repository {
}
async push() {
try {
let cmd = 'git push';
let cmd = "git push";
if (this._newBranch) {
cmd += ` --set-upstream origin ${this.branchName()}`;
}
Expand All @@ -34877,13 +34878,13 @@ class Repository {
async createPullRequest() {
try {
const defaultBranch = await (0, filesystem_1.exec)(`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`);
return this._config.repository.octokit.rest.pulls.create({
return this._octokit.rest.pulls.create({
owner: this._config.repository.owner,
repo: this._config.repository.repo,
title: this._config.repository.pullRequest.title,
body: this._config.repository.pullRequest.body,
head: this.branchName(),
base: defaultBranch
base: defaultBranch,
});
}
catch (error) {
Expand All @@ -34894,11 +34895,11 @@ class Repository {
}
async assignee(issueNumber, assignees) {
try {
return this._config.repository.octokit.rest.issues.addAssignees({
return this._octokit.rest.issues.addAssignees({
owner: this._config.repository.owner,
repo: this._config.repository.repo,
issue_number: issueNumber,
assignees: assignees
assignees: assignees,
});
}
catch (error) {
Expand All @@ -34909,11 +34910,11 @@ class Repository {
}
async addLabels(issueNumber, labels) {
try {
return this._config.repository.octokit.rest.issues.addLabels({
return this._octokit.rest.issues.addLabels({
owner: this._config.repository.owner,
repo: this._config.repository.repo,
issue_number: issueNumber,
labels
labels,
});
}
catch (error) {
Expand All @@ -34923,8 +34924,8 @@ class Repository {
}
}
branchName() {
if (this._currentBranch === '') {
this._currentBranch = this._config.repository.commit.branch.replace('{random}', (0, randomizer_1.randomizer)());
if (this._currentBranch === "") {
this._currentBranch = this._config.repository.commit.branch.replace("{random}", (0, randomizer_1.randomizer)());
}
return this._currentBranch;
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"dev": "npm run build && node dist/index.js",
"coverage": "jest --coverage",
"test": "jest",
"type-check": "tsc --noEmit"
"type-check": "tsc --noEmit",
"lint": "npx @biomejs/biome lint --write",
"format": "npx @biomejs/biome format --write",
"style": "npm run lint && npm run format"
},
"keywords": [
"preview",
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const previewUpdater = async () => {
repository: {
owner: context.repo.owner,
repo: context.repo.repo,
octokit: getOctokit(token),
},
},
configPath,
Expand All @@ -39,7 +38,7 @@ const previewUpdater = async () => {
info(`Working directory: ${config.directory}`);

// Authenticate
const repo = new Repository(config);
const repo = new Repository(config, getOctokit(token));
await repo.authenticate();

// Read file
Expand Down
1 change: 0 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export interface PullRequest {
export interface Repository {
owner?: string;
repo?: string;
octokit?: any;

commit: Commit;
pullRequest: PullRequest;
Expand Down
7 changes: 6 additions & 1 deletion src/utils/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ export const setPreview = (content: string, config: Config) => {

const images: string = getImages(config);

return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, "$1" + images + "\n\n");
const replace = "$1";

return cleanUp(content).replace(
/^(#\s+.+[\n\s]+)/,
`${replace}${images}\n\n`,
);
};
20 changes: 15 additions & 5 deletions src/utils/repository.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { Config } from "../types/config";
import { exec } from "./filesystem";
import { randomizer } from "./randomizer";
import type { GitHub } from "@actions/github/lib/utils";
import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types";

export class Repository {
private _config: Config;
private _currentBranch: string = "";
private _newBranch: boolean = false;
private _octokit: InstanceType<typeof GitHub>;

constructor(config: Config) {
constructor(config: Config, octokit: InstanceType<typeof GitHub>) {
this._config = config;
this._octokit = octokit;
}

async authenticate() {
Expand Down Expand Up @@ -69,7 +73,7 @@ export class Repository {

async stage() {
try {
await exec("git add " + this._config.path.readme);
await exec(`git add ${this._config.path.readme}`);
} catch (error) {
// @ts-expect-error
error.message = `Error staging file "${this._config.path.readme}": ${error.message}`;
Expand Down Expand Up @@ -117,7 +121,9 @@ export class Repository {
`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`,
);

return this._config.repository.octokit.rest.pulls.create({
return this._octokit.rest.pulls.create(<
RestEndpointMethodTypes["pulls"]["create"]["parameters"]
>{
owner: this._config.repository.owner,
repo: this._config.repository.repo,
title: this._config.repository.pullRequest.title,
Expand All @@ -135,7 +141,9 @@ export class Repository {

async assignee(issueNumber: number, assignees: string[]) {
try {
return this._config.repository.octokit.rest.issues.addAssignees({
return this._octokit.rest.issues.addAssignees(<
RestEndpointMethodTypes["issues"]["addAssignees"]["parameters"]
>{
owner: this._config.repository.owner,
repo: this._config.repository.repo,
issue_number: issueNumber,
Expand All @@ -151,7 +159,9 @@ export class Repository {

async addLabels(issueNumber: number, labels: string[]) {
try {
return this._config.repository.octokit.rest.issues.addLabels({
return this._octokit.rest.issues.addLabels(<
RestEndpointMethodTypes["issues"]["addLabels"]["parameters"]
>{
owner: this._config.repository.owner,
repo: this._config.repository.repo,
issue_number: issueNumber,
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setPreview } from "../../src/utils/preview";
import { testConfig } from "./config";

export const getReadme = (filename: string): string => {
const content = readFile(testConfig, "tests/fixtures/readme/" + filename);
const content = readFile(testConfig, `tests/fixtures/readme/${filename}`);

return setPreview(content, testConfig);
};