Skip to content

Commit dbb96f3

Browse files
feat: allow git commit type to be changed in configuration (#462)
1 parent 016ba93 commit dbb96f3

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

lib/add-contributor.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ async function addContributor({
5555
originalSha: config.getOriginalSha(),
5656
};
5757

58-
const convention = config.get().commitConvention;
58+
const { commitConvention, commitType } = config.get();
5959
const prTitle = convertMessage({
60-
tag: "docs",
60+
tag: commitType,
6161
msg: generatePrTitle(`add ${who} as a contributor`, contributions),
62-
convention
62+
convention: commitConvention
6363
});
6464

6565
const skipCi = config.get().skipCi;
@@ -78,7 +78,8 @@ async function addContributor({
7878
body: prBody,
7979
filesByPath: filesByPathToUpdate,
8080
branchName,
81-
convention,
81+
convention: commitConvention,
82+
commitType,
8283
});
8384

8485
// let user know in comment

lib/modules/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Config {
1212
files: ["README.md"],
1313
imageSize: 100,
1414
commit: false,
15+
commitType: "docs",
1516
commitConvention: "angular",
1617
contributors: [],
1718
contributorsPerLine: 7,
@@ -69,6 +70,10 @@ class Config {
6970
options.files = ["README.md"];
7071
}
7172

73+
if (!options.commitType) {
74+
options.commitType = "docs";
75+
}
76+
7277
if (!options.commitConvention) {
7378
options.commitConvention = "angular";
7479
}

lib/modules/repository.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Repository {
118118
});
119119
}
120120

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

124124
//octokit.github.io/rest.js/#api-Repos-updateFile
@@ -127,7 +127,7 @@ class Repository {
127127
repo: this.repo,
128128
path: filePath,
129129
message: convertMessage({
130-
tag: "docs",
130+
tag: commitType,
131131
msg: `update ${filePath} ${this.skipCiString}`,
132132
convention,
133133
}).trim(),
@@ -137,7 +137,7 @@ class Repository {
137137
});
138138
}
139139

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

143143
//octokit.github.io/rest.js/#api-Repos-createFile
@@ -146,7 +146,7 @@ class Repository {
146146
repo: this.repo,
147147
path: filePath,
148148
message: convertMessage({
149-
tag: "docs",
149+
tag: commitType,
150150
msg: `create ${filePath} ${this.skipCiString}`,
151151
convention,
152152
}).trim(),
@@ -161,21 +161,23 @@ class Repository {
161161
branchName,
162162
originalSha,
163163
convention,
164+
commitType,
164165
}) {
165166
if (originalSha === undefined) {
166-
await this.createFile({ filePath, content, branchName, convention });
167+
await this.createFile({ filePath, content, branchName, convention, commitType });
167168
} else {
168169
await this.updateFile({
169170
filePath,
170171
content,
171172
branchName,
172173
originalSha,
173174
convention,
175+
commitType,
174176
});
175177
}
176178
}
177179

178-
async createOrUpdateFiles({ filesByPath, branchName, convention }) {
180+
async createOrUpdateFiles({ filesByPath, branchName, convention, commitType }) {
179181
const repository = this;
180182
const createOrUpdateFilesMultiple = Object.entries(filesByPath).map(
181183
([filePath, { content, originalSha }]) => {
@@ -185,6 +187,7 @@ class Repository {
185187
branchName,
186188
originalSha,
187189
convention,
190+
commitType,
188191
});
189192
}
190193
);
@@ -252,6 +255,7 @@ class Repository {
252255
filesByPath,
253256
branchName,
254257
convention,
258+
commitType,
255259
}) {
256260
const branchNameExists = branchName === this.baseBranch;
257261
if (!branchNameExists) {
@@ -262,6 +266,7 @@ class Repository {
262266
filesByPath,
263267
branchName,
264268
convention,
269+
commitType,
265270
});
266271

267272
return this.createPullRequest({

0 commit comments

Comments
 (0)