Skip to content

Commit

Permalink
Add amount keyword (#90)
Browse files Browse the repository at this point in the history
* added amount keyword for changes_requested

* run build and format

* Update dist/index.js

Co-authored-by: Andre_601 <[email protected]>

* Update src/config.js

Co-authored-by: Andre_601 <[email protected]>

* run build and format

* Update commitFile.js

* run build and format

* Update amountReplacer.js

* run build and format

* Revert "Update amountReplacer.js"

This reverts commit 28fd35a.

* run build and format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andre_601 <[email protected]>
  • Loading branch information
3 people authored Aug 3, 2021
1 parent 6a66196 commit d57b6c1
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"prefer-destructuring": ["error", { "object": true, "array": false }],
"no-unused-vars": ["error", { "argsIgnorePattern": "req|res|next|val" }]
"no-unused-vars": ["warn", { "argsIgnorePattern": "req|res|next|val" }],
"no-prototype-builtins": "off"
}
}
52 changes: 47 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25169,7 +25169,7 @@ const defaultVals = {
wiki_create: "📖 Created new wiki page {WIKI} in {REPO}",
added_member: "🤝 Became collaborator on {REPO}",
changes_approved: "👍 Approved {ID} in {REPO}",
changes_requested: "🔴 Requested changes in {ID} in {REPO}",
changes_requested: "🔴 Requested {AMOUNT} change(s) for {ID} in {REPO}",
new_release: "✌️ Released {ID} in {REPO}",
new_star: "⭐ Starred {REPO}",
commit_name: "readme-bot",
Expand Down Expand Up @@ -25473,6 +25473,7 @@ module.exports = PullRequestReviewCommentEvent;
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const { changes_approved, changes_requested } = __nccwpck_require__(4570);
const { amountUpdate } = __nccwpck_require__(3195);
const makeCustomUrl = __nccwpck_require__(434);
const toUrlFormat = __nccwpck_require__(5879);

Expand All @@ -25489,6 +25490,9 @@ const PullRequestReviewEvent = (item) => {
item.payload.action === "created" &&
item.payload.review.state == "changes_requested"
) {
if (!amountUpdate(item.payload.review.pull_request_url)) {
return "";
}
return changes_requested
.replace(/{ID}/g, toUrlFormat(item, "pr_review"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "pr_review"))
Expand Down Expand Up @@ -25546,6 +25550,37 @@ const WatchEvent = (item) => {
module.exports = WatchEvent;


/***/ }),

/***/ 3195:
/***/ ((module) => {

const identifier = [];
const amount = [];

const amountUpdate = (data) => {
let amt = identifier.indexOf(data);
if (amt !== -1) {
amount[amt] += 1;
return false;
} else {
identifier.push(data);
amount.push(1);
return true;
}
};

const amountReplace = (data) => {
amount.forEach((amt) => {
data = data.replace("{AMOUNT}", amt);
});

return data;
};

module.exports = { amountUpdate, amountReplace };


/***/ }),

/***/ 4922:
Expand Down Expand Up @@ -25673,6 +25708,7 @@ const commitFile = async () => {
await exec("git", ["config", "--global", "user.email", commit_email], false);
await exec("git", ["config", "--global", "user.name", commit_name], false);
await exec("git", ["add", readme_file], false);
await exec("git", ["pull"], false);
await exec("git", ["commit", "-m", commit_msg], false);
await exec("git", ["push"], true);
};
Expand Down Expand Up @@ -25721,7 +25757,8 @@ const exec = (cmd, args = [], callAPI) =>
});
app.on("close", (code) => {
if (code !== 0 && !stdout.includes("nothing to commit")) {
err = new Error(`Invalid status code: ${code}`);
console.log(stdout);
let err = new Error(`Invalid status code: ${code}`);
err.code = code;
if (callAPI) {
apiRequest({ ...reqParams, status: "failure" }, () => reject(err));
Expand Down Expand Up @@ -25763,11 +25800,12 @@ module.exports = exec;

const serializers = __nccwpck_require__(3169);
const { max_lines } = __nccwpck_require__(4570);
const { amountReplace } = __nccwpck_require__(3195);

const filterContent = (eventData) => {
let temp_content = [];

for (i = 0; i < eventData.length; i++) {
for (let i = 0; i < eventData.length; i++) {
let event_string = serializers[eventData[i].type](eventData[i]);

if (event_string !== "") {
Expand All @@ -25781,6 +25819,10 @@ const filterContent = (eventData) => {
temp_content = temp_content.flat();
temp_content.length = max_lines;

temp_content = temp_content.join("\n\n");

temp_content = amountReplace(temp_content).split("\n\n");

console.log(temp_content);

return temp_content;
Expand Down Expand Up @@ -25888,7 +25930,7 @@ const makeCustomUrl = (item, type) => {
`](${item.payload.release.html_url})`;
break;
default:
tools.exit.failure("Failed while creating the url string.");
url = "";
break;
}
return url;
Expand Down Expand Up @@ -25968,7 +26010,7 @@ const toUrlFormat = (item, type) => {
url = `[${item.payload.release.name}](${item.payload.release.html_url})`;
break;
default:
tools.exit.failure("Failed while creating the url format.");
url = "";
break;
}
return url;
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultVals = {
wiki_create: "📖 Created new wiki page {WIKI} in {REPO}",
added_member: "🤝 Became collaborator on {REPO}",
changes_approved: "👍 Approved {ID} in {REPO}",
changes_requested: "🔴 Requested changes in {ID} in {REPO}",
changes_requested: "🔴 Requested {AMOUNT} change(s) for {ID} in {REPO}",
new_release: "✌️ Released {ID} in {REPO}",
new_star: "⭐ Starred {REPO}",
commit_name: "readme-bot",
Expand Down
4 changes: 4 additions & 0 deletions src/events/PullRequestReviewEvent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { changes_approved, changes_requested } = require("../config");
const { amountUpdate } = require("../functions/amountReplacer");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

Expand All @@ -15,6 +16,9 @@ const PullRequestReviewEvent = (item) => {
item.payload.action === "created" &&
item.payload.review.state == "changes_requested"
) {
if (!amountUpdate(item.payload.review.pull_request_url)) {
return "";
}
return changes_requested
.replace(/{ID}/g, toUrlFormat(item, "pr_review"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "pr_review"))
Expand Down
24 changes: 24 additions & 0 deletions src/functions/amountReplacer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const identifier = [];
const amount = [];

const amountUpdate = (data) => {
let amt = identifier.indexOf(data);
if (amt !== -1) {
amount[amt] += 1;
return false;
} else {
identifier.push(data);
amount.push(1);
return true;
}
};

const amountReplace = (data) => {
amount.forEach((amt) => {
data = data.replace("{AMOUNT}", amt);
});

return data;
};

module.exports = { amountUpdate, amountReplace };
1 change: 1 addition & 0 deletions src/functions/commitFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const commitFile = async () => {
await exec("git", ["config", "--global", "user.email", commit_email], false);
await exec("git", ["config", "--global", "user.name", commit_name], false);
await exec("git", ["add", readme_file], false);
await exec("git", ["pull"], false);
await exec("git", ["commit", "-m", commit_msg], false);
await exec("git", ["push"], true);
};
Expand Down
3 changes: 2 additions & 1 deletion src/functions/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const exec = (cmd, args = [], callAPI) =>
});
app.on("close", (code) => {
if (code !== 0 && !stdout.includes("nothing to commit")) {
err = new Error(`Invalid status code: ${code}`);
console.log(stdout);
let err = new Error(`Invalid status code: ${code}`);
err.code = code;
if (callAPI) {
apiRequest({ ...reqParams, status: "failure" }, () => reject(err));
Expand Down
7 changes: 6 additions & 1 deletion src/functions/filterContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

const serializers = require("../serializers");
const { max_lines } = require("../config");
const { amountReplace } = require("./amountReplacer");

const filterContent = (eventData) => {
let temp_content = [];

for (i = 0; i < eventData.length; i++) {
for (let i = 0; i < eventData.length; i++) {
let event_string = serializers[eventData[i].type](eventData[i]);

if (event_string !== "") {
Expand All @@ -23,6 +24,10 @@ const filterContent = (eventData) => {
temp_content = temp_content.flat();
temp_content.length = max_lines;

temp_content = temp_content.join("\n\n");

temp_content = amountReplace(temp_content).split("\n\n");

console.log(temp_content);

return temp_content;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/makeCustomUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const makeCustomUrl = (item, type) => {
`](${item.payload.release.html_url})`;
break;
default:
tools.exit.failure("Failed while creating the url string.");
url = "";
break;
}
return url;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/toUrlFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const toUrlFormat = (item, type) => {
url = `[${item.payload.release.name}](${item.payload.release.html_url})`;
break;
default:
tools.exit.failure("Failed while creating the url format.");
url = "";
break;
}
return url;
Expand Down

0 comments on commit d57b6c1

Please sign in to comment.