Skip to content

Commit

Permalink
feat: allow git commit type to be changed in configuration (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasbueschel committed May 24, 2023
1 parent 016ba93 commit dbb96f3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
9 changes: 5 additions & 4 deletions lib/add-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ async function addContributor({
originalSha: config.getOriginalSha(),
};

const convention = config.get().commitConvention;
const { commitConvention, commitType } = config.get();
const prTitle = convertMessage({
tag: "docs",
tag: commitType,
msg: generatePrTitle(`add ${who} as a contributor`, contributions),
convention
convention: commitConvention
});

const skipCi = config.get().skipCi;
Expand All @@ -78,7 +78,8 @@ async function addContributor({
body: prBody,
filesByPath: filesByPathToUpdate,
branchName,
convention,
convention: commitConvention,
commitType,
});

// let user know in comment
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Config {
files: ["README.md"],
imageSize: 100,
commit: false,
commitType: "docs",
commitConvention: "angular",
contributors: [],
contributorsPerLine: 7,
Expand Down Expand Up @@ -69,6 +70,10 @@ class Config {
options.files = ["README.md"];
}

if (!options.commitType) {
options.commitType = "docs";
}

if (!options.commitConvention) {
options.commitConvention = "angular";
}
Expand Down
17 changes: 11 additions & 6 deletions lib/modules/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Repository {
});
}

async updateFile({ filePath, content, branchName, originalSha, convention }) {
async updateFile({ filePath, content, branchName, originalSha, convention, commitType }) {
const contentBinary = Buffer.from(content).toString("base64");

//octokit.github.io/rest.js/#api-Repos-updateFile
Expand All @@ -127,7 +127,7 @@ class Repository {
repo: this.repo,
path: filePath,
message: convertMessage({
tag: "docs",
tag: commitType,
msg: `update ${filePath} ${this.skipCiString}`,
convention,
}).trim(),
Expand All @@ -137,7 +137,7 @@ class Repository {
});
}

async createFile({ filePath, content, branchName, convention }) {
async createFile({ filePath, content, branchName, convention, commitType }) {
const contentBinary = Buffer.from(content).toString("base64");

//octokit.github.io/rest.js/#api-Repos-createFile
Expand All @@ -146,7 +146,7 @@ class Repository {
repo: this.repo,
path: filePath,
message: convertMessage({
tag: "docs",
tag: commitType,
msg: `create ${filePath} ${this.skipCiString}`,
convention,
}).trim(),
Expand All @@ -161,21 +161,23 @@ class Repository {
branchName,
originalSha,
convention,
commitType,
}) {
if (originalSha === undefined) {
await this.createFile({ filePath, content, branchName, convention });
await this.createFile({ filePath, content, branchName, convention, commitType });
} else {
await this.updateFile({
filePath,
content,
branchName,
originalSha,
convention,
commitType,
});
}
}

async createOrUpdateFiles({ filesByPath, branchName, convention }) {
async createOrUpdateFiles({ filesByPath, branchName, convention, commitType }) {
const repository = this;
const createOrUpdateFilesMultiple = Object.entries(filesByPath).map(
([filePath, { content, originalSha }]) => {
Expand All @@ -185,6 +187,7 @@ class Repository {
branchName,
originalSha,
convention,
commitType,
});
}
);
Expand Down Expand Up @@ -252,6 +255,7 @@ class Repository {
filesByPath,
branchName,
convention,
commitType,
}) {
const branchNameExists = branchName === this.baseBranch;
if (!branchNameExists) {
Expand All @@ -262,6 +266,7 @@ class Repository {
filesByPath,
branchName,
convention,
commitType,
});

return this.createPullRequest({
Expand Down
Loading

1 comment on commit dbb96f3

@vercel
Copy link

@vercel vercel bot commented on dbb96f3 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.